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.
This commit is contained in:
parent
e568378ecb
commit
f1886391c5
14
edit.lua
14
edit.lua
|
@ -223,7 +223,7 @@ end
|
|||
|
||||
function edit.mouse_press(State, x,y, mouse_button)
|
||||
if State.search_term then return end
|
||||
--? print('press', State.cursor1.line)
|
||||
print_and_log(('edit.mouse_press: cursor at %d,%d').format(State.cursor1.line, State.cursor1.pos))
|
||||
if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
|
||||
-- press on a button and it returned 'true' to short-circuit
|
||||
return
|
||||
|
@ -241,6 +241,7 @@ function edit.mouse_press(State, x,y, mouse_button)
|
|||
-- press and hold to start a selection: sets selection on press, cursor on release
|
||||
-- press and hold, then press shift: ignore shift
|
||||
-- i.e. mouse_release should never look at shift state
|
||||
print_and_log(('edit.mouse_press: in line %d').format(line_index))
|
||||
State.old_cursor1 = State.cursor1
|
||||
State.old_selection1 = State.selection1
|
||||
State.mousepress_shift = App.shift_down()
|
||||
|
@ -248,7 +249,7 @@ function edit.mouse_press(State, x,y, mouse_button)
|
|||
line=line_index,
|
||||
pos=Text.to_pos_on_line(State, line_index, x, y),
|
||||
}
|
||||
--? print('selection', State.selection1.line, State.selection1.pos)
|
||||
print_and_log(('edit.mouse_press: selection now %d,%d').format(State.selection1.line, State.selection1.pos))
|
||||
break
|
||||
end
|
||||
elseif line.mode == 'drawing' then
|
||||
|
@ -266,7 +267,7 @@ end
|
|||
|
||||
function edit.mouse_release(State, x,y, mouse_button)
|
||||
if State.search_term then return end
|
||||
--? print('release', State.cursor1.line)
|
||||
print_and_log(('edit.mouse_release: cursor at %d,%d').format(State.cursor1.line, State.cursor1.pos))
|
||||
if State.lines.current_drawing then
|
||||
Drawing.mouse_release(State, x,y, mouse_button)
|
||||
schedule_save(State)
|
||||
|
@ -275,15 +276,16 @@ function edit.mouse_release(State, x,y, mouse_button)
|
|||
Drawing.before = nil
|
||||
end
|
||||
else
|
||||
print_and_log('edit.mouse_release: no current drawing')
|
||||
for line_index,line in ipairs(State.lines) do
|
||||
if line.mode == 'text' then
|
||||
if Text.in_line(State, line_index, x,y) then
|
||||
--? print('reset selection')
|
||||
print_and_log(('edit.mouse_release: in line %d').format(line_index))
|
||||
State.cursor1 = {
|
||||
line=line_index,
|
||||
pos=Text.to_pos_on_line(State, line_index, x, y),
|
||||
}
|
||||
--? print('cursor', State.cursor1.line, State.cursor1.pos)
|
||||
print_and_log(('edit.mouse_release: cursor now %d,%d').format(State.cursor1.line, State.cursor1.pos))
|
||||
if State.mousepress_shift then
|
||||
if State.old_selection1.line == nil then
|
||||
State.selection1 = State.old_cursor1
|
||||
|
@ -299,7 +301,7 @@ function edit.mouse_release(State, x,y, mouse_button)
|
|||
end
|
||||
end
|
||||
end
|
||||
--? print('selection:', State.selection1.line, State.selection1.pos)
|
||||
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
|
||||
end
|
||||
|
||||
|
|
5
run.lua
5
run.lua
|
@ -48,6 +48,11 @@ function run.initialize(arg)
|
|||
end
|
||||
end
|
||||
|
||||
function print_and_log(s)
|
||||
print(s)
|
||||
log(3, s)
|
||||
end
|
||||
|
||||
function run.load_settings()
|
||||
love.graphics.setFont(love.graphics.newFont(Settings.font_height))
|
||||
-- determine default dimensions and flags
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue