about summary refs log tree commit diff stats
path: root/source_edit.lua
diff options
context:
space:
mode:
Diffstat (limited to 'source_edit.lua')
-rw-r--r--source_edit.lua39
1 files changed, 21 insertions, 18 deletions
diff --git a/source_edit.lua b/source_edit.lua
index 2dca05d..77487ea 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -142,14 +142,13 @@ function edit.cursor_on_text(State)
 end
 
 function edit.put_cursor_on_next_text_line(State)
-  while true do
-    if State.cursor1.line >= #State.lines then
-      break
-    end
-    if State.lines[State.cursor1.line].mode == 'text' then
-      break
-    end
-    State.cursor1.line = State.cursor1.line+1
+  local line = State.cursor1.line
+  if State.lines[line].mode == 'text' then return end
+  while line <= #State.lines and State.lines[line].mode ~= 'text' do
+    line = line+1
+  end
+  if line <= #State.lines and State.lines[line].mode == 'text' then
+    State.cursor1.line = line
     State.cursor1.pos = 1
   end
 end
@@ -233,8 +232,7 @@ function edit.quit(State)
   end
 end
 
-function edit.mouse_press(State, x,y, mouse_button)
-  love.keyboard.setTextInput(true)  -- bring up keyboard on touch screen
+function edit.mouse_press(State, x,y, mouse_button, is_touch, presses)
   if State.search_term then return end
   State.mouse_down = mouse_button
 --?   print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
@@ -281,7 +279,7 @@ function edit.mouse_press(State, x,y, mouse_button)
         State.lines.current_drawing_index = line_index
         State.lines.current_drawing = line
         Drawing.before = snapshot(State, line_index)
-        Drawing.mouse_press(State, line_index, x,y, mouse_button)
+        Drawing.mouse_press(State, line_index, x,y, mouse_button, is_touch, presses)
         return
       end
     end
@@ -294,12 +292,12 @@ function edit.mouse_press(State, x,y, mouse_button)
   State.selection1 = Text.final_text_loc_on_screen(State)
 end
 
-function edit.mouse_release(State, x,y, mouse_button)
+function edit.mouse_release(State, x,y, mouse_button, is_touch, presses)
   if State.search_term then return end
 --?   print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
   State.mouse_down = nil
   if State.lines.current_drawing then
-    Drawing.mouse_release(State, x,y, mouse_button)
+    Drawing.mouse_release(State, x,y, mouse_button, is_touch, presses)
     if Drawing.before then
       record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})
       Drawing.before = nil
@@ -385,7 +383,7 @@ function edit.text_input(State, t)
   schedule_save(State)
 end
 
-function edit.keychord_press(State, chord, key)
+function edit.keychord_press(State, chord, key, scancode, is_repeat)
   if State.selection1.line and
       not State.lines.current_drawing and
       -- printable character created using shift key => delete selection
@@ -408,9 +406,14 @@ function edit.keychord_press(State, chord, key)
       local len = utf8.len(State.search_term)
       local byte_offset = Text.offset(State.search_term, len)
       State.search_term = string.sub(State.search_term, 1, byte_offset-1)
-    elseif chord == 'down' then
-      State.cursor1.pos = State.cursor1.pos+1
+      State.cursor = deepcopy(State.search_backup.cursor)
+      State.screen_top = deepcopy(State.search_backup.screen_top)
       Text.search_next(State)
+    elseif chord == 'down' then
+      if #State.search_term > 0 then
+        Text.right(State)
+        Text.search_next(State)
+      end
     elseif chord == 'up' then
       Text.search_previous(State)
     end
@@ -499,7 +502,7 @@ function edit.keychord_press(State, chord, key)
     local drawing_index, drawing = Drawing.current_drawing(State)
     if drawing_index then
       local before = snapshot(State, drawing_index)
-      Drawing.keychord_press(State, chord)
+      Drawing.keychord_press(State, chord, key, scancode, is_repeat)
       record_undo_event(State, {before=before, after=snapshot(State, drawing_index)})
       schedule_save(State)
     end
@@ -532,7 +535,7 @@ function edit.keychord_press(State, chord, key)
     end
     schedule_save(State)
   else
-    Text.keychord_press(State, chord)
+    Text.keychord_press(State, chord, key, scancode, is_repeat)
   end
 end