Made code faster and cleaned some code.

This commit is contained in:
paxcut
2026-01-16 08:25:33 -07:00
committed by paxcut
parent 0e2d7ee3bc
commit 219f588cbe
12 changed files with 928 additions and 1085 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <utility>
#include <vector>
#include <array>
#include <memory>
@@ -62,8 +63,8 @@ namespace hex::ui {
bool operator>=(const Coordinates &o) const;
Coordinates operator+(const Coordinates &o) const;
Coordinates operator-(const Coordinates &o) const;
i32 getLine() const { return m_line; }
i32 getColumn() const { return m_column; }
[[nodiscard]] i32 getLine() const { return m_line; }
[[nodiscard]] i32 getColumn() const { return m_column; }
private:
i32 m_line, m_column;
@@ -84,11 +85,11 @@ namespace hex::ui {
Coordinates getEnd() { return m_end; }
bool isSingleLine();
enum class EndsInclusive : u8 { None = 0, Start = 2, End = 1, Both = 3 };
bool contains(const Coordinates &coordinates, EndsInclusive endsInclusive = EndsInclusive::Both) const;
bool contains(const Range &range, EndsInclusive endsInclusive = EndsInclusive::Both) const;
bool containsLine(i32 value, EndsInclusive endsInclusive = EndsInclusive::Both) const;
bool containsColumn(i32 value, EndsInclusive endsInclusive = EndsInclusive::Both) const;
bool overlaps(const Range &o, EndsInclusive endsInclusive = EndsInclusive::Both) const;
[[nodiscard]] bool contains(const Coordinates &coordinates, EndsInclusive endsInclusive = EndsInclusive::Both) const;
[[nodiscard]] bool contains(const Range &range, EndsInclusive endsInclusive = EndsInclusive::Both) const;
[[nodiscard]] bool containsLine(i32 value, EndsInclusive endsInclusive = EndsInclusive::Both) const;
[[nodiscard]] bool containsColumn(i32 value, EndsInclusive endsInclusive = EndsInclusive::Both) const;
[[nodiscard]] bool overlaps(const Range &o, EndsInclusive endsInclusive = EndsInclusive::Both) const;
bool operator==(const Range &o) const;
bool operator!=(const Range &o) const;
bool operator<(const Range &o) const {
@@ -118,7 +119,7 @@ namespace hex::ui {
Interval() : m_start(0), m_end(0) {}
Interval(i32 start, i32 end) : m_start(start), m_end(end) {
if (m_start > m_end) std::swap(m_start, m_end);}
Interval(const Interval &other) : m_start(other.m_start), m_end(other.m_end) {}
Interval(const Interval &other) = default;
explicit Interval(ImVec2 vec) : m_start((i32)vec.x), m_end((i32)vec.y) {
if (m_start > m_end) std::swap(m_start, m_end);}
@@ -130,11 +131,11 @@ namespace hex::ui {
bool operator!=(const Interval &other) const { return m_start != other.m_start || m_end != other.m_end; }
bool operator<=(const Interval &other) const { return other.m_end >= m_end; }
bool operator>=(const Interval &other) const { return m_end >= other.m_end; }
bool contains_or_equals(const Interval &other) const { return other.m_start >= m_start && other.m_end <= m_end; }
bool contains(const Interval &other) const { return (other.m_start >= m_start && other.m_end < m_end) || (other.m_start > m_start && other.m_end <= m_end); }
bool contains(i32 value, bool inclusive = true) const;
bool contiguous(const Interval &other) const;
operator ImVec2() const { return ImVec2((float)m_start, (float)m_end); }
[[nodiscard]] bool contains_or_equals(const Interval &other) const { return other.m_start >= m_start && other.m_end <= m_end; }
[[nodiscard]] bool contains(const Interval &other) const { return (other.m_start >= m_start && other.m_end < m_end) || (other.m_start > m_start && other.m_end <= m_end); }
[[nodiscard]] bool contains(i32 value, bool inclusive = true) const;
[[nodiscard]] bool contiguous(const Interval &other) const;
explicit operator ImVec2() const { return {(float)m_start, (float)m_end}; }
private:
i32 m_start;
i32 m_end;
@@ -144,8 +145,8 @@ namespace hex::ui {
public:
friend class TextEditor;
bool operator==(const EditorState &o) const;
EditorState() : m_selection(), m_cursorPosition() {}
EditorState(const Range &selection, const Coordinates &cursorPosition) : m_selection(selection), m_cursorPosition(cursorPosition) {}
EditorState() = default;
EditorState(Range selection, Coordinates cursorPosition) : m_selection(selection), m_cursorPosition(cursorPosition) {}
private:
Range m_selection;
Coordinates m_cursorPosition;
@@ -153,10 +154,12 @@ namespace hex::ui {
class UndoRecord;
using Matches = std::vector<EditorState>;
using UndoRecords = std::vector<UndoRecord>;
class FindReplaceHandler {
public:
FindReplaceHandler();
using Matches = std::vector<EditorState>;
Matches &getMatches() { return m_matches; }
bool findNext(Lines *lines, u64 &byteIndex);
bool findNext(TextEditor *editor, u64 &byteIndex) { return findNext(&editor->m_lines, byteIndex); };
@@ -177,17 +180,17 @@ namespace hex::ui {
void findAllMatches(TextEditor *editor, std::string findWord) { findAllMatches(&editor->m_lines, findWord); };
u32 findPosition(Lines *lines, Coordinates pos, bool isNext);
u32 findPosition(TextEditor *editor, Coordinates pos, bool isNext) { return findPosition(&editor->m_lines, pos, isNext); };
bool getMatchCase() const { return m_matchCase; }
[[nodiscard]] bool getMatchCase() const { return m_matchCase; }
void setMatchCase(Lines *lines, bool matchCase);
void setMatchCase(TextEditor *editor, bool matchCase) { setMatchCase(&editor->m_lines, matchCase); };
bool getWholeWord() const { return m_wholeWord; }
[[nodiscard]] bool getWholeWord() const { return m_wholeWord; }
void setWholeWord(Lines *lines, bool wholeWord);
void setWholeWord(TextEditor *editor, bool wholeWord) { setWholeWord(&editor->m_lines, wholeWord); };
bool getFindRegEx() const { return m_findRegEx; }
[[nodiscard]] bool getFindRegEx() const { return m_findRegEx; }
void setFindRegEx(Lines *lines, bool findRegEx);
void setFindRegEx(TextEditor *editor, bool findRegEx) { setFindRegEx(&editor->m_lines, findRegEx); };
void resetMatches();
std::vector<UndoRecord> m_undoBuffer;
UndoRecords m_undoBuffer;
private:
std::string m_findWord;
std::string m_replaceWord;
@@ -198,22 +201,24 @@ namespace hex::ui {
Matches m_matches;
};
enum class PaletteIndex {
enum class PaletteIndex : u8 {
Default, Identifier, Directive, Operator, Separator, BuiltInType, Keyword, NumericLiteral, StringLiteral, CharLiteral, Cursor, Background, LineNumber, Selection, Breakpoint, ErrorMarker, PreprocessorDeactivated,
CurrentLineFill, CurrentLineFillInactive, CurrentLineEdge, ErrorText, WarningText, DebugText, DefaultText, Attribute, PatternVariable, LocalVariable, CalculatedPointer, TemplateArgument, Function, View,
FunctionVariable, FunctionParameter, UserDefinedType, PlacedVariable, GlobalVariable, NameSpace, TypeDef, UnkIdentifier, DocComment, DocBlockComment, BlockComment, GlobalDocComment, Comment, PreprocIdentifier, Max
};
using Token = pl::core::Token;
using TokenIter = pl::hlp::SafeIterator<std::vector<Token>::const_iterator>;
using Location = pl::core::Location;
using RegexList = std::vector<std::pair<std::regex, PaletteIndex>>;
using Keywords = std::unordered_set<std::string>;
using ErrorMarkers = std::map<Coordinates, std::pair<i32, std::string>>;
using Breakpoints = std::unordered_set<u32>;
using Palette = std::array<ImU32, (u64) PaletteIndex::Max>;
using Glyph = u8;
using CodeFoldBlocks = std::map<Coordinates,Coordinates>;
using Token = pl::core::Token;
using Tokens = std::vector<Token>;
using SafeTokenIterator = pl::hlp::SafeIterator<Tokens::const_iterator>;
using Location = pl::core::Location;
using RegexList = std::vector<std::pair<std::regex, PaletteIndex>>;
using Keywords = std::unordered_set<std::string>;
using ErrorMarkers = std::map<Coordinates, std::pair<i32, std::string>>;
using Breakpoints = std::unordered_set<u32>;
using Palette = std::array<ImU32, (u64) PaletteIndex::Max>;
using Glyph = u8;
using CodeFoldBlocks = std::map<Coordinates,Coordinates>;
using GlobalBlocks = std::set<Interval>;
struct Identifier { Coordinates m_location; std::string m_declaration;};
using Identifiers = std::unordered_map<std::string, Identifier>;
@@ -223,7 +228,7 @@ namespace hex::ui {
ActionableBox() : m_box(ImRect(ImVec2(0, 0), ImVec2(0, 0))) {};
explicit ActionableBox(const ImRect &box) : m_box(box) {}
ImRect &getBox() const { return const_cast<ImRect &>(m_box);}
[[nodiscard]] ImRect &getBox() const { return const_cast<ImRect &>(m_box);}
virtual bool trigger();
virtual void callback() {}
virtual ~ActionableBox() = default;
@@ -274,12 +279,12 @@ namespace hex::ui {
bool startHovered();
bool endHovered();
bool isDetected();
bool isOpen();
[[nodiscard]] bool isOpen() const;
void open();
void close();
void moveFold(float lineCount, float lineHeight);
private:
Lines *lines;
Lines *lines = nullptr;
Range key;
CursorChangeBox codeFoldStartCursorBox;
ActionableBox codeFoldEndActionBox;
@@ -302,14 +307,16 @@ namespace hex::ui {
using ErrorGotoBoxes = std::map<Coordinates, ErrorGotoBox>;
using CursorBoxes = std::map<Coordinates, CursorChangeBox>;
using ErrorHoverBoxes = std::map<Coordinates, ErrorHoverBox>;
using Keys = std::vector<Range>;
using CodeFoldKeys = std::set<Range>;
using CodeFoldDelimiters = std::map<Range,std::pair<char,char>>;
using Segments = std::vector<Coordinates>;
using CodeFoldKeyMap = std::map<Coordinates,Coordinates>;
using CodeFoldKeyLineMap = std::multimap<i32,Coordinates>;
using CodeFoldState = std::map<Range,bool>;
// using RowsToCodeFoldMap = std::map<u32,Interval>;
using Indices = std::vector<i32>;
using LineIndexToScreen = std::map<i32,ImVec2>;
using MultiLinesToRow = std::map<i32,i32>;
using IndexMap = std::map<i32,i32>;
using RowCodeFoldTooltips = std::map<i32,std::vector<CodeFoldTooltip>>;
enum class TrimMode : u8 { TrimNone = 0, TrimEnd = 1, TrimStart = 2, TrimBoth = 3 };
@@ -322,12 +329,12 @@ namespace hex::ui {
public:
friend class hex::ui::TextEditor;
friend class hex::ui::TextEditor::Lines;
LineIterator(const LineIterator &other) : m_charsIter(other.m_charsIter), m_colorsIter(other.m_colorsIter), m_flagsIter(other.m_flagsIter) {}
LineIterator(const LineIterator &other) = default;
LineIterator() = default;
char operator*();
LineIterator &operator++();
LineIterator operator=(const LineIterator &other);
LineIterator &operator=(const LineIterator &other);
bool operator!=(const LineIterator &other) const;
bool operator==(const LineIterator &other) const;
LineIterator operator+(i32 n);
@@ -359,20 +366,20 @@ namespace hex::ui {
};
union Flags {
Flags(char value) : m_value(value) {}
Flags(FlagBits bits) : m_bits(bits) {}
explicit Flags(char value) : m_value(value) {}
explicit Flags(FlagBits bits) : m_bits(bits) {}
FlagBits m_bits;
char m_value;
};
enum class LinePart { Chars, Utf8, Colors, Flags };
enum class LinePart : u8 { Chars, Utf8, Colors, Flags };
Line() : m_chars(""), m_colors(""), m_flags(""), m_colorized(false), m_lineMaxColumn(-1) {}
explicit Line(const char *line) { Line(std::string(line)); }
explicit Line(const std::string &line) : m_chars(line), m_colors(std::string(line.size(), 0x00)), m_flags(std::string(line.size(), 0x00)), m_colorized(false), m_lineMaxColumn(maxColumn()) {}
Line() : m_lineMaxColumn(-1) {}
explicit Line(const char *line) : Line(std::string(line)) {}
explicit Line(const std::string &line) : m_chars(line), m_colors(std::string(line.size(), 0x00)), m_flags(std::string(line.size(), 0x00)), m_lineMaxColumn(maxColumn()) {}
Line(const Line &line) : m_chars(std::string(line.m_chars)), m_colors(std::string(line.m_colors)), m_flags(std::string(line.m_flags)), m_colorized(line.m_colorized), m_lineMaxColumn(line.m_lineMaxColumn) {}
Line(Line &&line) noexcept : m_chars(std::move(line.m_chars)), m_colors(std::move(line.m_colors)), m_flags(std::move(line.m_flags)), m_colorized(line.m_colorized), m_lineMaxColumn(line.m_lineMaxColumn) {}
Line(std::string chars, std::string colors, std::string flags) : m_chars(std::move(chars)), m_colors(std::move(colors)), m_flags(std::move(flags)), m_colorized(false), m_lineMaxColumn(maxColumn()) {}
Line(std::string chars, std::string colors, std::string flags) : m_chars(std::move(chars)), m_colors(std::move(colors)), m_flags(std::move(flags)), m_lineMaxColumn(maxColumn()) {}
bool operator==(const Line &o) const;
bool operator!=(const Line &o) const;
@@ -382,7 +389,7 @@ namespace hex::ui {
[[nodiscard]] i32 columnIndex(i32 column) const;
[[nodiscard]] i32 textSize() const;
[[nodiscard]] i32 textSize(u32 index) const;
ImVec2 intervalToScreen(Interval stringIndices) const;
[[nodiscard]] ImVec2 intervalToScreen(Interval stringIndices) const;
i32 lineTextSize(TrimMode trimMode = TrimMode::TrimNone);
[[nodiscard]] i32 stringTextSize(const std::string &str) const;
i32 textSizeIndex(float textSize, i32 position);
@@ -403,19 +410,19 @@ namespace hex::ui {
[[nodiscard]] std::string substr(u64 start, u64 length = (u64) -1, LinePart part = LinePart::Chars) const;
Line subLine(u64 start, u64 length = (u64) -1);
char operator[](u64 index) const;
char at(u64 index) const;
[[nodiscard]] char at(u64 index) const;
// C++ can't overload functions based on return type, so use any type other
// than u64 to avoid ambiguity.
std::string operator[](i64 column) const;
std::string at(i64 column) const;
[[nodiscard]] std::string at(i64 column) const;
void setNeedsUpdate(bool needsUpdate);
void append(const char *text);
void append(const char text);
void append(char text);
void append(const std::string &text);
void append(const Line &line);
void append(LineIterator begin, LineIterator end);
void insert(LineIterator iter, const std::string &text);
void insert(LineIterator iter, const char text);
void insert(LineIterator iter, char text);
void insert(LineIterator iter, strConstIter beginString, strConstIter endString);
void insert(LineIterator iter, const Line &line);
void insert(LineIterator iter, LineIterator beginLine, LineIterator endLine);
@@ -461,16 +468,16 @@ namespace hex::ui {
Range findDelimiterCoordinates(Range key);
private:
Line m_foldedLine;
Lines *m_lines;
Lines *m_lines{};
Range m_full;
i32 m_row;
i32 m_row{};
FoldType m_type = FoldType::Invalid;
std::string m_brackets;
std::vector<Range> m_keys;
std::vector<Range> m_keysToRemove;
std::vector<i32> m_ellipsisIndices;
std::vector<Coordinates> m_foldedSegments;
std::vector<Coordinates> m_unfoldedSegments;
Keys m_keys;
Keys m_keysToRemove;
Indices m_ellipsisIndices;
Segments m_foldedSegments;
Segments m_unfoldedSegments;
Coordinates m_cursorPosition;
Range m_selection;
bool m_built = false;
@@ -480,7 +487,7 @@ namespace hex::ui {
public:
friend class Lines;
friend class TextEditor;
MatchedDelimiter() : m_active(false), m_changed(false), m_nearCursor(0, 0), m_matched(0, 0) {}
MatchedDelimiter() : m_nearCursor(0, 0), m_matched(0, 0) {}
MatchedDelimiter(bool active, bool changed, const Coordinates &nearCursor, const Coordinates &matched) : m_active(active), m_changed(changed), m_nearCursor(nearCursor), m_matched(matched) {}
bool checkPosition(Lines *lines, Coordinates &from);
@@ -494,15 +501,15 @@ namespace hex::ui {
private:
bool m_active = false;
bool m_changed = false;
Coordinates m_nearCursor = {};
Coordinates m_matched = {};
Coordinates m_nearCursor{};
Coordinates m_matched{};
};
class Segment {
class FoldSegment {
public:
friend class TextEditor;
Segment(Coordinates foldEnd, const Interval &segment) : m_foldEnd(foldEnd), m_segment(segment) {}
bool operator==(const Segment &o) const {
FoldSegment(Coordinates foldEnd, const Interval &segment) : m_foldEnd(foldEnd), m_segment(segment) {}
bool operator==(const FoldSegment &o) const {
return m_foldEnd == o.m_foldEnd && m_segment == o.m_segment;
}
private:
@@ -511,9 +518,9 @@ namespace hex::ui {
};
struct LanguageDefinition {
typedef std::pair<std::string, PaletteIndex> TokenRegexString;
typedef std::vector<TokenRegexString> TokenRegexStrings;
typedef bool(*TokenizeCallback)(strConstIter in_begin, strConstIter in_end, strConstIter &out_begin, strConstIter &out_end, PaletteIndex &paletteIndex);
using TokenRegexString = std::pair<std::string, PaletteIndex>;
using TokenRegexStrings = std::vector<TokenRegexString>;
using TokenizeCallback = bool (*)(strConstIter, strConstIter, strConstIter &, strConstIter &, PaletteIndex &);
std::string m_name;
Keywords m_keywords;
@@ -522,12 +529,11 @@ namespace hex::ui {
std::string m_singleLineComment, m_commentEnd, m_commentStart, m_globalDocComment, m_docComment, m_blockDocComment;
char m_preprocChar = '#';
bool m_autoIndentation = true;
TokenizeCallback m_tokenize;
TokenizeCallback m_tokenize = {};
TokenRegexStrings m_tokenRegexStrings;
bool m_caseSensitive = true;
LanguageDefinition() : m_keywords({}), m_identifiers({}), m_preprocIdentifiers({}),
m_tokenize(nullptr), m_tokenRegexStrings({}) {}
LanguageDefinition() : m_keywords({}), m_identifiers({}), m_preprocIdentifiers({}), m_tokenRegexStrings({}) {}
static const LanguageDefinition &CPlusPlus();
static const LanguageDefinition &HLSL();
@@ -544,14 +550,14 @@ namespace hex::ui {
class UndoRecord {
public:
friend class TextEditor;
UndoRecord() {}
~UndoRecord() {}
UndoRecord() = default;
~UndoRecord() = default;
UndoRecord( std::string added,
Range addedRange,
std::string removed,
Range removedRange,
EditorState &before,
EditorState &after);
EditorState before,
EditorState after);
void undo(TextEditor *editor);
void redo(TextEditor *editor);
@@ -564,13 +570,11 @@ namespace hex::ui {
EditorState m_after;
};
using UndoRecords = std::vector<UndoRecord>;
class UndoAction {
public:
UndoAction() {}
~UndoAction() {}
explicit UndoAction(const UndoRecords &records) : m_records(records) {}
UndoAction() = default;
~UndoAction() = default;
explicit UndoAction(UndoRecords records) : m_records(std::move(records)) {}
void undo(TextEditor *editor);
void redo(TextEditor *editor);
private:
@@ -581,25 +585,31 @@ namespace hex::ui {
public:
friend class Lines;
HiddenLine() = default;
HiddenLine(i32 lineIndex, const std::string &lineContent) : m_lineIndex(lineIndex), m_line(lineContent) {}
HiddenLine(i32 lineIndex, std::string lineContent) : m_lineIndex(lineIndex), m_line(std::move(lineContent)) {}
private:
i32 m_lineIndex;
i32 m_lineIndex{};
std::string m_line;
};
using CodeFolds = std::map<Range,CodeFold>;
using Segments = std::vector<Segment>;
using RowToSegments = std::map<i32,Segments>;
using UndoBuffer = std::vector<UndoAction>;
using RowToFoldedLine = std::map<i32,FoldedLine>;
enum class FoldSymbol : u8 { Line, Up, Down, Square };
using CodeFolds = std::map<Range, CodeFold>;
using FoldSegments = std::vector<FoldSegment>;
using RowToFoldSegments = std::map<i32, FoldSegments>;
using UndoBuffer = std::vector<UndoAction>;
using FoldedLines = std::map<i32, FoldedLine>;
using UnfoldedLines = std::vector<Line>;
using HiddenLines = std::vector<HiddenLine>;
using FoldSymbols = std::map<i32, FoldSymbol>;
using StringVector = std::vector<std::string>;
using RangeFromCoordinates = std::pair<Coordinates, Coordinates>;
bool areEqual(const std::pair<Range,CodeFold> &a, const std::pair<Range,CodeFold> &b);
class Lines {
public:
friend class TextEditor;
Lines() : m_unfoldedLines({}), m_foldedLines({}), m_hiddenLines({}), m_matchedDelimiter(), m_colorizerEnabled(true), m_defines({}) {}
enum class FoldSymbol { Line, Up, Down, Square };
Lines() : m_unfoldedLines({}), m_foldedLines({}), m_hiddenLines({}), m_defines({}) {}
Line &at(i32 index);
Line &operator[](i32 index);
@@ -621,7 +631,6 @@ namespace hex::ui {
void clearCursorBoxes() { m_cursorBoxes.clear(); }
void clearCodeFolds();
void addClickableText(std::string text) { m_clickableText.push_back(text); }
//void setErrorMarkers(const ErrorMarkers &markers) { m_errorMarkers = markers; }
Breakpoints &getBreakpoints() { return m_breakpoints; }
void saveCodeFoldStates();
void applyCodeFoldStates();
@@ -642,7 +651,7 @@ namespace hex::ui {
void moveUp(i32 amount, bool select);
void moveHome(bool select);
void moveEnd(bool select);
std::vector<Range> removeEmbeddedFolds();
Keys removeEmbeddedFolds();
bool isLastLine(i32 lineIndex);
bool isLastLine();
Coordinates find(const std::string &text, const Coordinates &start);
@@ -654,17 +663,17 @@ namespace hex::ui {
friend bool Range::Coordinates::isValid(Lines &lines);
friend TextEditor::Coordinates Range::Coordinates::sanitize(Lines &lines);
void appendLine(const std::string &value);
void readHiddenLines();
void writeHiddenLines();
void removeHiddenLinesFromPattern();
void addHiddenLinesToPattern();
void setSelection(const Range &selection);
Range getSelection() const;
ImVec2 getLineStartScreenPos(float leftMargin, float lineNumber);
ImVec2 &getCharAdvance() { return m_charAdvance; }
std::vector<Range> getDeactivatedBlocks();
Keys getDeactivatedBlocks();
std::string getSelectedText();
void deleteSelection();
inline void setTextChanged(bool value) { m_textChanged = value; }
inline bool isTextChanged() { return m_textChanged; }
void setTextChanged(bool value) { m_textChanged = value; }
bool isTextChanged() { return m_textChanged; }
void setLanguageDefinition(const LanguageDefinition &aLanguageDef);
const LanguageDefinition &getLanguageDefinition() const { return m_languageDefinition; }
TextEditor::PaletteIndex getColorIndexFromFlags(Line::Flags flags);
@@ -681,8 +690,8 @@ namespace hex::ui {
void openCodeFold(const Range &key);
void removeKeys();
ImVec2 indexCoordsToScreen(Coordinates indexCoords);
inline void setImGuiChildIgnored(bool value) { m_ignoreImGuiChild = value; }
inline bool isImGuiChildIgnored() const { return m_ignoreImGuiChild; }
void setImGuiChildIgnored(bool value) { m_ignoreImGuiChild = value; }
bool isImGuiChildIgnored() const { return m_ignoreImGuiChild; }
ImVec2 lineIndexToScreen(i32 lineIndex, Interval stringIndices);
void printCodeFold(const Range &key);
void resetCursorBlinkTime();
@@ -691,7 +700,7 @@ namespace hex::ui {
void setCursorPosition(const Coordinates &position, bool unfoldIfNeeded = true, bool scrollToCursor = true);
void setFocusAtCoords(const Coordinates &coords, bool ensureVisible = false);
void ensureCursorVisible();
std::vector<Coordinates> unfoldedEllipsisCoordinates(Range delimiterCoordinates);
Segments unfoldedEllipsisCoordinates(Range delimiterCoordinates);
Coordinates unfoldedToFoldedCoords(const Coordinates &coords);
Coordinates foldedToUnfoldedCoords(const Coordinates &coords);
void setScrollY();
@@ -699,59 +708,61 @@ namespace hex::ui {
Coordinates findNextWord(const Coordinates &from);
Line &insertLine(i32 index);
void deleteRange(const Range &rangeToDelete);
inline void clearBreakpointsChanged() { m_breakPointsChanged = false; }
inline bool isBreakpointsChanged() { return m_breakPointsChanged; }
void clearBreakpointsChanged() { m_breakPointsChanged = false; }
bool isBreakpointsChanged() { return m_breakPointsChanged; }
Coordinates stringIndexCoords(i32 strIndex, const std::string &input);
void refreshSearchResults();
inline void setReadOnly(bool value) { m_readOnly = value; }
void setReadOnly(bool value) { m_readOnly = value; }
void removeLines(i32 start, i32 end);
void removeLine(i32 index);
float textDistanceToLineStart(const Coordinates &from);
std::string getText(bool addHiddenLines = false);
std::string getText();
void setCursorPosition();
void ensureSelectionNotFolded();
bool hasSelection();
i32 insertTextAtCursor(const std::string &value);
void addUndo(std::vector<UndoRecord> value);
void addUndo(UndoRecords value);
void insertText(const std::string &value);
void insertText(const char *value);
Interval findBlockInRange(Interval interval);
std::vector<Interval> searchRangeForBlocks(Interval interval);
std::pair<Coordinates ,Coordinates> getDelimiterLineNumbers(i32 start, i32 end, const std::string &delimiters);
RangeFromCoordinates getDelimiterLineNumbers(i32 start, i32 end, const std::string &delimiters);
void nonDelimitedFolds();
std::pair<i32,i32> convertIndexToLineNumbers(Interval interval);
std::pair<i32,char> findMatchingDelimiter(i32 from);
CodeFoldBlocks foldPointsFromSource();
Coordinates findCommentEndCoord(i32 tokenId);
std::set<Interval> blocksFromGlobal();
void skipAttribute();
bool isTokenIdValid(i32 tokenId);
bool isLocationValid(Location location);
pl::core::Location getLocation(i32 tokenId);
i32 getTokenId(pl::core::Location location);
i32 getTokenId(SafeTokenIterator tokenIterator);
i32 getTokenId();
void loadFirstTokenIdOfLine();
i32 nextLine(i32 line);
void setAllCodeFolds();
void setCodeFoldState(CodeFoldState states);
CodeFoldState getCodeFoldState() const;
void advanceToNextLine(i32 &lineIndex, i32 &currentTokenId, Location &location);
void advanceTokenId(i32 &lineIndex, i32 &currentTokenId, Location &location);
void moveToLocationColumn(i32 locationColumn, i32 &currentTokenId, Location &location);
void incrementTokenId(i32 &lineIndex, i32 &currentTokenId, Location &location);
void moveToStringIndex(i32 stringIndex, i32 &currentTokenId, Location &location);
void resetToTokenId(i32 &lineIndex, i32 &currentTokenId, Location &location);
i32 findNextDelimiter(bool openOnly);
constexpr static u32 Normal = 0;
constexpr static u32 Not = 1;
template<typename T> T *getValue(const i32 index);
template<typename T> T *getValue(i32 index);
void next(i32 count = 1);
bool begin();
void partBegin();
void reset();
void partReset();
bool resetIfFailed(const bool value);
bool resetIfFailed(bool value);
template<auto S = Normal> bool sequenceImpl();
template<auto S = Normal> bool matchOne(const Token &token);
template<auto S = Normal> bool sequenceImpl(const auto &... args);
template<auto S = Normal> bool sequence(const Token &token, const auto &... args);
bool isValid();
bool peek(const Token &token, const i32 index = 0);
bool peek(const Token &token, i32 index = 0);
friend bool Coordinates::operator==(const Coordinates &o) const;
friend bool Coordinates::operator!=(const Coordinates &o) const;
@@ -763,53 +774,53 @@ namespace hex::ui {
friend Coordinates Coordinates::operator-(const Coordinates &o) const;
private:
std::vector<Line> m_unfoldedLines;
RowToFoldedLine m_foldedLines;
std::vector<HiddenLine> m_hiddenLines;
std::map<i32,FoldSymbol> m_rowToFoldSymbol = {};
MatchedDelimiter m_matchedDelimiter = {};
UnfoldedLines m_unfoldedLines;
FoldedLines m_foldedLines;
HiddenLines m_hiddenLines;
FoldSymbols m_rowToFoldSymbol;
MatchedDelimiter m_matchedDelimiter{};
bool m_colorizerEnabled = true;
std::vector<std::string> m_defines;
StringVector m_defines;
FindReplaceHandler m_findReplaceHandler;
RowToSegments m_rowToSegments = {};
EditorState m_state = {};
UndoBuffer m_undoBuffer = {};
std::vector<i32> m_leadingLineSpaces = {};
RowToFoldSegments m_rowToFoldSegments;
EditorState m_state;
UndoBuffer m_undoBuffer;
Indices m_leadingLineSpaces;
i32 m_undoIndex = 0;
bool m_updateFlags = true;
Breakpoints m_breakpoints = {};
ErrorMarkers m_errorMarkers = {};
ErrorHoverBoxes m_errorHoverBoxes = {};
ErrorGotoBoxes m_errorGotoBoxes = {};
CursorBoxes m_cursorBoxes = {};
CodeFoldKeys m_codeFoldKeys = {};
CodeFolds m_codeFolds = {};
CodeFoldKeyMap m_codeFoldKeyMap = {};
CodeFoldKeyMap m_codeFoldValueMap = {};
CodeFoldKeyLineMap m_codeFoldKeyLineMap = {};
CodeFoldKeyLineMap m_codeFoldValueLineMap = {};
CodeFoldDelimiters m_codeFoldDelimiters = {};
Range m_codeFoldHighlighted = {};
CodeFoldState m_codeFoldState = {};
Breakpoints m_breakpoints;
ErrorMarkers m_errorMarkers;
ErrorHoverBoxes m_errorHoverBoxes;
ErrorGotoBoxes m_errorGotoBoxes;
CursorBoxes m_cursorBoxes;
CodeFoldKeys m_codeFoldKeys;
CodeFolds m_codeFolds;
CodeFoldKeyMap m_codeFoldKeyMap;
CodeFoldKeyMap m_codeFoldValueMap;
CodeFoldKeyLineMap m_codeFoldKeyLineMap;
CodeFoldKeyLineMap m_codeFoldValueLineMap;
CodeFoldDelimiters m_codeFoldDelimiters;
Range m_codeFoldHighlighted;
CodeFoldState m_codeFoldState;
bool m_codeFoldsDisabled = false;
std::map<i32,i32> m_rowToLineIndex = {};
std::map<i32,i32> m_lineIndexToRow = {};
ImVec2 m_cursorScreenPosition = {};
ImVec2 m_lineNumbersStartPos = {};
LineIndexToScreen m_lineIndexToScreen = {};
MultiLinesToRow m_multiLinesToRow = {};
RowCodeFoldTooltips m_rowCodeFoldTooltips = {};
Range m_interactiveSelection = {};
std::vector<std::string> m_clickableText;
IndexMap m_rowToLineIndex;
IndexMap m_lineIndexToRow;
ImVec2 m_cursorScreenPosition;
ImVec2 m_lineNumbersStartPos;
LineIndexToScreen m_lineIndexToScreen;
IndexMap m_multiLinesToRow;
RowCodeFoldTooltips m_rowCodeFoldTooltips;
Range m_interactiveSelection;
StringVector m_clickableText;
float m_topRow = 0.0F;
bool m_setTopRow = false;
bool m_restoreSavedFolds = true;
ImVec2 m_charAdvance = {};
ImVec2 m_charAdvance;
float m_leftMargin = 0.0F;
float m_topMargin = 0.0F;
float m_lineNumberFieldWidth = 0.0F;
bool m_textChanged = false;
LanguageDefinition m_languageDefinition = {};
LanguageDefinition m_languageDefinition;
RegexList m_regexList;
float m_numberOfLinesDisplayed = 0;
bool m_withinRender = false;
@@ -818,7 +829,7 @@ namespace hex::ui {
std::string m_title;
bool m_unfoldIfNeeded = false;
bool m_scrollToCursor = false;
Coordinates m_focusAtCoords = {};
Coordinates m_focusAtCoords;
bool m_updateFocus = false;
float m_oldTopMargin = 0.0F;
float m_scrollYIncrement = 0.0F;
@@ -826,17 +837,18 @@ namespace hex::ui {
bool m_breakPointsChanged = false;
bool m_readOnly = false;
u64 m_startTime = 0;
bool m_codeFoldStateLoaded = false;
bool m_codeFoldsChanged = false;
bool m_saveCodeFoldStateRequested = false;
bool m_useSavedFoldStatesRequested = false;
bool m_foldsAreInstalled = false;
std::vector<Token> m_tokens;
TokenIter m_curr;
TokenIter m_startToken, m_originalPosition, m_partOriginalPosition;
Tokens m_tokens;
SafeTokenIterator m_curr;
SafeTokenIterator m_startToken, m_originalPosition, m_partOriginalPosition;
bool m_interrupt = false;
std::vector<i32> m_firstTokenIdOfLine;
Indices m_firstTokenIdOfLine;
CodeFoldBlocks m_foldPoints;
std::set<Interval> m_globalBlocks;
GlobalBlocks m_globalBlocks;
i32 m_cachedGlobalRowMax{};
bool m_globalRowMaxChanged = true;
};
private:
@@ -871,11 +883,11 @@ namespace hex::ui {
float rowToLineIndex(i32 row);
float lineIndexToRow(i32 lineNumber);
void clearErrorMarkers();
void clearActionables() {return m_lines.clearActionables();}
void clearActionables() { m_lines.clearActionables();}
void saveCodeFoldStates();
void applyCodeFoldStates();
void readHiddenLines() { m_lines.readHiddenLines(); };
void writeHiddenLines() { m_lines.writeHiddenLines(); };
void removeHiddenLinesFromPattern() { m_lines.removeHiddenLinesFromPattern(); };
void addHiddenLinesToPattern() { m_lines.addHiddenLinesToPattern(); };
// Highlighting
private:
@@ -889,7 +901,7 @@ namespace hex::ui {
void renderSquare(ImVec2 lineStartScreenPos, ImDrawList *drawList, float boxSize, float verticalMargin, i32 color);
void renderMinus(ImVec2 lineStartScreenPos, ImDrawList *drawList, float boxSize, float verticalMargin, i32 color);
void renderPlus(ImVec2 lineStartScreenPos, ImDrawList *drawList, float boxSize, float verticalMargin, i32 color);
void renderCodeFolds(i32 row, ImDrawList *drawList, i32 color, Lines::FoldSymbol state);
void renderCodeFolds(i32 row, ImDrawList *drawList, i32 color, FoldSymbol state);
void drawLineNumbers(float lineNumber);
void drawBreakpoints(float lineIndex, const ImVec2 &contentSize, ImDrawList *drawList, std::string title);
void drawCodeFolds(float lineIndex, ImDrawList *drawList);
@@ -931,12 +943,12 @@ namespace hex::ui {
bool isOverwrite() const { return m_overwrite; }
void setText(const std::string &text, bool undo = false);
void setImGuiChildIgnored(bool value) { m_lines.setImGuiChildIgnored(value); }
std::vector<std::string> getTextLines() const;
StringVector getTextLines() const;
void setLanguageDefinition(const LanguageDefinition &aLanguageDef) { m_lines.setLanguageDefinition(aLanguageDef); }
std::string getLineText(i32 line);
void setTextChanged(bool value) { m_lines.setTextChanged(value); }
std::string getText(bool addHiddenLines = false) { return m_lines.getText(addHiddenLines); }
void addUndo(std::vector<UndoRecord> value) { m_lines.addUndo(value); }
std::string getText() { return m_lines.getText(); }
void addUndo(UndoRecords value) { m_lines.addUndo(value); }
bool isTextChanged() { return m_lines.isTextChanged(); }
void setHandleMouseInputs(bool value) { m_handleMouseInputs = value; }
bool isHandleMouseInputsEnabled() const { return m_handleKeyboardInputs; }
@@ -967,7 +979,7 @@ namespace hex::ui {
void moveEnd(bool select = false);
void moveToMatchedDelimiter(bool select = false);
void setCursorPosition(const Coordinates &position, bool unfoldIfNeeded = true, bool scrollToCursor = true) {
return m_lines.setCursorPosition(position, unfoldIfNeeded, scrollToCursor);
m_lines.setCursorPosition(position, unfoldIfNeeded, scrollToCursor);
};
void setScroll(ImVec2 scroll);
ImVec2 getScroll() const {return m_scroll;}
@@ -995,8 +1007,8 @@ namespace hex::ui {
void codeFoldCollapse(i32 level=1, bool recursive=false, bool all=false);
i32 getCodeFoldLevel(i32 line) const;
void resetFoldedSelections();
void computeLPSArray(const std::string &pattern, std::vector<i32> & lps);
std::vector<i32> KMPSearch(const std::string& text, const std::string& pattern);
void computeLPSArray(const std::string &pattern, Indices & lps);
Indices KMPSearch(const std::string& text, const std::string& pattern);
bool isEmpty();
// utf8
@@ -1011,7 +1023,7 @@ namespace hex::ui {
Coordinates lineCoordsToIndexCoords(const Coordinates &coordinates);
private:
float m_lineSpacing = 1.0F;
Lines m_lines = {};
Lines m_lines;
float m_newTopMargin = 0.0F;
bool m_topMarginChanged = false;
i32 m_tabSize = 4;
@@ -1027,7 +1039,7 @@ namespace hex::ui {
TextEditor *m_sourceCodeEditor = nullptr;
float m_shiftedScrollY = 0;
bool m_setScroll = false;
ImVec2 m_scroll = {};
ImVec2 m_scroll;
float m_scrollOffset = 0;
float m_maxScroll =0;
bool m_scrollFromLines = false;