Fix automatic buffer reopen, modifying ctrl-left/right semantics inline with vscode/sublime, modifying load word semantics

This commit is contained in:
Krzosa Karol
2026-01-04 18:28:55 +01:00
parent 04e5642ce3
commit a7afdac4fa
4 changed files with 80 additions and 24 deletions

View File

@@ -4,8 +4,8 @@
- We need regex for: [FormatCode matching, IsCode matching, - We need regex for: [FormatCode matching, IsCode matching,
- Variable documentation - Variable documentation
- Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?) - 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. - IndentKind has issues with stuff still like cleaning whitespace etc.
- Remedybg commands integrated! (like clicking f5 and opening up the window)
Use session 4 Use session 4
- ListVariables instead of GenerateConfig, auto saving of variables - ListVariables instead of GenerateConfig, auto saving of variables

View File

@@ -307,7 +307,7 @@ API Int GetWordEnd(Buffer *buffer, Int pos) {
} }
API bool IsLoadWord(char16_t w) { 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) { if (!result) {
result = !(IsSymbol(w) || IsWhitespace(w)); result = !(IsSymbol(w) || IsWhitespace(w));
} }
@@ -360,21 +360,78 @@ API Int GetNextWordEnd(Buffer *buffer, Int pos) {
} }
API Int GetPrevWordStart(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; char16_t prev = 0;
Int i = pos - 1; Int i = pos - 1;
for (; i >= 0; i -= 1) { for (; i >= 0; i -= 1) {
if (prev == u'\n' || (prev && prev != buffer->str[i]) || IsWord(buffer->str[i])) { if (prev == u'\n' || (prev && prev != buffer->str[i]) || IsWord(buffer->str[i])) {
break; break;
} }
pos = i; pos = i;
prev = buffer->str[i]; prev = buffer->str[i];
} }
bool new_line = prev == u'\n'; bool new_line = prev == u'\n';
Int result = new_line ? pos : GetWordStart(buffer, pos); Int result = new_line ? pos : GetWordStart(buffer, pos);
return result; 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) { API Int GetLineStart(Buffer *buffer, Int pos) {
pos = Clamp(pos, (Int)0, buffer->len); pos = Clamp(pos, (Int)0, buffer->len);
Int line = PosToLine(buffer, pos); Int line = PosToLine(buffer, pos);

View File

@@ -364,7 +364,7 @@ void OnCommand(Event event) {
caret.ifront = 1; caret.ifront = 1;
} }
} else if (event.clicks >= 2 && InBounds({caret.range.min - 1, caret.range.max + 1}, p)) { } 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) { if (event.clicks >= 3) {
range = EncloseFullLine(active.buffer, p); range = EncloseFullLine(active.buffer, p);
} }
@@ -477,6 +477,18 @@ void GarbageCollect() {
ProfileFunction(); ProfileFunction();
Allocator sys_allocator = GetSystemAllocator(); 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) { IterRemove(Views) {
IterRemovePrepare(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(); GarbageCollect();
} }

View File

@@ -295,13 +295,13 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool
} break; } break;
case DIR_LEFT: { case DIR_LEFT: {
if (ctrl && shift) { if (ctrl && shift) {
Int pos = GetPrevWordStart(buffer, front); Int pos = OnCharClassBoundary_GetPrevWordStart(buffer, front);
it = SetFront(it, pos); it = SetFront(it, pos);
} else if (ctrl) { } else if (ctrl) {
if (range_size != 0 && front != it.range.min) { if (range_size != 0 && front != it.range.min) {
it = MakeCaret(it.range.min); it = MakeCaret(it.range.min);
} else { } else {
Int pos = GetPrevWordStart(buffer, it.range.min); Int pos = OnCharClassBoundary_GetPrevWordStart(buffer, it.range.min);
it = MakeCaret(pos); it = MakeCaret(pos);
} }
} else if (shift) { } else if (shift) {
@@ -318,13 +318,13 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool
} break; } break;
case DIR_RIGHT: { case DIR_RIGHT: {
if (ctrl && shift) { if (ctrl && shift) {
Int pos = GetNextWordEnd(buffer, front); Int pos = OnCharClassBoundary_GetNextWordEnd(buffer, front);
it = SetFront(it, pos); it = SetFront(it, pos);
} else if (ctrl) { } else if (ctrl) {
if (range_size != 0 && front != it.range.max) { if (range_size != 0 && front != it.range.max) {
it = MakeCaret(it.range.max); it = MakeCaret(it.range.max);
} else { } else {
Int pos = GetNextWordEnd(buffer, it.range.max); Int pos = OnCharClassBoundary_GetNextWordEnd(buffer, it.range.max);
it = MakeCaret(pos); it = MakeCaret(pos);
} }
} else if (shift) { } else if (shift) {