diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-25 15:47:11 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-25 15:47:11 -0700 |
commit | d1f893a98e80b3baf25aa9d30f8305c586569e66 (patch) | |
tree | 5e500df3120c2ee2a824b31f3be6d7705eec07f5 /text.lua | |
parent | 9892bc5d7c924ce284003a35c00914352713eb42 (diff) | |
download | text.love-d1f893a98e80b3baf25aa9d30f8305c586569e66.tar.gz |
M-left/M-right for word-based motions
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/text.lua b/text.lua index 7ff7baf..0668d17 100644 --- a/text.lua +++ b/text.lua @@ -772,6 +772,28 @@ function Text.keychord_pressed(chord) Text.left() elseif chord == 'right' then Text.right() + -- left/right by one word + -- C- hotkeys reserved for drawings, so we'll use M- + elseif chord == 'M-left' then + while true do + Text.left() + if Cursor1.pos == 1 then break end + assert(Cursor1.pos > 1) + local offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos) + assert(offset > 1) + if Lines[Cursor1.line].data:sub(offset-1,offset-1) == ' ' then + break + end + end + elseif chord == 'M-right' then + while true do + Text.right() + if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then break end + local offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos) + if Lines[Cursor1.line].data:sub(offset,offset) == ' ' then + break + end + end elseif chord == 'home' then Cursor1.pos = 1 elseif chord == 'end' then |