about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua29
1 files changed, 27 insertions, 2 deletions
diff --git a/text.lua b/text.lua
index 098129d..6661fd8 100644
--- a/text.lua
+++ b/text.lua
@@ -515,9 +515,22 @@ function Text.end_of_line(left, right)
 end
 
 function Text.word_left(left, right)
+  -- skip some whitespace
   while true do
+    if Cursor1.pos == 1 then
+      break
+    end
+    if Text.match(Lines[Cursor1.line].data, Cursor1.pos-1, '%S') then
+      break
+    end
     Text.left(left, right)
-    if Cursor1.pos == 1 then break end
+  end
+  -- skip some non-whitespace
+  while true do
+    Text.left(left, right)
+    if Cursor1.pos == 1 then
+      break
+    end
     assert(Cursor1.pos > 1)
     if Text.match(Lines[Cursor1.line].data, Cursor1.pos-1, '%s') then
       break
@@ -526,9 +539,21 @@ function Text.word_left(left, right)
 end
 
 function Text.word_right(left, right)
+  -- skip some whitespace
   while true do
+    if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then
+      break
+    end
+    if Text.match(Lines[Cursor1.line].data, Cursor1.pos, '%S') then
+      break
+    end
     Text.right_without_scroll()
-    if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then break end
+  end
+  while true do
+    Text.right_without_scroll()
+    if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then
+      break
+    end
     if Text.match(Lines[Cursor1.line].data, Cursor1.pos, '%s') then
       break
     end