about summary refs log tree commit diff stats
path: root/edit.lua
diff options
context:
space:
mode:
Diffstat (limited to 'edit.lua')
-rw-r--r--edit.lua50
1 files changed, 24 insertions, 26 deletions
diff --git a/edit.lua b/edit.lua
index eaa415e..edfcb20 100644
--- a/edit.lua
+++ b/edit.lua
@@ -1,7 +1,7 @@
 -- some constants people might like to tweak
 Text_color = {r=0, g=0, b=0}
 Cursor_color = {r=1, g=0, b=0}
-Highlight_color = {r=0.7, g=0.7, b=0.9}  -- selected text
+Highlight_color = {r=0.7, g=0.7, b=0.9, a=0.4}  -- selected text
 
 Margin_top = 15
 Margin_left = 25
@@ -97,7 +97,6 @@ function edit.invalid_cursor1(State)
   return cursor1.pos > #State.lines[cursor1.line].data + 1
 end
 
--- return y drawn until
 function edit.draw(State)
   love.graphics.setFont(State.font)
   App.color(Text_color)
@@ -122,7 +121,6 @@ function edit.draw(State)
   if State.search_term then
     Text.draw_search_bar(State)
   end
-  return y
 end
 
 function edit.update(State, dt)
@@ -147,8 +145,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))
@@ -190,15 +187,15 @@ 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 = Text.final_text_loc_on_screen(State)
+  State.selection1 = Text.final_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(%d,%d): cursor at %d,%d'):format(x,y, State.cursor1.line, State.cursor1.pos))
   State.mouse_down = nil
   if y < State.top then
-    State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
+    State.cursor1 = deepcopy(State.screen_top1)
     edit.clean_up_mouse_press(State)
     return
   end
@@ -216,7 +213,7 @@ function edit.mouse_release(State, x,y, mouse_button)
   end
 
   -- still here? mouse release is below all screen lines
-  State.cursor1 = Text.final_text_loc_on_screen(State)
+  State.cursor1 = Text.final_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
@@ -237,7 +234,7 @@ end
 
 function edit.mouse_wheel_move(State, dx,dy)
   if dy > 0 then
-    State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
+    State.cursor1 = deepcopy(State.screen_top1)
     for i=1,math.floor(dy) do
       Text.up(State)
     end
@@ -260,13 +257,13 @@ 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
       -- printable character created using shift key => delete selection
       -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
       (not App.shift_down() or utf8.len(key) == 1) and
       chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then
-    Text.delete_selection(State, State.left, State.right)
+    Text.delete_selection_and_record_undo_event(State)
   end
   if State.search_term then
     if chord == 'escape' then
@@ -274,7 +271,7 @@ function edit.keychord_press(State, chord, key)
       State.cursor1 = State.search_backup.cursor
       State.screen_top1 = State.search_backup.screen_top
       State.search_backup = nil
-      Text.redraw_all(State)  -- if we're scrolling, reclaim all fragments to avoid memory leaks
+      Text.redraw_all(State)  -- if we're scrolling, reclaim all line caches to avoid memory leaks
     elseif chord == 'return' then
       State.search_term = nil
       State.search_backup = nil
@@ -282,9 +279,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
@@ -316,9 +318,7 @@ function edit.keychord_press(State, chord, key)
       State.cursor1 = deepcopy(src.cursor)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.after, event.before)
-      patch_placeholders(State.line_cache, event.after, event.before)
-      -- if we're scrolling, reclaim all fragments to avoid memory leaks
-      Text.redraw_all(State)
+      Text.redraw_all(State)  -- if we're scrolling, reclaim all line caches to avoid memory leaks
       schedule_save(State)
     end
   elseif chord == 'C-y' then
@@ -329,8 +329,7 @@ function edit.keychord_press(State, chord, key)
       State.cursor1 = deepcopy(src.cursor)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.before, event.after)
-      -- if we're scrolling, reclaim all fragments to avoid memory leaks
-      Text.redraw_all(State)
+      Text.redraw_all(State)  -- if we're scrolling, reclaim all line caches to avoid memory leaks
       schedule_save(State)
     end
   -- clipboard
@@ -343,7 +342,7 @@ function edit.keychord_press(State, chord, key)
       App.set_clipboard(s)
     end
   elseif chord == 'C-x' then
-    local s = Text.cut_selection(State, State.left, State.right)
+    local s = Text.cut_selection_and_record_undo_event(State)
     if s then
       App.set_clipboard(s)
     end
@@ -365,20 +364,19 @@ function edit.keychord_press(State, chord, key)
     if Text.cursor_out_of_screen(State) then
       Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
     end
-    schedule_save(State)
     record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
-  -- dispatch to text
+    schedule_save(State)
   else
-    Text.keychord_press(State, chord)
+    Text.keychord_press(State, chord, key, scancode, is_repeat)
   end
 end
 
 function edit.key_release(State, key, scancode)
 end
 
-function edit.update_font_settings(State, font_height)
+function edit.update_font_settings(State, font_height, font)
   State.font_height = font_height
-  State.font = love.graphics.newFont(State.font_height)
+  State.font = font or love.graphics.newFont(State.font_height)
   State.line_height = math.floor(font_height*1.3)
 end