about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app.lua6
-rw-r--r--main.lua25
-rw-r--r--text.lua8
3 files changed, 27 insertions, 12 deletions
diff --git a/app.lua b/app.lua
index d7f3c72..99c1cd2 100644
--- a/app.lua
+++ b/app.lua
@@ -204,6 +204,12 @@ function App.run_after_mousepress(x,y, button)
   App.draw()
 end
 
+function App.run_after_mouserelease(x,y, button)
+  App.mousereleased(x,y, button)
+  App.screen.contents = {}
+  App.draw()
+end
+
 function App.screen.check(y, expected_contents, msg)
 --?   print('checking for "'..expected_contents..'" at y '..tostring(y))
   local screen_row = 'y'..tostring(y)
diff --git a/main.lua b/main.lua
index 3479cbc..d20fd2c 100644
--- a/main.lua
+++ b/main.lua
@@ -198,16 +198,8 @@ function App.mousepressed(x,y, mouse_button)
   for line_index,line in ipairs(Lines) do
     if line.mode == 'text' then
       if Text.in_line(line, x,y) then
-        if love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift') then
-          if Selection1.line == nil then
-            Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
-          end
-        else
-          if Selection1.line then
-            Selection1 = {}
-          end
-        end
         Text.move_cursor(line_index, line, x, y)
+        Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
       end
     elseif line.mode == 'drawing' then
       if Drawing.in_drawing(line, x, y) then
@@ -219,7 +211,20 @@ end
 
 function App.mousereleased(x,y, button)
   if Search_term then return end
-  Drawing.mouse_released(x,y, button)
+  if Lines.current_drawing then
+    Drawing.mouse_released(x,y, button)
+  else
+    for line_index,line in ipairs(Lines) do
+      if line.mode == 'text' then
+        if Text.in_line(line, x,y) then
+          Text.move_cursor(line_index, line, x, y)
+          if Text.eq1(Cursor1, Selection1) then
+            Selection1 = {}
+          end
+        end
+      end
+    end
+  end
 end
 
 function App.textinput(t)
diff --git a/text.lua b/text.lua
index 3c3bb9d..a2e22ab 100644
--- a/text.lua
+++ b/text.lua
@@ -499,7 +499,7 @@ function test_move_cursor_using_mouse()
   Screen_bottom1 = {}
   App.draw()  -- populate line.y for each line in Lines
   local screen_left_margin = 25  -- pixels
-  App.run_after_mousepress(screen_left_margin+8,Margin_top+5, '1')
+  App.run_after_mouserelease(screen_left_margin+8,Margin_top+5, '1')
   check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
   check_eq(Cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos')
 end
@@ -1039,7 +1039,7 @@ function test_position_cursor_on_recently_edited_wrapping_line()
   App.screen.check(y, 'stu', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:3')
   -- try to move the cursor earlier in the third screen line by clicking the mouse
   local screen_left_margin = 25  -- pixels
-  App.run_after_mousepress(screen_left_margin+8,Margin_top+Line_height*2+5, '1')
+  App.run_after_mouserelease(screen_left_margin+8,Margin_top+Line_height*2+5, '1')
   -- cursor should move
   check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
   check_eq(Cursor1.pos, 26, 'F - test_move_cursor_using_mouse/cursor:pos')
@@ -1980,6 +1980,10 @@ function Text.to1(pos2)
   return result
 end
 
+function Text.eq1(a, b)
+  return a.line == b.line and a.pos == b.pos
+end
+
 function Text.lt1(a, b)
   if a.line < b.line then
     return true