clicking now moves the cursor even on long, wrapped lines
[?]
May 20, 2022, 5:07 AM
BOFNXP5GZDCUMQG3LQVTSSFEQP7REQ4RIRJLDLETFSAGFTVDVEKACDependencies
- [2]
DXT4QTAHa few more integer coordinates - [3]
DAENUOGVeliminate assumptions that line length == size in bytes - [4]
PHQPLJUQrename - [5]
DLQMM265scroll past first page - [6]
LUNH47XXmake text and drawings the same width - [7]
4C375P53this is a bit clearer - [8]
BULPIBEGbeginnings of a module for the text editor - [9]
B3IWYWSRdelete another arg that can be deduced - [10]
UWNHC4AAredo y computations - [11]
HYEAFRZ2split mouse_pressed events between Text and Drawing - [12]
H2DPLWMVsnapshot: wrapping long lines at word boundaries - [13]
2INHXC3Kposition cursor by clicking on text - [14]
HIH47LNBdrop unused arg - [*]
OTIBCAUJlove2d scaffold - [*]
VVXVV2D2change data model; text can now have metadata - [*]
JCSLDGAHbeginnings of support for multiple shapes
Change contents
- edit in text.lua at line 42
--? love.graphics.setColor(0.75,0.75,0.75)--? love.graphics.line(line_width, 0, line_width, Screen_height) - edit in text.lua at line 58
if line.screen_line_starting_pos == nil thenline.screen_line_starting_pos = {1, pos}elsetable.insert(line.screen_line_starting_pos, pos)end - replacement in text.lua at line 273
return x >= 16 and y >= line.y and y < line.y + math.floor(15*Zoom)if x < 16 then return false endif y < line.y then return false endif line.screen_line_starting_pos == nil then return y < line.y + math.floor(15*Zoom) endreturn y < line.y + #line.screen_line_starting_pos * math.floor(15*Zoom) - replacement in text.lua at line 279
function Text.move_cursor(line_index, line, mx)function Text.move_cursor(line_index, line, mx, my) - replacement in text.lua at line 281
Cursor_pos = Text.nearest_cursor_pos(line.data, mx)if line.screen_line_starting_pos == nil then--? print('single screen line')Cursor_pos = Text.nearest_cursor_pos(line.data, mx)returnendassert(line.fragments)assert(my >= line.y)--? print('move_cursor', mx, my)if my < line.y + math.floor(15*Zoom) then--? print('first screen line')Cursor_pos = Text.nearest_cursor_pos(line.data, mx)returnend-- duplicate some logic from Text.drawlocal y = line.yfor _,screen_line_starting_pos in ipairs(line.screen_line_starting_pos) do--? print('screen line:', screen_line_starting_pos)local nexty = y + math.floor(15*Zoom)if my < nexty thenlocal s = string.sub(line.data, screen_line_starting_pos)Cursor_pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, mx) - 1returnendy = nextyendassert(false) - edit in text.lua at line 308
-- manual test:-- line: abc-- def-- gh-- fragments: abc, def, gh-- click inside e-- line_starting_pos = 1 + 3 = 4-- nearest_cursor_pos('defgh', mx) = 2-- Cursor_pos = 4 + 2 - 1 = 5-- manual test:-- click inside h-- line_starting_pos = 1 + 3 + 3 = 7-- nearest_cursor_pos('gh', mx) = 2-- Cursor_pos = 7 + 2 - 1 = 8 - edit in main.lua at line 15[17.104][18.104]
-- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line - edit in main.lua at line 130
--? y = Text.draw(line, 100, line_index, Cursor_line, Cursor_pos) - replacement in main.lua at line 148
Text.move_cursor(line_index, line, x)Text.move_cursor(line_index, line, x, y)