Changed block movement to mimic word movement

This commit is contained in:
rxi 2020-05-28 13:08:18 +01:00
parent 9c652086e8
commit 1b2fda2825
3 changed files with 14 additions and 14 deletions

View File

@ -322,8 +322,8 @@ local translations = {
["next-char"] = translate.next_char, ["next-char"] = translate.next_char,
["previous-word-start"] = translate.previous_word_start, ["previous-word-start"] = translate.previous_word_start,
["next-word-end"] = translate.next_word_end, ["next-word-end"] = translate.next_word_end,
["previous-start-of-block"] = translate.previous_start_of_block, ["previous-block-start"] = translate.previous_block_start,
["next-start-of-block"] = translate.next_start_of_block, ["next-block-end"] = translate.next_block_end,
["start-of-doc"] = translate.start_of_doc, ["start-of-doc"] = translate.start_of_doc,
["end-of-doc"] = translate.end_of_doc, ["end-of-doc"] = translate.end_of_doc,
["start-of-line"] = translate.start_of_line, ["start-of-line"] = translate.start_of_line,

View File

@ -85,30 +85,30 @@ function translate.end_of_word(doc, line, col)
end end
function translate.previous_start_of_block(doc, line, col) function translate.previous_block_start(doc, line, col)
while true do while true do
line = line - 1 line = line - 1
if line <= 1 then if line <= 1 then
return 1, 1 return 1, 1
end end
if doc.lines[line-1]:match("^%s*$") if doc.lines[line-1]:find("^%s*$")
and not doc.lines[line]:match("^%s*$") then and not doc.lines[line]:find("^%s*$") then
return line, (doc.lines[line]:find("%S")) return line, (doc.lines[line]:find("%S"))
end end
end end
end end
function translate.next_start_of_block(doc, line, col) function translate.next_block_end(doc, line, col)
while true do while true do
line = line + 1
if line >= #doc.lines then if line >= #doc.lines then
return #doc.lines, 1 return #doc.lines, 1
end end
if doc.lines[line-1]:match("^%s*$") if doc.lines[line+1]:find("^%s*$")
and not doc.lines[line]:match("^%s*$") then and not doc.lines[line]:find("^%s*$") then
return line, (doc.lines[line]:find("%S")) return line+1, #doc.lines[line+1]
end end
line = line + 1
end end
end end

View File

@ -157,8 +157,8 @@ keymap.add {
["down"] = { "command:select-next", "doc:move-to-next-line" }, ["down"] = { "command:select-next", "doc:move-to-next-line" },
["ctrl+left"] = "doc:move-to-previous-word-start", ["ctrl+left"] = "doc:move-to-previous-word-start",
["ctrl+right"] = "doc:move-to-next-word-end", ["ctrl+right"] = "doc:move-to-next-word-end",
["ctrl+["] = "doc:move-to-previous-start-of-block", ["ctrl+["] = "doc:move-to-previous-block-start",
["ctrl+]"] = "doc:move-to-next-start-of-block", ["ctrl+]"] = "doc:move-to-next-block-end",
["home"] = "doc:move-to-start-of-line", ["home"] = "doc:move-to-start-of-line",
["end"] = "doc:move-to-end-of-line", ["end"] = "doc:move-to-end-of-line",
["ctrl+home"] = "doc:move-to-start-of-doc", ["ctrl+home"] = "doc:move-to-start-of-doc",
@ -172,8 +172,8 @@ keymap.add {
["shift+down"] = "doc:select-to-next-line", ["shift+down"] = "doc:select-to-next-line",
["ctrl+shift+left"] = "doc:select-to-previous-word-start", ["ctrl+shift+left"] = "doc:select-to-previous-word-start",
["ctrl+shift+right"] = "doc:select-to-next-word-end", ["ctrl+shift+right"] = "doc:select-to-next-word-end",
["ctrl+shift+["] = "doc:select-to-previous-start-of-block", ["ctrl+shift+["] = "doc:select-to-previous-block-start",
["ctrl+shift+]"] = "doc:select-to-next-start-of-block", ["ctrl+shift+]"] = "doc:select-to-next-block-end",
["shift+home"] = "doc:select-to-start-of-line", ["shift+home"] = "doc:select-to-start-of-line",
["shift+end"] = "doc:select-to-end-of-line", ["shift+end"] = "doc:select-to-end-of-line",
["ctrl+shift+home"] = "doc:select-to-start-of-doc", ["ctrl+shift+home"] = "doc:select-to-start-of-doc",