diff --git a/src/text_editor/buffer_helpers.cpp b/src/text_editor/buffer_helpers.cpp index bae97e2..4cb8556 100644 --- a/src/text_editor/buffer_helpers.cpp +++ b/src/text_editor/buffer_helpers.cpp @@ -363,6 +363,20 @@ Int GetLineEnd(Buffer *buffer, Int pos) { return range.max; } +Int GetFullLineStart(Buffer *buffer, Int pos) { + pos = Clamp(pos, (Int)0, buffer->len); + Int line = PosToLine(*buffer, pos); + Range range = GetLineRange(*buffer, line); + return range.min; +} + +Int GetFullLineEnd(Buffer *buffer, Int pos) { + pos = Clamp(pos, (Int)0, buffer->len); + Int line = PosToLine(*buffer, pos); + Range range = GetLineRange(*buffer, line); + return range.max; +} + Int GetBufferEnd(Buffer *buffer) { return buffer->len; } @@ -429,6 +443,11 @@ Range EncloseLine(Buffer *buffer, Int pos) { return result; } +Range EncloseFullLine(Buffer *buffer, Int pos) { + Range result = {GetFullLineStart(buffer, pos), GetFullLineEnd(buffer, pos)}; + return result; +} + Int OffsetByLine(Buffer *buffer, Int pos, Int line_offset) { XY xy = PosToXY(*buffer, pos); Int result = XYToPosWithoutNL(*buffer, {xy.col, xy.line + line_offset}); diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index ea1f598..6ce8235 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -354,10 +354,25 @@ bool GlobalCommand(Event event) { } } else if (event.clicks >= 2) { view->carets.len = 1; + if (InBounds({caret.range.min - 1, caret.range.max + 1}, p)) { - Range range = EncloseWord(buffer, p); - if (event.clicks == 3) range = EncloseLoadWord(buffer, p); - if (event.clicks >= 4) range = EncloseExecWord(buffer, p); + Range range = EncloseWord(buffer, p); + wchar_t scope = GetChar(buffer, p); + if (scope == '{' || scope == '}') { + range = EncloseScope(buffer, p, '{', '}'); + } else if (scope == '(' || scope == ')') { + range = EncloseScope(buffer, p, '(', ')'); + } else { + if (event.clicks == 3) { + Range load_word_range = EncloseLoadWord(buffer, p); + if (AreEqual(load_word_range, range)) { + load_word_range = EncloseFullLine(buffer, p); + } + range = load_word_range; + } + if (event.clicks >= 4) range = EncloseFullLine(buffer, p); + } + caret = MakeCaret(range.max, range.min); } else { caret = MakeCaret(p); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 66ddc55..8f3b4b7 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -2,6 +2,7 @@ - I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection) - ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting BUG: there is a click hang when switching windows sometimes, you click after select and it doesn't switch active window +BUG: when redo and ctrl pressed a bugged enclosure rect is shown - mouse execute - experiment with using multiple cursors to select command and it's input @@ -9,8 +10,13 @@ BUG: there is a click hang when switching windows sometimes, you click after sel - each buffer needs a directory even the special ones: C:\a\b\c\+errors? - open directories - resulting in buffer with dir listing and proper buffer name + + - clean \r\n into \n on trim and load +- Dump editor state to file +- make the editor replayable, store events and then replay, be careful about globals + - global config and local config - load all files in a directory @@ -19,7 +25,6 @@ BUG: there is a click hang when switching windows sometimes, you click after sel - Search and replace - select space between parens,braces but make it good -- make the editor replayable, store events and then replay, be careful about globals - Implement shell interaction (here we also could use the coroutine library) - word complete