about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-03-23 21:43:26 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-03-23 21:43:26 -0700
commitaa8994167f06680beba998a08e8f4d782537d540 (patch)
treeb809984f58eb96e27c5a075ac17a7b33fcb074b8
parent75dfd3fd623ea0755b1c5a5056af0e569dcfecc5 (diff)
parenta6dcfc5ac862637719b35c0fda137fdb4015c540 (diff)
downloadtext.love-aa8994167f06680beba998a08e8f4d782537d540.tar.gz
Merge lines.love
-rw-r--r--edit.lua14
-rw-r--r--log_browser.lua44
-rw-r--r--main.lua10
-rw-r--r--run.lua5
-rw-r--r--source.lua9
-rw-r--r--source_edit.lua14
6 files changed, 84 insertions, 12 deletions
diff --git a/edit.lua b/edit.lua
index 3f7ec34..871e48f 100644
--- a/edit.lua
+++ b/edit.lua
@@ -200,6 +200,20 @@ function edit.mouse_release(State, x,y, mouse_button)
 --?   print('selection:', State.selection1.line, State.selection1.pos)
 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}
+    for i=1,math.floor(dy) do
+      Text.up(State)
+    end
+  elseif dy < 0 then
+    State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}
+    for i=1,math.floor(-dy) do
+      Text.down(State)
+    end
+  end
+end
+
 function edit.text_input(State, t)
   if State.search_term then
     State.search_term = State.search_term..t
diff --git a/log_browser.lua b/log_browser.lua
index 5946e3e..46d84c0 100644
--- a/log_browser.lua
+++ b/log_browser.lua
@@ -263,25 +263,27 @@ end
 function log_browser.mouse_release(State, x,y, mouse_button)
 end
 
+function log_browser.mouse_wheel_move(State, dx,dy)
+  if dy > 0 then
+    for i=1,math.floor(dy) do
+      log_browser.up(State)
+    end
+  elseif dy < 0 then
+    for i=1,math.floor(-dy) do
+      log_browser.down(State)
+    end
+  end
+end
+
 function log_browser.text_input(State, t)
 end
 
 function log_browser.keychord_press(State, chord, key)
   -- move
   if chord == 'up' then
-    while State.screen_top1.line > 1 do
-      State.screen_top1.line = State.screen_top1.line-1
-      if should_show(State.lines[State.screen_top1.line]) then
-        break
-      end
-    end
+    log_browser.up(State)
   elseif chord == 'down' then
-    while State.screen_top1.line < #State.lines do
-      State.screen_top1.line = State.screen_top1.line+1
-      if should_show(State.lines[State.screen_top1.line]) then
-        break
-      end
-    end
+    log_browser.down(State)
   elseif chord == 'pageup' then
     local y = 0
     while State.screen_top1.line > 1 and y < App.screen.height - 100 do
@@ -301,6 +303,24 @@ function log_browser.keychord_press(State, chord, key)
   end
 end
 
+function log_browser.up(State)
+  while State.screen_top1.line > 1 do
+    State.screen_top1.line = State.screen_top1.line-1
+    if should_show(State.lines[State.screen_top1.line]) then
+      break
+    end
+  end
+end
+
+function log_browser.down(State)
+  while State.screen_top1.line < #State.lines do
+    State.screen_top1.line = State.screen_top1.line+1
+    if should_show(State.lines[State.screen_top1.line]) then
+      break
+    end
+  end
+end
+
 function log_browser.height(State, line_index)
   local line = State.lines[line_index]
   if line.data == nil then
diff --git a/main.lua b/main.lua
index 3166e56..4e8425e 100644
--- a/main.lua
+++ b/main.lua
@@ -248,6 +248,16 @@ function App.mousereleased(x,y, mouse_button)
   end
 end
 
+function App.wheelmoved(dx,dy)
+  if Current_app == 'run' then
+    if run.mouse_wheel_move then run.mouse_wheel_move(dx,dy) end
+  elseif Current_app == 'source' then
+    if source.mouse_wheel_move then source.mouse_wheel_move(dx,dy) end
+  else
+    assert(false, 'unknown app "'..Current_app..'"')
+  end
+end
+
 function love.quit()
   if Current_app == 'run' then
     local source_settings = Settings.source
diff --git a/run.lua b/run.lua
index 9af9604..ea96a76 100644
--- a/run.lua
+++ b/run.lua
@@ -163,6 +163,11 @@ function run.mouse_release(x,y, mouse_button)
   return edit.mouse_release(Editor_state, x,y, mouse_button)
 end
 
+function run.mouse_wheel_move(dx,dy)
+  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
+  return edit.mouse_wheel_move(Editor_state, dx,dy)
+end
+
 function run.text_input(t)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   return edit.text_input(Editor_state, t)
diff --git a/source.lua b/source.lua
index a390ed3..7621d6b 100644
--- a/source.lua
+++ b/source.lua
@@ -323,6 +323,15 @@ function source.mouse_release(x,y, mouse_button)
   end
 end
 
+function source.mouse_wheel_move(dx,dy)
+  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
+  if Focus == 'edit' then
+    return edit.mouse_wheel_move(Editor_state, dx,dy)
+  else
+    return log_browser.mouse_wheel_move(Log_browser_state, dx,dy)
+  end
+end
+
 function source.text_input(t)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   if Show_file_navigator then
diff --git a/source_edit.lua b/source_edit.lua
index 964f6ff..b70aab1 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -305,6 +305,20 @@ function edit.mouse_release(State, x,y, mouse_button)
   end
 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}
+    for i=1,math.floor(dy) do
+      Text.up(State)
+    end
+  elseif dy < 0 then
+    State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}
+    for i=1,math.floor(-dy) do
+      Text.down(State)
+    end
+  end
+end
+
 function edit.text_input(State, t)
   if State.search_term then
     State.search_term = State.search_term..t