diff options
-rw-r--r-- | edit.lua | 4 | ||||
-rw-r--r-- | select.lua | 11 | ||||
-rw-r--r-- | text_tests.lua | 46 |
3 files changed, 24 insertions, 37 deletions
diff --git a/edit.lua b/edit.lua index 82d9542..3e92a54 100644 --- a/edit.lua +++ b/edit.lua @@ -75,8 +75,6 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c old_cursor1 = nil, old_selection1 = nil, mousepress_shift = nil, - -- when selecting text, avoid recomputing some state on every single frame - recent_mouse = {}, -- cursor coordinates in pixels cursor_x = 0, @@ -249,7 +247,6 @@ function edit.mouse_press(State, x,y, mouse_button) line=line_index, pos=Text.to_pos_on_line(State, line_index, x, y), } - State.recent_mouse = {time=Current_time, line=State.selection1.line, pos=State.selection1.pos} break end elseif line.mode == 'drawing' then @@ -286,7 +283,6 @@ function edit.mouse_release(State, x,y, mouse_button) pos=Text.to_pos_on_line(State, line_index, x, y), } print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos)) - State.recent_mouse = {time=Current_time, line=State.cursor1.line, pos=State.cursor1.pos} if State.mousepress_shift then if State.old_selection1.line == nil then State.selection1 = State.old_cursor1 diff --git a/select.lua b/select.lua index d0509ef..dbd551b 100644 --- a/select.lua +++ b/select.lua @@ -69,17 +69,8 @@ end -- inefficient for some reason, so don't do it on every frame function Text.mouse_pos(State) - if State.recent_mouse.time and State.recent_mouse.time > Current_time-0.1 then - print_and_log(('text.mouse_pos: returning recent value %d,%d'):format(State.recent_mouse.line, State.recent_mouse.pos)) - return State.recent_mouse.line, State.recent_mouse.pos - end - State.recent_mouse.time = Current_time local line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y()) - if line then - State.recent_mouse.line = line - State.recent_mouse.pos = pos - end - return State.recent_mouse.line, State.recent_mouse.pos + return line, pos end function Text.to_pos(State, x,y) diff --git a/text_tests.lua b/text_tests.lua index bd449ac..eec3098 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -904,29 +904,29 @@ function test_select_all_text() check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos') end -function test_select_all_text_then_mouse_press_outside_text() - -- display a single line of text - App.screen.init{width=75, height=80} - Editor_state = edit.initialize_test_state() - Editor_state.lines = load_array{'abc def'} - Text.redraw_all(Editor_state) - Editor_state.cursor1 = {line=1, pos=1} - Editor_state.screen_top1 = {line=1, pos=1} - Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) - -- select all - App.fake_key_press('lctrl') - edit.run_after_keychord(Editor_state, 'C-a') - App.fake_key_release('lctrl') - edit.key_release(Editor_state, 'lctrl') - -- selection - check_eq(Editor_state.selection1.line, 1, 'selection:line') - check_eq(Editor_state.selection1.pos, 1, 'selection:pos') - check_eq(Editor_state.cursor1.line, 1, 'cursor:line') - check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos') - -- part of a mouse click outside the selected line - edit.run_after_mouse_press(Editor_state, 45, Margin_top + Editor_state.line_height + 10, --[[mouse button]] 1) -end +--? function test_select_all_text_then_mouse_press_outside_text() +--? -- display a single line of text +--? App.screen.init{width=75, height=80} +--? Editor_state = edit.initialize_test_state() +--? Editor_state.lines = load_array{'abc def'} +--? Text.redraw_all(Editor_state) +--? Editor_state.cursor1 = {line=1, pos=1} +--? Editor_state.screen_top1 = {line=1, pos=1} +--? Editor_state.screen_bottom1 = {} +--? edit.draw(Editor_state) +--? -- select all +--? App.fake_key_press('lctrl') +--? edit.run_after_keychord(Editor_state, 'C-a') +--? App.fake_key_release('lctrl') +--? edit.key_release(Editor_state, 'lctrl') +--? -- selection +--? check_eq(Editor_state.selection1.line, 1, 'selection:line') +--? check_eq(Editor_state.selection1.pos, 1, 'selection:pos') +--? check_eq(Editor_state.cursor1.line, 1, 'cursor:line') +--? check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos') +--? -- part of a mouse click outside the selected line +--? edit.run_after_mouse_press(Editor_state, 45, Margin_top + Editor_state.line_height + 10, --[[mouse button]] 1) +--? end function test_cut_without_selection() -- display a few lines |