about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--edit.lua6
-rw-r--r--text.lua3
-rw-r--r--text_tests.lua19
4 files changed, 28 insertions, 4 deletions
diff --git a/README.md b/README.md
index 25da355..c09ed25 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,10 @@ found anything amiss: http://akkartik.name/contact
 * No clipping yet for drawings. In particular, circles/squares/rectangles and
   point labels can overflow a drawing.
 
+* Long wrapping lines can't yet distinguish between the cursor at end of one
+  screen line and start of the next, so clicking the mouse to position the
+  cursor can very occasionally do the wrong thing.
+
 * Touchpads can drag the mouse pointer using a light touch or a heavy click.
   On Linux, drags using the light touch get interrupted when a key is pressed.
   You'll have to press down to drag.
diff --git a/edit.lua b/edit.lua
index 9e32c8c..7006da8 100644
--- a/edit.lua
+++ b/edit.lua
@@ -131,9 +131,11 @@ end
 
 function edit.draw(State)
   App.color(Text_color)
---?   print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
   assert(#State.lines == #State.line_cache)
-  assert(Text.le1(State.screen_top1, State.cursor1))
+  if not Text.le1(State.screen_top1, State.cursor1) then
+    print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
+    assert(false)
+  end
   State.cursor_y = -1
   local y = State.top
 --?   print('== draw')
diff --git a/text.lua b/text.lua
index 3490f7c..ddc5661 100644
--- a/text.lua
+++ b/text.lua
@@ -691,7 +691,6 @@ function Text.in_line(State, line_index, x,y)
   local line = State.lines[line_index]
   local line_cache = State.line_cache[line_index]
   if line_cache.starty == nil then return false end  -- outside current page
-  if x < State.left then return false end
   if y < line_cache.starty then return false end
   Text.populate_screen_line_starting_pos(State, line_index)
   return y < line_cache.starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
@@ -759,7 +758,7 @@ end
 -- oblivious to wrapping
 -- result: 1 to len+1
 function Text.nearest_cursor_pos(line, x, left)
-  if x == 0 then
+  if x < left then
     return 1
   end
   local len = utf8.len(line)
diff --git a/text_tests.lua b/text_tests.lua
index 9f0b0e9..91c5364 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -269,6 +269,25 @@ function test_click_with_mouse()
   check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits')
 end
 
+function test_click_with_mouse_to_left_of_line()
+  io.write('\ntest_click_with_mouse_to_left_of_line')
+  -- display a line with the cursor in the middle
+  App.screen.init{width=50, height=80}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=3}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  -- click to the left of the line
+  edit.draw(Editor_state)
+  edit.run_after_mouse_click(Editor_state, Editor_state.left-4,Editor_state.top+5, 1)
+  -- cursor moves to start of line
+  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:line')
+  check_eq(Editor_state.cursor1.pos, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:pos')
+  check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_to_left_of_line/selection is empty to avoid perturbing future edits')
+end
+
 function test_click_with_mouse_takes_margins_into_account()
   io.write('\ntest_click_with_mouse_takes_margins_into_account')
   -- display two lines with cursor on one of them