SelectComment

This commit is contained in:
Krzosa Karol
2026-01-30 22:16:22 +01:00
parent a87d2491bb
commit 903159d2bd

View File

@@ -227,3 +227,32 @@ void CheckKeybindingColission() {
} }
} }
} }
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");