about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-11 18:56:19 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-11 18:56:19 -0700
commitbc2c14c89921d255e99778e6c6b2c4f2e755d08f (patch)
tree01962ffb1dc9c75c21e7a08843f2bc9b168fff43 /text.lua
parent92e572fc8966d6f60f90c5c8311b082b84d67ed0 (diff)
downloadtext.love-bc2c14c89921d255e99778e6c6b2c4f2e755d08f.tar.gz
support other whitespace chars in word movements
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/text.lua b/text.lua
index 561df01..098129d 100644
--- a/text.lua
+++ b/text.lua
@@ -519,9 +519,7 @@ function Text.word_left(left, right)
     Text.left(left, right)
     if Cursor1.pos == 1 then break end
     assert(Cursor1.pos > 1)
-    local offset = Text.offset(Lines[Cursor1.line].data, Cursor1.pos)
-    assert(offset > 1)
-    if Lines[Cursor1.line].data:sub(offset-1,offset-1) == ' ' then
+    if Text.match(Lines[Cursor1.line].data, Cursor1.pos-1, '%s') then
       break
     end
   end
@@ -531,8 +529,7 @@ function Text.word_right(left, right)
   while true do
     Text.right_without_scroll()
     if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then break end
-    local offset = Text.offset(Lines[Cursor1.line].data, Cursor1.pos)
-    if Lines[Cursor1.line].data:sub(offset,offset) == ' ' then  -- TODO: other space characters
+    if Text.match(Lines[Cursor1.line].data, Cursor1.pos, '%s') then
       break
     end
   end
@@ -541,6 +538,15 @@ function Text.word_right(left, right)
   end
 end
 
+function Text.match(s, pos, pat)
+  local start_offset = Text.offset(s, pos)
+  assert(start_offset)
+  local end_offset = Text.offset(s, pos+1)
+  assert(end_offset > start_offset)
+  local curr = s:sub(start_offset, end_offset-1)
+  return curr:match(pat)
+end
+
 function Text.left(left, right)
   assert(Lines[Cursor1.line].mode == 'text')
   if Cursor1.pos > 1 then