click to the left of a line

This commit is contained in:
Kartik K. Agaram 2022-07-29 14:38:45 -07:00
parent 1e6b9e25aa
commit 0218980add
4 changed files with 28 additions and 4 deletions

View File

@ -63,6 +63,10 @@ found anything amiss: http://akkartik.name/contact
* No clipping yet for drawings. In particular, circles/squares/rectangles and
point labels can overflow a drawing.
* Long wrapping lines can't yet distinguish between the cursor at end of one
screen line and start of the next, so clicking the mouse to position the
cursor can very occasionally do the wrong thing.
* Touchpads can drag the mouse pointer using a light touch or a heavy click.
On Linux, drags using the light touch get interrupted when a key is pressed.
You'll have to press down to drag.

View File

@ -131,9 +131,11 @@ end
function edit.draw(State)
App.color(Text_color)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
assert(#State.lines == #State.line_cache)
assert(Text.le1(State.screen_top1, State.cursor1))
if not Text.le1(State.screen_top1, State.cursor1) then
print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
assert(false)
end
State.cursor_y = -1
local y = State.top
--? print('== draw')

View File

@ -691,7 +691,6 @@ function Text.in_line(State, line_index, x,y)
local line = State.lines[line_index]
local line_cache = State.line_cache[line_index]
if line_cache.starty == nil then return false end -- outside current page
if x < State.left then return false end
if y < line_cache.starty then return false end
Text.populate_screen_line_starting_pos(State, line_index)
return y < line_cache.starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
@ -759,7 +758,7 @@ end
-- oblivious to wrapping
-- result: 1 to len+1
function Text.nearest_cursor_pos(line, x, left)
if x == 0 then
if x < left then
return 1
end
local len = utf8.len(line)

View File

@ -269,6 +269,25 @@ function test_click_with_mouse()
check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits')
end
function test_click_with_mouse_to_left_of_line()
io.write('\ntest_click_with_mouse_to_left_of_line')
-- display a line with the cursor in the middle
App.screen.init{width=50, height=80}
Editor_state = edit.initialize_test_state()
Editor_state.lines = load_array{'abc'}
Text.redraw_all(Editor_state)
Editor_state.cursor1 = {line=1, pos=3}
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.screen_bottom1 = {}
-- click to the left of the line
edit.draw(Editor_state)
edit.run_after_mouse_click(Editor_state, Editor_state.left-4,Editor_state.top+5, 1)
-- cursor moves to start of line
check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_to_left_of_line/selection is empty to avoid perturbing future edits')
end
function test_click_with_mouse_takes_margins_into_account()
io.write('\ntest_click_with_mouse_takes_margins_into_account')
-- display two lines with cursor on one of them