about summary refs log tree commit diff stats
path: root/select.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-06-01 12:20:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-06-01 12:30:19 -0700
commitf1886391c56e530bb1bb362a450aa9ab6cb8485c (patch)
tree20ae5cacb614159267dd226d83db8cbcc799e34a /select.lua
parente568378ecb13a6d49d24a5b820a20f65cc9004dc (diff)
downloadlines.love-f1886391c56e530bb1bb362a450aa9ab6cb8485c.tar.gz
some temporary logging to catch a bug
The bug has been spotted twice:

1. In snap.love, I selected text in one node, then another, and hit:
  Error: text.lua:789: attempt to compare nil with number
  stack traceback:
    text.lua:789: in function 'lt1'
    select.lua:19: in function 'clip_selection'
    text.lua:32: in function 'draw'
    edit.lua:117: in function 'draw'
    [string "REPL"]:21: in function 'draw'
    main.lua:152: in function 'draw'
    app.lua:102: in function <app.lua:84>
    [C]: in function 'xpcall'
    app.lua:112: in function <app.lua:111>
    [C]: in function 'xpcall'

  Couldn't reproduce.

2. In text.love, inscript selected all text in a small buffer and then
   clicked outside the text. And got:

  Error: text.lua:784: attempt to compare nil with number
  Traceback
    [love "callbacks.lua"]:228: in function 'handler'
    text.lua:784: in function 'lt1'
    select.lua:19: in function 'clip_selection'
    text.lua:27: in function 'draw'
    edit.lua:117: in function 'draw'
    run.lua:136: in function 'draw'
    main.lua:148: in function 'draw'
    app.lua:42: in function <app.lua:22>
    [C]: in function 'xpcall'

  This is reproducible, and also across forks.
Diffstat (limited to 'select.lua')
-rw-r--r--select.lua4
1 files changed, 4 insertions, 0 deletions
diff --git a/select.lua b/select.lua
index efb6909..094cca9 100644
--- a/select.lua
+++ b/select.lua
@@ -8,13 +8,17 @@
 -- Result: positions spos,epos between apos,bpos.
 function Text.clip_selection(State, line_index, apos, bpos)
   if State.selection1.line == nil then return nil,nil end
+  print_and_log('text.clip_selection')
   -- min,max = sorted(State.selection1,State.cursor1)
   local minl,minp = State.selection1.line,State.selection1.pos
+  print_and_log(('text.clip_selection: one end from selection: %d,%d'):format(minl,minp))
   local maxl,maxp
   if App.mouse_down(1) then
     maxl,maxp = Text.mouse_pos(State)
+    print_and_log(('text.clip_selection: other end from mouse: %d,%d'):format(maxl,maxp))
   else
     maxl,maxp = State.cursor1.line,State.cursor1.pos
+    print_and_log(('text.clip_selection: other end from cursor: %d,%d'):format(maxl,maxp))
   end
   if Text.lt1({line=maxl, pos=maxp},
               {line=minl, pos=minp}) then