beginnings of a module for the text editor
[?]
May 18, 2022, 3:29 AM
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQCDependencies
- [2]
TRK4TSN7more precise cursor positioning - [3]
BLWAYPKVextract a module - [4]
7IKRRESBlonger names for indices in long loops - [5]
H7OEU6WPexperimental approach to combining keyboard and mouse while drawing - [6]
2INHXC3Kposition cursor by clicking on text - [7]
PRPPZGDYspeed up some obvious common cases - [8]
ZD63LJ2Tbugfix: keep the click to create a new drawing from creating a new shape in the drawing - [9]
JS6JSYOTonline contextual help - [10]
TNTYISW6rename - [11]
JVRL5TWLstore device-independent coordinates inside drawings - [12]
7RN3AETYbugfix: text sometimes getting colored like drawing borders - [13]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [14]
VVXVV2D2change data model; text can now have metadata - [15]
V5TP27FPctrl-+ and ctrl-- to adjust font size - [16]
XX7G2FFJintermingle freehand line drawings with text - [17]
WDWXNW7Vslightly strange way to move points - [18]
HJ3PM2VT. - [19]
AVQ5MC5Dfinish uppercasing all globals - [20]
IHG5RXP5allow text to be typed while mouse hovers over drawing - [21]
3SYFA5JQshow cursor even on empty lines - [22]
RJGZD4INbinary search to most natural up/down with proportional fonts - [23]
IFGAJAF7add a level of indirection to vertices of shapes - [24]
FBDRL6LHdelete points or shapes - [25]
KHFU5NFDbugfix: up/down across drawings - [26]
JCSLDGAHbeginnings of support for multiple shapes - [27]
M36DBSDEbit more polish to help screen - [28]
HRWN5V6JDevine's suggestion to try to live with just freehand - [29]
3CS5KKCIup/down cursor movement - [30]
3D5RFWHVstop handling drawings in cursor_pos computations - [31]
MGOQ5XAVstart uppercasing globals - [*]
R5QXEHUIsomebody stop me - [*]
OTIBCAUJlove2d scaffold
Change contents
- file addition: text.lua[33.2]
-- primitives for editing textText = {}function Text.draw(line, line_index, cursor_line, y, cursor_pos)love.graphics.setColor(0,0,0)local love_text = love.graphics.newText(love.graphics.getFont(), line.data)love.graphics.draw(love_text, 25,y, 0, Zoom)if line_index == cursor_line then-- cursorlove.graphics.print('_', Text.cursor_x(line.data, cursor_pos), y+6) -- drop the cursor down a bit to account for the increased font sizeendendfunction Text.nearest_cursor_pos(line, x, hint)if x == 0 thenreturn 1endlocal max_x = Text.cursor_x(line, #line+1)if x > max_x thenreturn #line+1endlocal currx = Text.cursor_x(line, hint)if currx > x-2 and currx < x+2 thenreturn hintendlocal left, right = 1, #line+1if currx > x thenright = hintelseleft = hintendwhile left < right-1 dolocal curr = math.floor((left+right)/2)local currxmin = Text.cursor_x(line, curr)local currxmax = Text.cursor_x(line, curr+1)if currxmin <= x and x < currxmax thenreturn currendif currxmin > x thenright = currelseleft = currendendreturn rightendfunction Text.cursor_x(line_data, cursor_pos)local line_before_cursor = line_data:sub(1, cursor_pos-1)local text_before_cursor = love.graphics.newText(love.graphics.getFont(), line_before_cursor)return 25+text_before_cursor:getWidth()*Zoomendreturn Text - edit in main.lua at line 4
local Text = require 'text' - replacement in main.lua at line 124[5.1249]→[5.2:38](∅→∅),[5.38]→[5.469:546](∅→∅),[5.546]→[5.1410:1456](∅→∅),[5.1456]→[4.263:303](∅→∅),[4.303]→[5.32:50](∅→∅),[5.1487]→[5.32:50](∅→∅),[5.32]→[5.32:50](∅→∅),[5.50]→[5.1488:1629](∅→∅),[5.142]→[5.411:421](∅→∅),[5.158]→[5.411:421](∅→∅),[5.695]→[5.411:421](∅→∅),[5.1629]→[5.411:421](∅→∅),[5.411]→[5.411:421](∅→∅)
love.graphics.setColor(0,0,0)local text = love.graphics.newText(love.graphics.getFont(), line.data)love.graphics.draw(text, 25,y, 0, Zoom)if line_index == Cursor_line then-- cursorlove.graphics.print('_', cursor_x(line.data, Cursor_pos), y+6) -- drop the cursor down a bit to account for the increased font sizeendText.draw(line, line_index, Cursor_line, y, Cursor_pos) - replacement in main.lua at line 165
Cursor_pos = nearest_cursor_pos(line.data, x, 1)Cursor_pos = Text.nearest_cursor_pos(line.data, x, 1) - replacement in main.lua at line 536
local old_x = cursor_x(Lines[new_cursor_line].data, Cursor_pos)local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos) - replacement in main.lua at line 538
Cursor_pos = nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos)Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos) - replacement in main.lua at line 548
local old_x = cursor_x(Lines[new_cursor_line].data, Cursor_pos)local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos) - replacement in main.lua at line 550
Cursor_pos = nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos)Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos) - edit in main.lua at line 707[5.552]→[5.552:588](∅→∅),[5.46]→[5.588:739](∅→∅),[5.2966]→[5.588:739](∅→∅),[5.588]→[5.588:739](∅→∅),[5.739]→[5.6231:6278](∅→∅),[5.283]→[5.778:783](∅→∅),[5.662]→[5.778:783](∅→∅),[5.6278]→[5.778:783](∅→∅),[5.778]→[5.778:783](∅→∅),[5.783]→[5.157:200](∅→∅),[5.95]→[5.820:856](∅→∅),[5.200]→[5.820:856](∅→∅),[5.3016]→[5.820:856](∅→∅),[5.820]→[5.820:856](∅→∅),[5.856]→[5.201:383](∅→∅),[5.383]→[5.856:889](∅→∅),[5.856]→[5.856:889](∅→∅),[5.889]→[5.384:450](∅→∅),[5.450]→[5.889:959](∅→∅),[5.889]→[5.889:959](∅→∅),[5.959]→[2.1:130](∅→∅),[2.130]→[5.1038:1056](∅→∅),[5.1038]→[5.1038:1056](∅→∅),[5.1056]→[5.576:584](∅→∅),[5.576]→[5.576:584](∅→∅),[5.584]→[2.131:156](∅→∅),[2.156]→[5.1079:1133](∅→∅),[5.1079]→[5.1079:1133](∅→∅),[5.584]→[5.482:488](∅→∅),[5.1072]→[5.482:488](∅→∅),[5.1133]→[5.482:488](∅→∅),[5.482]→[5.482:488](∅→∅),[5.488]→[5.1134:1149](∅→∅),[5.1149]→[5.488:493](∅→∅),[5.488]→[5.488:493](∅→∅)
function cursor_x(line, cursor_pos)local line_before_cursor = line:sub(1, cursor_pos-1)local text_before_cursor = love.graphics.newText(love.graphics.getFont(), line_before_cursor)return 25+text_before_cursor:getWidth()*Zoomendfunction nearest_cursor_pos(line, x, hint)if x == 0 thenreturn 1endlocal max_x = cursor_x(line, #line+1)if x > max_x thenreturn #line+1endlocal currx = cursor_x(line, hint)if currx > x-2 and currx < x+2 thenreturn hintendlocal left, right = 1, #line+1if currx > x thenright = hintelseleft = hintendwhile left < right-1 dolocal curr = math.floor((left+right)/2)local currxmin = cursor_x(line, curr)local currxmax = cursor_x(line, curr+1)if currxmin <= x and x < currxmax thenreturn currendif currxmin > x thenright = currelseleft = currendendreturn rightend