diff --git a/src/backup/todo.txt b/src/backup/todo.txt index e50f149..8594b30 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -4,8 +4,8 @@ - We need regex for: [FormatCode matching, IsCode matching, - Variable documentation - Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?) -- String16 string <<<@= GetString(buffer, pos_range_of_line); - here deleted space + 'string', seems like same behavior as lite but different from Sublie/VSCode - IndentKind has issues with stuff still like cleaning whitespace etc. +- Remedybg commands integrated! (like clicking f5 and opening up the window) Use session 4 - ListVariables instead of GenerateConfig, auto saving of variables diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 3c41ce5..b17473e 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -307,7 +307,7 @@ API Int GetWordEnd(Buffer *buffer, Int pos) { } API bool IsLoadWord(char16_t w) { - bool result = w == u'(' || w == u')' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@' || w == u','; + bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@' || w == u','; if (!result) { result = !(IsSymbol(w) || IsWhitespace(w)); } @@ -360,21 +360,78 @@ API Int GetNextWordEnd(Buffer *buffer, Int pos) { } API Int GetPrevWordStart(Buffer *buffer, Int pos) { - pos = Clamp(pos, (Int)0, buffer->len); + pos = Clamp(pos, (Int)0, buffer->len); char16_t prev = 0; - Int i = pos - 1; + Int i = pos - 1; for (; i >= 0; i -= 1) { if (prev == u'\n' || (prev && prev != buffer->str[i]) || IsWord(buffer->str[i])) { break; } - pos = i; + pos = i; prev = buffer->str[i]; } bool new_line = prev == u'\n'; - Int result = new_line ? pos : GetWordStart(buffer, pos); + Int result = new_line ? pos : GetWordStart(buffer, pos); return result; } +enum CharClass { + CharClass_Whitespace, + CharClass_Symbol, + CharClass_Word, + CharClass_NewLine, +}; + +CharClass GetCharClass(char16_t c) { + if (c == '\n') { + return CharClass_NewLine; + } + + if (IsWhitespace(c)) { + return CharClass_Whitespace; + } + + if (c == '_') { + return CharClass_Word; + } + + if (IsSymbol(c)) { + return CharClass_Symbol; + } + + return CharClass_Word; +} + +API Int OnCharClassBoundary_GetNextWordEnd(Buffer *buffer, Int pos) { + Int i = Clamp(pos, (Int)0, buffer->len); + + while (i < buffer->len && GetCharClass(buffer->str[i]) == CharClass_Whitespace) { + i += 1; + } + + CharClass initial_char_class = GetCharClass(buffer->str[i]); + while (i < buffer->len && GetCharClass(buffer->str[i]) == initial_char_class) { + i += 1; + } + return i; +} + +API Int OnCharClassBoundary_GetPrevWordStart(Buffer *buffer, Int pos) { + pos = Clamp(pos, (Int)0, buffer->len); + Int i = pos - 1; + + while (i >= 0 && GetCharClass(buffer->str[i]) == CharClass_Whitespace) { + i -= 1; + } + + CharClass initial_word_class = GetCharClass(buffer->str[i]); + while (i >= 0 && GetCharClass(buffer->str[i]) == initial_word_class) { + i -= 1; + } + + return i + 1; +} + API Int GetLineStart(Buffer *buffer, Int pos) { pos = Clamp(pos, (Int)0, buffer->len); Int line = PosToLine(buffer, pos); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index abe72df..4d70e95 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -364,7 +364,7 @@ void OnCommand(Event event) { caret.ifront = 1; } } else if (event.clicks >= 2 && InBounds({caret.range.min - 1, caret.range.max + 1}, p)) { - Range range = EncloseWord(active.buffer, p); + Range range = EncloseLoadWord(active.buffer, p); if (event.clicks >= 3) { range = EncloseFullLine(active.buffer, p); } @@ -477,6 +477,18 @@ void GarbageCollect() { ProfileFunction(); Allocator sys_allocator = GetSystemAllocator(); + For(Buffers) { + if (it->file_mod_time) { + int64_t new_file_mod_time = GetFileModTime(it->name); + if (it->file_mod_time != new_file_mod_time) { + it->changed_on_disk = true; + if (it->dirty == false) { + ReopenBuffer(it); + } + } + } + } + IterRemove(Views) { IterRemovePrepare(Views); @@ -655,19 +667,6 @@ void Update(Event event) { } } - For(Buffers) { - if (it->file_mod_time) { - int64_t new_file_mod_time = GetFileModTime(it->name); - if (it->file_mod_time != new_file_mod_time) { - it->changed_on_disk = true; - if (it->dirty == false) { - ReopenBuffer(it); - } - } - } - } - - GarbageCollect(); } diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 3fcab0e..580cf7a 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -295,13 +295,13 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool } break; case DIR_LEFT: { if (ctrl && shift) { - Int pos = GetPrevWordStart(buffer, front); + Int pos = OnCharClassBoundary_GetPrevWordStart(buffer, front); it = SetFront(it, pos); } else if (ctrl) { if (range_size != 0 && front != it.range.min) { it = MakeCaret(it.range.min); } else { - Int pos = GetPrevWordStart(buffer, it.range.min); + Int pos = OnCharClassBoundary_GetPrevWordStart(buffer, it.range.min); it = MakeCaret(pos); } } else if (shift) { @@ -318,13 +318,13 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool } break; case DIR_RIGHT: { if (ctrl && shift) { - Int pos = GetNextWordEnd(buffer, front); + Int pos = OnCharClassBoundary_GetNextWordEnd(buffer, front); it = SetFront(it, pos); } else if (ctrl) { if (range_size != 0 && front != it.range.max) { it = MakeCaret(it.range.max); } else { - Int pos = GetNextWordEnd(buffer, it.range.max); + Int pos = OnCharClassBoundary_GetNextWordEnd(buffer, it.range.max); it = MakeCaret(pos); } } else if (shift) {