EncloseSpace, EncloseScope changes

This commit is contained in:
Krzosa Karol
2025-05-11 16:24:06 +02:00
parent 3b48954bc1
commit a79f11d137
4 changed files with 31 additions and 13 deletions

View File

@@ -496,15 +496,15 @@ Int FindScopeEnd(Buffer *buffer, Int seek, Int max_seek, char16_t open, char16_t
return seek; return seek;
} }
Range EncloseScope(Buffer *buffer, Int pos, char16_t open, char16_t close) { Range EncloseScope(Buffer *buffer, Int pos_min, Int pos_max, char16_t open, char16_t close) {
Range result = {pos, pos}; Range result = {pos_min, pos_max};
for (Int i = pos; i >= 0; i -= 1) { for (Int i = pos_min - 1; i >= 0; i -= 1) {
if (buffer->str[i] == open) { if (buffer->str[i] == open) {
result.min = i; result.min = i;
break; break;
} }
} }
for (Int i = pos; i < buffer->len; i += 1) { for (Int i = pos_max; i < buffer->len; i += 1) {
if (buffer->str[i] == close) { if (buffer->str[i] == close) {
result.max = i + 1; result.max = i + 1;
break; break;

View File

@@ -667,6 +667,7 @@ void ApplyClangFormat(Buffer *buffer) {
Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string); Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string);
ReplaceWithoutMovingCarets(buffer, GetRange(buffer), {temp_buffer->str, temp_buffer->len}); ReplaceWithoutMovingCarets(buffer, GetRange(buffer), {temp_buffer->str, temp_buffer->len});
} }
int Lua_ApplyClangFormat(lua_State *L) { int Lua_ApplyClangFormat(lua_State *L) {
lua_Integer buffer_id = luaL_checkinteger(L, 1); lua_Integer buffer_id = luaL_checkinteger(L, 1);
lua_pop(L, 1); lua_pop(L, 1);
@@ -731,6 +732,23 @@ void EncloseLine(View *view) {
} }
} }
void EncloseScope(View *view) {
Buffer *buffer = GetBuffer(view->active_buffer);
For (view->carets) {
it.range = EncloseScope(buffer, it.range.min - 1, it.range.max + 1, u'(', u')');
it.range.min = Clamp(buffer, it.range.min + 1);
it.range.max = Clamp(buffer, it.range.max - 1);
}
}
void EncloseSpace(View *view) {
Buffer *buffer = GetBuffer(view->active_buffer);
For (view->carets) {
it.range.min = GetPrevEmptyLineStart(buffer, it.range.min);
it.range.max = GetNextEmptyLineStart(buffer, it.range.max);
}
}
void Command_Delete(View *view, int direction, bool ctrl = false) { void Command_Delete(View *view, int direction, bool ctrl = false) {
Assert(direction == DIR_LEFT || direction == DIR_RIGHT); Assert(direction == DIR_LEFT || direction == DIR_RIGHT);
Scratch scratch; Scratch scratch;

View File

@@ -399,10 +399,6 @@ void OnCommand(Event event) {
ToggleVisibility(DebugWindowID); ToggleVisibility(DebugWindowID);
} }
if (Press(SDLK_F5)) {
AppIsRunning = false;
}
if (Press(SDLK_F11)) { if (Press(SDLK_F11)) {
Command_ToggleFullscreen(); Command_ToggleFullscreen();
} }
@@ -688,7 +684,9 @@ void OnCommand(Event event) {
} }
if (CtrlPress(SDLK_L)) { if (CtrlShiftPress(SDLK_L)) {
EncloseSpace(active.view);
} else if (CtrlPress(SDLK_L)) {
EncloseLine(active.view); EncloseLine(active.view);
} }

View File

@@ -5,6 +5,9 @@
- Delete directory/file on disk command - Delete directory/file on disk command
- Check. Convert more commands to taking buffer instead of view - Check. Convert more commands to taking buffer instead of view
- Check. Rewrite more commands to use already implemented commands? - Check. Rewrite more commands to use already implemented commands?
- Lua OnCommand should be able to comunicate that we don't want C handling and do only the Lua handling
- Easily programmable F1-F12 commands
- Lua namespaces for different kinds of commands (by ids, using main_set, using active_set)?
- Set window layout using project file - Set window layout using project file
- Split command - Split command
@@ -15,11 +18,10 @@
- Fix jump scroll, the query ends up the last line on screen, kind of wacky - Fix jump scroll, the query ends up the last line on screen, kind of wacky
- Fix Ctrl+1 Ctrl+2 (choosing window) - Fix Ctrl+1 Ctrl+2 (choosing window)
- Fix search, should have an anchor - Fix search, should have an anchor
- Use project file as working dir instead of scratch buffer path, separate project dir and project file - Use project file as working dir instead of scratch buffer path, separate project dir and project file
- Remedybg integration
- Enclose line (Ctrl + L) - GetLine()
- Enclose most outer scope (but without the last chars, this would be for eval) - in lua start debugging, jump to line, start debugger on file
- Enclose scope - Enclose scope
- save all relevant buffers and build - save all relevant buffers and build