From 3765ef1d7afe2caaf77ad8c4be6d5e7d659f34ab Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sun, 20 Mar 2022 04:28:26 +0100 Subject: [PATCH] Move cursor to the beginning or the end of its selection When using `doc:move-to-{previous,next}-char` in a selection, we were moving the cursor to the character before the initial/after the last character of the selection. Now we follow what other editors do and move it to just before the initial/just after the final character. --- data/core/commands/doc.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index d80c4641..ed35913a 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -578,18 +578,20 @@ commands["doc:move-to-previous-char"] = function() for idx, line1, col1, line2, col2 in doc():get_selections(true) do if line1 ~= line2 or col1 ~= col2 then doc():set_selections(idx, line1, col1) + else + doc():move_to_cursor(idx, translate.previous_char) end end - doc():move_to(translate.previous_char) end commands["doc:move-to-next-char"] = function() for idx, line1, col1, line2, col2 in doc():get_selections(true) do if line1 ~= line2 or col1 ~= col2 then doc():set_selections(idx, line2, col2) + else + doc():move_to_cursor(idx, translate.next_char) end end - doc():move_to(translate.next_char) end command.add("core.docview", commands)