From 3f16888fe0c8d1b61678caf707aa2da84547729a Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 4 Aug 2024 08:34:09 +0200 Subject: [PATCH] Home + left stops at indent --- src/text_editor/buffer_helpers.cpp | 11 ++++++----- src/text_editor/commands_window.cpp | 8 +++++++- src/text_editor/todo.txt | 5 ----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/text_editor/buffer_helpers.cpp b/src/text_editor/buffer_helpers.cpp index 0b995f8..337396e 100644 --- a/src/text_editor/buffer_helpers.cpp +++ b/src/text_editor/buffer_helpers.cpp @@ -400,10 +400,11 @@ Int GetLineIndent(Buffer *buffer, Int line) { break; } } - - // string = TrimEnd(string); - // if (EndsWith(string, L"{")) indent += StyleIndentSize; - // if (EndsWith(string, L"(")) indent += StyleIndentSize; - return indent; } + +Int GetIndentAtPos(Buffer *buffer, Int pos) { + Int line = PosToLine(*buffer, pos); + Int result = GetLineIndent(buffer, line); + return result; +} diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 15966c9..4c29a70 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -36,7 +36,13 @@ void Command_MoveCursorsToSide(View *view, int direction, bool shift = false) { if (direction == DIR_RIGHT) { pos = GetLineEnd(buffer, pos); } else { - pos = GetLineStart(buffer, pos); + Int indent = GetIndentAtPos(buffer, pos); + Int new_pos = GetLineStart(buffer, pos); + if (new_pos + indent != pos) { + pos = new_pos + indent; + } else { + pos = new_pos; + } } if (shift) { diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 933369e..86b0fa9 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -4,14 +4,9 @@ - switch to previous view (ctrl + tab) - save location on open and allow for revert (buffer id? or buffer name? - buffer name can change, buffer id is harder to serialize, I guess if internal only then buffer id) -- delete till indent -- indent on enter -- click 3 times to select line - we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace -- improve cursor movement, it's too clunky, too much stopping - should be able click on title bar of windows which disappear on losing focus - search backwards -- load selected string or auto enclosed word when midclick?, ctrl + click, ctrl + e? - experiment with using multiple cursors to select command and it's input - search as a command to execute which is going to be in the title bar - Ctrl + G should select the line number in bar