diff --git a/src/text_editor/buffer_history.cpp b/src/text_editor/buffer_history.cpp index 4898f20..2e92c0e 100644 --- a/src/text_editor/buffer_history.cpp +++ b/src/text_editor/buffer_history.cpp @@ -132,11 +132,16 @@ void AfterEdit(Buffer *buffer, Array *edits, Array *carets, bool ki for (Int i = 0; i < carets->len; i += 1) { Caret &old_cursor = carets->data[i]; Caret &new_cursor = new_carets.data[i]; + if (old_cursor.range.min == edit.range.min) { new_cursor.range.min += insert_size; - new_cursor.range.max += insert_size; } else if (old_cursor.range.min > edit.range.min) { new_cursor.range.min += offset; + } + + if (old_cursor.range.max == edit.range.max) { + new_cursor.range.max += insert_size; + } else if (old_cursor.range.max > edit.range.max) { new_cursor.range.max += offset; } } diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 1fa0b3c..f089917 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -31,7 +31,7 @@ void Command_DuplicateLine(View *view, int direction) { For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.min, direction, false)); } -void Command_IndentSelectedLines(View *view) { +void Command_IndentSelectedLines(View *view, bool shift = false) { Scratch scratch; Buffer *buffer = GetBuffer(view->active_buffer); @@ -65,7 +65,18 @@ void Command_IndentSelectedLines(View *view) { For(line_ranges_to_indent) { for (Int i = it.min; i <= it.max; i += 1) { Range pos_range_of_line = GetLineRange(*buffer, i); - AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, L" "); + + if (!shift) { + AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, L" "); + } else { + String16 string = GetString(*buffer, pos_range_of_line); + Int whitespace_len = 0; + for (Int i = 0; i < 4 && i < string.len && string.data[i] == ' '; i += 1) { + whitespace_len += 1; + } + + AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min + whitespace_len}, L""); + } } } @@ -401,8 +412,10 @@ void WindowCommand(Event event, Window *window, View *view) { } bool search = false; - if (Press(SDLK_TAB)) { - // Command_Replace(view, L" "); + if (Shift(SDLK_TAB)) { + Command_IndentSelectedLines(view, SHIFT_PRESSED); + search = true; + } else if (Press(SDLK_TAB)) { Command_IndentSelectedLines(view); search = true; } diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 0c7f30b..1464ebf 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -6,6 +6,7 @@ - underline the word which can be loaded / executed - search as a command to execute which is going to be in the title bar +- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection) - commands: - indent selected lines