about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--text.lua16
-rw-r--r--text_tests.lua22
2 files changed, 33 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
diff --git a/text_tests.lua b/text_tests.lua
index a135aa8..1d508bc 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -141,6 +141,17 @@ function test_skip_to_previous_word()
   check_eq(Cursor1.pos, 1, 'F - test_skip_to_previous_word')
 end
 
+function test_skip_past_tab_to_previous_word()
+  io.write('\ntest_skip_past_tab_to_previous_word')
+  App.screen.init{width=120, height=60}
+  Lines = load_array{'abc def\tghi'}
+  Cursor1 = {line=1, pos=10}  -- within third word
+  Margin_right = 0; Margin_width = Margin_left
+  App.draw()
+  App.run_after_keychord('M-left')
+  check_eq(Cursor1.pos, 9, 'F - test_skip_past_tab_to_previous_word')
+end
+
 function test_move_to_start_of_word_on_previous_line()
   io.write('\ntest_move_to_start_of_word_on_previous_line')
   App.screen.init{width=120, height=60}
@@ -175,6 +186,17 @@ function test_skip_to_next_word()
   check_eq(Cursor1.pos, 8, 'F - test_skip_to_next_word')
 end
 
+function test_skip_past_tab_to_next_word()
+  io.write('\ntest_skip_past_tab_to_next_word')
+  App.screen.init{width=120, height=60}
+  Lines = load_array{'abc\tdef'}
+  Cursor1 = {line=1, pos=1}  -- at the space between words
+  Margin_right = 0; Margin_width = Margin_left
+  App.draw()
+  App.run_after_keychord('M-right')
+  check_eq(Cursor1.pos, 4, 'F - test_skip_past_tab_to_next_word')
+end
+
 function test_move_past_end_of_word_on_next_line()
   io.write('\ntest_move_past_end_of_word_on_next_line')
   App.screen.init{width=120, height=60}
3'>223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335