diff --git a/src/text_editor/buffer_helpers.cpp b/src/text_editor/buffer_helpers.cpp index 833f064..9b1f6e1 100644 --- a/src/text_editor/buffer_helpers.cpp +++ b/src/text_editor/buffer_helpers.cpp @@ -402,6 +402,11 @@ Int GetPrevChar(Buffer *buffer, Int pos) { return result; } +wchar_t GetChar(Buffer *buffer, Int pos) { + if (pos >= 0 && pos < buffer->len) return buffer->str[pos]; + return 0; +} + Int GetLineIndent(Buffer *buffer, Int line) { String16 string = GetLineStringWithoutNL(*buffer, line); Int indent = 0; @@ -421,6 +426,13 @@ Int GetIndentAtPos(Buffer *buffer, Int pos) { return result; } +Range GetIndentRangeAtPos(Buffer *buffer, Int pos) { + Int line = PosToLine(*buffer, pos); + Int indent = GetLineIndent(buffer, line); + Range range = GetLineRangeWithoutNL(*buffer, line); + return {range.min, range.min + indent}; +} + Range EncloseScope(Buffer *buffer, Int pos, wchar_t open, wchar_t close) { Range result = {pos, pos}; for (Int i = pos; i >= 0; i -= 1) { diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 79b3b36..7bbc63f 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -342,7 +342,25 @@ void Command_Delete(View *view, int direction, bool ctrl = false) { // Select things to delete For(view->carets) { if (GetSize(it.range)) continue; - it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED); + if (direction == DIR_LEFT) { + + // Delete indent in multiple of IndentSize + Range indent_range = GetIndentRangeAtPos(buffer, it.range.min); + if (it.range.min > indent_range.min && it.range.max <= indent_range.max) { + Int offset = it.range.min - indent_range.min; + Int to_delete = (offset % (StyleIndentSize)); + if (to_delete == 0) to_delete = StyleIndentSize; + to_delete = Clamp(to_delete, (Int)1, StyleIndentSize); + for (Int i = 0; i < to_delete; i += 1) { + it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED); + } + + } else { + it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED); + } + } else { + it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED); + } } MergeCarets(view); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index ad9b7d2..fae48c0 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -9,8 +9,7 @@ - fix the bug where when we create a new view the anchor value on new view is compromised because and incongruent with position so we select from start of buffer - hand cursor on hover over underlined word -- ctrl + q to open, alt + q to go back -- delete multiple spaces (based on indent size) on delete instead one by one +- delete multiple spaces (based on indent size) on delete instead one by one. It should only work at beginning of line, in indent area - 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) - we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace