about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Manual_tests.md3
-rw-r--r--main.lua7
-rw-r--r--text.lua35
3 files changed, 45 insertions, 0 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 75b37d8..8e9a02c 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -20,3 +20,6 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
   Several bugs have arisen due to destructive interference between the two for
   some key chord. I wish I could guarantee that the two sets are disjoint. But
   perhaps I'm not thinking about this right.
+
+* Like any high-level language, it's easy to accidentally alias two non-scalar
+  variables. I wish there was a way to require copy when assigning.
diff --git a/main.lua b/main.lua
index e822ce4..a6674be 100644
--- a/main.lua
+++ b/main.lua
@@ -52,6 +52,9 @@ Lines = {{mode='text', data=''}}
 --
 -- Most of the time we'll only persist positions in schema 1, translating to
 -- schema 2 when that's convenient.
+--
+-- Make sure these coordinates are never aliased, so that changing one causes
+-- action at a distance.
 Screen_top1 = {line=1, pos=1}  -- position of start of screen line at top of screen
 Cursor1 = {line=1, pos=1}  -- position of cursor
 Screen_bottom1 = {line=1, pos=1}  -- position of start of screen line at bottom of screen
@@ -187,6 +190,8 @@ function App.resize(w, h)
 --?   print(("Window resized to width: %d and height: %d."):format(w, h))
   App.screen.width, App.screen.height = w, h
   Text.redraw_all()
+  Selection1 = {}  -- no support for shift drag while we're resizing
+  Text.tweak_screen_top_and_cursor()
   Last_resize_time = App.getTime()
 end
 
@@ -321,6 +326,7 @@ end
 
 function App.mousepressed(x,y, mouse_button)
   if Search_term then return end
+--?   print('press')
   propagate_to_button_handlers(x,y, mouse_button)
 
   for line_index,line in ipairs(Lines) do
@@ -354,6 +360,7 @@ end
 
 function App.mousereleased(x,y, button)
   if Search_term then return end
+--?   print('release')
   if Lines.current_drawing then
     Drawing.mouse_released(x,y, button)
     schedule_save()
diff --git a/text.lua b/text.lua
index 8765798..7307056 100644
--- a/text.lua
+++ b/text.lua
@@ -915,6 +915,41 @@ function Text.populate_screen_line_starting_pos(line_index)
   end
 end
 
+function Text.tweak_screen_top_and_cursor()
+--?   print('a', Selection1.line)
+  if Screen_top1.pos == 1 then return end
+  Text.populate_screen_line_starting_pos(Screen_top1.line)
+  local line = Lines[Screen_top1.line]
+  for i=2,#line.screen_line_starting_pos do
+    local pos = line.screen_line_starting_pos[i]
+    if pos == Screen_top1.pos then
+      break
+    end
+    if pos > Screen_top1.pos then
+      -- make sure screen top is at start of a screen line
+      local prev = line.screen_line_starting_pos[i-1]
+      if Screen_top1.pos - prev < pos - Screen_top1.pos then
+        Screen_top1.pos = prev
+      else
+        Screen_top1.pos = pos
+      end
+      break
+    end
+  end
+  -- make sure cursor is on screen
+  if Text.lt1(Cursor1, Screen_top1) then
+    Cursor1 = {line=Screen_top1.line, pos=Screen_top1.pos}
+  elseif Cursor1.line >= Screen_bottom1.line then
+--?     print('too low')
+    App.draw()
+    if Text.lt1(Screen_bottom1, Cursor1) then
+--?       print('tweak')
+      local line = Lines[Screen_bottom1.line]
+      Cursor1 = {line=Screen_bottom1.line, pos=Text.to_pos_on_line(line, App.screen.width-5, App.screen.height-5)}
+    end
+  end
+end
+
 function Text.redraw_all()
 --?   print('clearing fragments')
   for _,line in ipairs(Lines) do