about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--drawing_tests.lua2
-rw-r--r--edit.lua13
-rw-r--r--text.lua19
-rw-r--r--text_tests.lua2
5 files changed, 33 insertions, 8 deletions
diff --git a/README.md b/README.md
index 1a27ac7..690d94c 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,11 @@ found anything amiss: http://akkartik.name/contact
 * No clipping yet for drawings. In particular, circles/squares/rectangles and
   point labels can overflow a drawing.
 
+* If you ever see a crash when clicking on the mouse, it might be because a
+  mouse press and release need to happen in separate frames. Try pressing and
+  releasing more slowly and let me know if that helps or not. This is klunky,
+  sorry.
+
 * 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/drawing_tests.lua b/drawing_tests.lua
index ede25f0..64188df 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -3,7 +3,7 @@
 -- of specific shapes. In particular, no tests of freehand drawings.
 
 function test_creating_drawing_saves()
-  App.screen.init{width=120, height=60}
+  App.screen.init{width=800, height=600}
   Editor_state = edit.initialize_test_state()
   Editor_state.filename = 'foo'
   Editor_state.lines = load_array{}
diff --git a/edit.lua b/edit.lua
index b096274..42309df 100644
--- a/edit.lua
+++ b/edit.lua
@@ -66,8 +66,10 @@ function edit.initialize_state(top, left, right, font, font_height, line_height)
     --
     -- Make sure these coordinates are never aliased, so that changing one causes
     -- action at a distance.
+    --
+    -- On lines that are drawings, pos will be nil.
     screen_top1 = {line=1, pos=1},  -- position of start of screen line at top of screen
-    cursor1 = {line=1, pos=1},  -- position of cursor
+    cursor1 = {line=1, pos=1},  -- position of cursor; must be on a text line
     screen_bottom1 = {line=1, pos=1},  -- position of start of screen line at bottom of screen
 
     selection1 = {},
@@ -185,6 +187,7 @@ function edit.draw(State)
                        Drawing.before = snapshot(State, line_index-1, line_index)
                        table.insert(State.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})
                        table.insert(State.line_cache, line_index, {})
+                       for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end
                        if State.cursor1.line >= line_index then
                          State.cursor1.line = State.cursor1.line+1
                        end
@@ -292,10 +295,7 @@ function edit.mouse_press(State, x,y, mouse_button)
   State.old_cursor1 = State.cursor1
   State.old_selection1 = State.selection1
   State.mousepress_shift = App.shift_down()
-  State.selection1 = {
-      line=State.screen_bottom1.line,
-      pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
-  }
+  State.selection1 = Text.final_text_loc_on_screen(State)
 end
 
 function edit.mouse_release(State, x,y, mouse_button)
@@ -333,7 +333,7 @@ function edit.mouse_release(State, x,y, mouse_button)
     end
 
     -- still here? mouse release is below all screen lines
-    State.cursor1.line, State.cursor1.pos = State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
+    State.cursor1 = Text.final_text_loc_on_screen(State)
     edit.clean_up_mouse_press(State)
 --?     print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))
   end
@@ -596,6 +596,7 @@ end
 function edit.run_after_mouse_click(State, x,y, mouse_button)
   App.fake_mouse_press(x,y, mouse_button)
   edit.mouse_press(State, x,y, mouse_button)
+  edit.draw(State)
   App.fake_mouse_release(x,y, mouse_button)
   edit.mouse_release(State, x,y, mouse_button)
   App.screen.contents = {}
diff --git a/text.lua b/text.lua
index 9c27bde..d9e7653 100644
--- a/text.lua
+++ b/text.lua
@@ -621,6 +621,7 @@ function Text.pos_at_start_of_screen_line(State, loc1)
 end
 
 function Text.pos_at_end_of_screen_line(State, loc1)
+  assert(State.lines[loc1.line].mode == 'text')
   Text.populate_screen_line_starting_pos(State, loc1.line)
   local line_cache = State.line_cache[loc1.line]
   local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1
@@ -634,6 +635,24 @@ function Text.pos_at_end_of_screen_line(State, loc1)
   assert(false, ('invalid pos %d'):format(loc1.pos))
 end
 
+function Text.final_text_loc_on_screen(State)
+  if State.lines[State.screen_bottom1.line].mode == 'text' then
+    return {
+      line=State.screen_bottom1.line,
+      pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
+    }
+  end
+  local loc2 = Text.to2(State, State.screen_bottom1)
+  while true do
+    if State.lines[loc2.line].mode == 'text' then break end
+    assert(loc2.line > 1 or loc2.screen_line > 1 and loc2.screen_pos > 1)  -- elsewhere we're making sure there's always at least one text line on screen
+    loc2 = Text.previous_screen_line(State, loc2)
+  end
+  local result = Text.to1(State, loc2)
+  result.pos = Text.pos_at_end_of_screen_line(State, result)
+  return result
+end
+
 function Text.cursor_at_final_screen_line(State)
   Text.populate_screen_line_starting_pos(State, State.cursor1.line)
   local screen_lines = State.line_cache[State.cursor1.line].screen_line_starting_pos
diff --git a/text_tests.lua b/text_tests.lua
index b8f89db..44cdafc 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -16,7 +16,7 @@ function test_initial_state()
 end
 
 function test_click_to_create_drawing()
-  App.screen.init{width=120, height=60}
+  App.screen.init{width=800, height=600}
   Editor_state = edit.initialize_test_state()
   Editor_state.lines = load_array{}
   Text.redraw_all(Editor_state)