support 2 cursors yet again

This time we assume that while a position may map to multiple rects,
only one of them will actually show the character.
This commit is contained in:
Kartik K. Agaram 2024-09-15 23:14:04 -07:00
parent 9d8a518085
commit 208cc02ed8
2 changed files with 6 additions and 6 deletions

View File

@ -157,7 +157,7 @@ function edit.draw(editor)
love.graphics.print(c.data, editor.left+c.x, y+c.y) love.graphics.print(c.data, editor.left+c.x, y+c.y)
end end
if line_index == editor.cursor.line then if line_index == editor.cursor.line then
if c.pos == editor.cursor.pos and c.show_cursor then if c.pos == editor.cursor.pos then
Text.draw_cursor(editor, editor.left+c.x, y+c.y) Text.draw_cursor(editor, editor.left+c.x, y+c.y)
end end
end end

View File

@ -282,7 +282,7 @@ function edit.to_coord(editor, loc) -- scans
-- text -- text
for _,s in ipairs(rect.screen_line_rects) do for _,s in ipairs(rect.screen_line_rects) do
for _,c in ipairs(s.char_rects) do for _,c in ipairs(s.char_rects) do
if c.pos == loc.pos and c.show_cursor then if c.pos == loc.pos and c.data then
return editor.left + c.x, y + c.y return editor.left + c.x, y + c.y
end end
end end
@ -557,7 +557,7 @@ function Text.get_rect(editor, loc)
if char:match('%s') then if char:match('%s') then
if Text.line_wrap_at_word_boundary(editor, editor.left + x, line.data, pos) then if Text.line_wrap_at_word_boundary(editor, editor.left + x, line.data, pos) then
table.insert(curr_screen_line, table.insert(curr_screen_line,
{x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char, show_cursor=true}) -- char {x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char}) -- char
table.insert(curr_screen_line, table.insert(curr_screen_line,
{x=x+w, y=y, dx=editor.width-x-w, dy=editor.line_height, pos=pos+1}) -- filler {x=x+w, y=y, dx=editor.width-x-w, dy=editor.line_height, pos=pos+1}) -- filler
table.insert(screen_lines, table.insert(screen_lines,
@ -572,7 +572,7 @@ function Text.get_rect(editor, loc)
end end
else else
table.insert(curr_screen_line, table.insert(curr_screen_line,
{x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char, show_cursor=true}) {x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char})
x = x + w x = x + w
end end
else else
@ -594,12 +594,12 @@ function Text.get_rect(editor, loc)
-- nothing -- nothing
end end
table.insert(curr_screen_line, table.insert(curr_screen_line,
{x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char, show_cursor=true}) {x=x, y=y, dx=w, dy=editor.line_height, pos=pos, data=char})
x = x + w x = x + w
end end
end end
table.insert(curr_screen_line, table.insert(curr_screen_line,
{x=x, y=y, dx=editor.width-x, dy=editor.line_height, pos=utf8.len(line.data)+1, show_cursor=true}) -- filler {x=x, y=y, dx=editor.width-x, dy=editor.line_height, pos=utf8.len(line.data)+1}) -- filler
table.insert(screen_lines, table.insert(screen_lines,
{x=0, y=y, dx=editor.width, dy=editor.line_height, {x=0, y=y, dx=editor.width, dy=editor.line_height,
pos=spos, dpos=utf8.len(line.data)+1-spos+1, char_rects=curr_screen_line}) pos=spos, dpos=utf8.len(line.data)+1-spos+1, char_rects=curr_screen_line})