From 2bf56e67c5c660c79b96a3f71f5646f998462d81 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Fri, 6 Aug 2021 18:08:08 -0400 Subject: [PATCH] Changed behaviour of home. --- data/core/commands/doc.lua | 1 + data/core/doc/translate.lua | 4 ++++ data/core/keymap-macos.lua | 2 +- data/core/keymap.lua | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 60a913ce..95919a70 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -418,6 +418,7 @@ local translations = { ["start-of-line"] = translate.start_of_line, ["end-of-line"] = translate.end_of_line, ["start-of-word"] = translate.start_of_word, + ["start-of-indentation"] = translate.start_of_indentation, ["end-of-word"] = translate.end_of_word, ["previous-line"] = DocView.translate.previous_line, ["next-line"] = DocView.translate.next_line, diff --git a/data/core/doc/translate.lua b/data/core/doc/translate.lua index b084e89a..d1bde5f0 100644 --- a/data/core/doc/translate.lua +++ b/data/core/doc/translate.lua @@ -117,6 +117,10 @@ function translate.start_of_line(doc, line, col) return line, 1 end +function translate.start_of_indentation(doc, line, col) + local s, e = doc.lines[line]:find("^%s*") + return line, col > e + 1 and e + 1 or 1 +end function translate.end_of_line(doc, line, col) return line, math.huge diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index e233bb2e..757b25da 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -80,7 +80,7 @@ local function keymap_macos(keymap) ["cmd+right"] = "doc:move-to-next-word-end", ["cmd+["] = "doc:move-to-previous-block-start", ["cmd+]"] = "doc:move-to-next-block-end", - ["home"] = "doc:move-to-start-of-line", + ["home"] = "doc:move-to-start-of-indentation", ["end"] = "doc:move-to-end-of-line", ["cmd+home"] = "doc:move-to-start-of-doc", ["cmd+end"] = "doc:move-to-end-of-doc", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 86be82b1..a757cbc9 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -184,7 +184,7 @@ keymap.add_direct { ["ctrl+right"] = "doc:move-to-next-word-end", ["ctrl+["] = "doc:move-to-previous-block-start", ["ctrl+]"] = "doc:move-to-next-block-end", - ["home"] = "doc:move-to-start-of-line", + ["home"] = "doc:move-to-start-of-indentation", ["end"] = "doc:move-to-end-of-line", ["ctrl+home"] = "doc:move-to-start-of-doc", ["ctrl+end"] = "doc:move-to-end-of-doc",