From 1590f12b43b7ea325c482d5ce94447c6b641c575 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 9 May 2025 10:56:17 +0200 Subject: [PATCH] Shift selects on last/first line --- src/text_editor/commands.cpp | 16 ++++++++++++---- src/text_editor/todo.txt | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 05767b3..8528645 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -293,8 +293,12 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool Int pos = GetPrevEmptyLineStart(buffer, it.range.min); it = MakeCaret(pos); } else if (shift) { - Int pos = OffsetByLine(buffer, front, -1); - it = SetFront(it, pos); + if (PosToLine(buffer, front) == 0) { + it = SetFront(it, 0); + } else { + Int pos = OffsetByLine(buffer, front, -1); + it = SetFront(it, pos); + } } else { if (range_size == 0) { Int pos = OffsetByLine(buffer, it.range.min, -1); @@ -312,8 +316,12 @@ Caret MoveCaret(Buffer *buffer, Caret it, int direction, bool ctrl = false, bool Int pos = GetNextEmptyLineStart(buffer, it.range.max); it = MakeCaret(pos); } else if (shift) { - Int pos = OffsetByLine(buffer, front, 1); - it = SetFront(it, pos); + if (LastLine(buffer) == PosToLine(buffer, front)) { + it = SetFront(it, buffer->len); + } else { + Int pos = OffsetByLine(buffer, front, 1); + it = SetFront(it, pos); + } } else { if (range_size == 0) { Int pos = OffsetByLine(buffer, it.range.max, 1); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 9dc391d..a4f0e3a 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -62,4 +62,4 @@ activate_buffer -!!As little lua code as possible, but lua code should be powerful just in case of quick edits +!!As little lua code as possible, but lua code should be powerful just in case of quick edits \ No newline at end of file