diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 48f1343..d207366 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -226,4 +226,33 @@ void CheckKeybindingColission() { } } } -} \ No newline at end of file +} + +Range EncloseScope(Buffer *buffer, Int pos_min, Int pos_max, String16 open, String16 close) { + Range result = {pos_min, pos_max}; + String16 buffer_string = GetString(buffer); + for (Int i = pos_min - 1; i >= 0; i -= 1) { + String16 string = Skip(buffer_string, i); + if (StartsWith(string, open)) { + result.min = i + open.len; + break; + } + } + for (Int i = pos_max; i < buffer->len; i += 1) { + String16 string = Skip(buffer_string, i); + if (StartsWith(string, close)) { + result.max = i; + break; + } + } + return result; +} + +void CMD_SelectComment() { + BSet active = GetBSet(ActiveWindowID); + For (active.view->carets) { + Range scope = EncloseScope(active.buffer, it.range.min, it.range.max, u"/*", u"*/"); + it.range = scope; + } + +} RegisterCommand(CMD_SelectComment, "ctrl-shift-l", "Find /* and */ and select the content in between"); \ No newline at end of file