Improved behaviour of and renamed `translate.next|previous_word_boundary`

This commit is contained in:
rxi 2020-05-28 11:50:03 +01:00
parent 74755f5b4a
commit 9c652086e8
3 changed files with 29 additions and 30 deletions

View File

@ -320,8 +320,8 @@ local commands = {
local translations = {
["previous-char"] = translate.previous_char,
["next-char"] = translate.next_char,
["previous-word-boundary"] = translate.previous_word_boundary,
["next-word-boundary"] = translate.next_word_boundary,
["previous-word-start"] = translate.previous_word_start,
["next-word-end"] = translate.next_word_end,
["previous-start-of-block"] = translate.previous_start_of_block,
["next-start-of-block"] = translate.next_start_of_block,
["start-of-doc"] = translate.start_of_doc,

View File

@ -28,33 +28,32 @@ function translate.next_char(doc, line, col)
end
function translate.previous_word_boundary(doc, line, col)
local char = doc:get_char(doc:position_offset(line, col, -1))
local inword = not is_non_word(char)
repeat
local line2, col2 = line, col
line, col = doc:position_offset(line, col, -1)
if line == line2 and col == col2 then
function translate.previous_word_start(doc, line, col)
local prev
while line > 1 or col > 1 do
local l, c = doc:position_offset(line, col, -1)
local char = doc:get_char(l, c)
if prev and prev ~= char or not is_non_word(char) then
break
end
local c = doc:get_char(doc:position_offset(line, col, -1))
until inword and is_non_word(c) or not inword and c ~= char
return line, col
prev, line, col = char, l, c
end
return translate.start_of_word(doc, line, col)
end
function translate.next_word_boundary(doc, line, col)
local char = doc:get_char(line, col)
local inword = not is_non_word(char)
repeat
local line2, col2 = line, col
line, col = doc:position_offset(line, col, 1)
if line == line2 and col == col2 then
function translate.next_word_end(doc, line, col)
local prev
local end_line, end_col = translate.end_of_doc(doc, line, col)
while line < end_line or col < end_col do
local char = doc:get_char(line, col)
if prev and prev ~= char or not is_non_word(char) then
break
end
local c = doc:get_char(line, col)
until inword and is_non_word(c) or not inword and c ~= char
return line, col
line, col = doc:position_offset(line, col, 1)
prev = char
end
return translate.end_of_word(doc, line, col)
end

View File

@ -132,12 +132,12 @@ keymap.add {
["shift+tab"] = "doc:unindent",
["backspace"] = "doc:backspace",
["shift+backspace"] = "doc:backspace",
["ctrl+backspace"] = "doc:delete-to-previous-word-boundary",
["ctrl+shift+backspace"] = "doc:delete-to-previous-word-boundary",
["ctrl+backspace"] = "doc:delete-to-previous-word-start",
["ctrl+shift+backspace"] = "doc:delete-to-previous-word-start",
["delete"] = "doc:delete",
["shift+delete"] = "doc:delete",
["ctrl+delete"] = "doc:delete-to-next-word-boundary",
["ctrl+shift+delete"] = "doc:delete-to-next-word-boundary",
["ctrl+delete"] = "doc:delete-to-next-word-end",
["ctrl+shift+delete"] = "doc:delete-to-next-word-end",
["return"] = { "command:submit", "doc:newline" },
["ctrl+return"] = "doc:newline-below",
["ctrl+shift+return"] = "doc:newline-above",
@ -155,8 +155,8 @@ keymap.add {
["right"] = "doc:move-to-next-char",
["up"] = { "command:select-previous", "doc:move-to-previous-line" },
["down"] = { "command:select-next", "doc:move-to-next-line" },
["ctrl+left"] = "doc:move-to-previous-word-boundary",
["ctrl+right"] = "doc:move-to-next-word-boundary",
["ctrl+left"] = "doc:move-to-previous-word-start",
["ctrl+right"] = "doc:move-to-next-word-end",
["ctrl+["] = "doc:move-to-previous-start-of-block",
["ctrl+]"] = "doc:move-to-next-start-of-block",
["home"] = "doc:move-to-start-of-line",
@ -170,8 +170,8 @@ keymap.add {
["shift+right"] = "doc:select-to-next-char",
["shift+up"] = "doc:select-to-previous-line",
["shift+down"] = "doc:select-to-next-line",
["ctrl+shift+left"] = "doc:select-to-previous-word-boundary",
["ctrl+shift+right"] = "doc:select-to-next-word-boundary",
["ctrl+shift+left"] = "doc:select-to-previous-word-start",
["ctrl+shift+right"] = "doc:select-to-next-word-end",
["ctrl+shift+["] = "doc:select-to-previous-start-of-block",
["ctrl+shift+]"] = "doc:select-to-next-start-of-block",
["shift+home"] = "doc:select-to-start-of-line",