From cebb280fe546190e55e071b6adbf37cd47950f34 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Mon, 11 May 2026 15:07:55 -0500 Subject: initial commit --- runtime/lua/core/motion.lua | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 runtime/lua/core/motion.lua (limited to 'runtime/lua/core/motion.lua') diff --git a/runtime/lua/core/motion.lua b/runtime/lua/core/motion.lua new file mode 100644 index 0000000..a6bcb80 --- /dev/null +++ b/runtime/lua/core/motion.lua @@ -0,0 +1,66 @@ +local M = {} + +local function is_word_char(ch) + if ch == "" then + return false + end + local byte = string.byte(ch) + if not byte then + return false + end + + if byte >= string.byte("a") and byte <= string.byte("z") then + return true + end + if byte >= string.byte("A") and byte <= string.byte("Z") then + return true + end + if byte >= string.byte("0") and byte <= string.byte("9") then + return true + end + return ch == "_" +end + +function M.forward_word() + local len = editor.buffer_length() + local point = editor.point() + if point >= len then + return + end + + local ch = editor.char_at(point) + if is_word_char(ch) then + while point < len and is_word_char(editor.char_at(point)) do + point = point + 1 + end + else + while point < len and not is_word_char(editor.char_at(point)) do + point = point + 1 + end + while point < len and is_word_char(editor.char_at(point)) do + point = point + 1 + end + end + + editor.set_point(point) +end + +function M.backward_word() + local point = editor.point() + if point <= 0 then + return + end + + point = point - 1 + while point >= 0 and not is_word_char(editor.char_at(point)) do + point = point - 1 + end + + while point >= 0 and is_word_char(editor.char_at(point)) do + point = point - 1 + end + + editor.set_point(point + 1) +end + +return M -- cgit v1.3.1