parent
40ebc71d58
commit
ed08869d25
2
0019-B
2
0019-B
|
@ -1,4 +1,5 @@
|
|||
B = function(skip_updating_screen_top_for)
|
||||
print('B', skip_updating_screen_top_for)
|
||||
-- recompute various aspects based on the current viewport settings
|
||||
for _,obj in ipairs(Surface) do
|
||||
if obj.type == 'line' then
|
||||
|
@ -22,4 +23,5 @@ B = function(skip_updating_screen_top_for)
|
|||
end
|
||||
end
|
||||
end
|
||||
print('end B', skip_updating_screen_top_for)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
compute_layout = function(node, x,y, nodes_to_render, skip_updating_screen_top_for)
|
||||
if node.editor then
|
||||
print('compute_layout', node, node.type, node.editor.screen_top1.line, skip_updating_screen_top_for)
|
||||
end
|
||||
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
|
||||
-- return x,y rendered until (surface coordinates)
|
||||
if node.type == 'text' then
|
||||
|
@ -59,7 +62,7 @@ compute_layout = function(node, x,y, nodes_to_render, skip_updating_screen_top_f
|
|||
if not child.width then
|
||||
child.width = node.width -- HACK: should we set child.w or child.width? Neither is quite satisfactory.
|
||||
end
|
||||
subx,suby = compute_layout(child, x,suby, nodes_to_render)
|
||||
subx,suby = compute_layout(child, x,suby, nodes_to_render, skip_updating_screen_top_for)
|
||||
if w < child.w then
|
||||
w = child.w
|
||||
end
|
||||
|
@ -87,7 +90,7 @@ compute_layout = function(node, x,y, nodes_to_render, skip_updating_screen_top_f
|
|||
subx = subx+child.margin
|
||||
w = w+child.margin
|
||||
end
|
||||
subx,suby = compute_layout(child, subx,y, nodes_to_render)
|
||||
subx,suby = compute_layout(child, subx,y, nodes_to_render, skip_updating_screen_top_for)
|
||||
w = w + child.w
|
||||
if h < child.h then
|
||||
h = child.h
|
||||
|
@ -100,5 +103,6 @@ compute_layout = function(node, x,y, nodes_to_render, skip_updating_screen_top_f
|
|||
node_to_render.h = h
|
||||
end
|
||||
end
|
||||
print('end compute_layout', skip_updating_screen_top_for, node)
|
||||
return x+node.w,y+node.h
|
||||
end
|
||||
|
|
|
@ -22,8 +22,9 @@ on.keychord_press = function(chord, key)
|
|||
if not eq(Cursor_node.editor.screen_top1, old_top) then
|
||||
print('==', old_top.line, old_top.pos, '=>', Cursor_node.editor.screen_top1.line, Cursor_node.editor.screen_top1.pos)
|
||||
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
|
||||
print('=>', Viewport.y)
|
||||
print('->', Viewport.y, Cursor_node.editor.top, Cursor_node.editor.screen_top1.line)
|
||||
A(--[[skip updating screen_top for]] Cursor_node)
|
||||
print('=>', Viewport.y, Cursor_node.editor.top, Cursor_node.editor.screen_top1.line)
|
||||
return
|
||||
end
|
||||
A()
|
||||
|
|
|
@ -32,8 +32,9 @@ on.draw = function()
|
|||
if obj.w == nil then
|
||||
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
|
||||
else
|
||||
--? print('edit.draw', obj.y, obj.editor.top, obj.editor.screen_top1.line)
|
||||
edit.draw(obj.editor, obj.fg or {r=0,g=0,b=0}, not obj.show_cursor)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
3
0028-A
3
0028-A
|
@ -1,8 +1,11 @@
|
|||
A = function(skip_updating_screen_top_for)
|
||||
print('A', skip_updating_screen_top_for)
|
||||
love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font
|
||||
Surface = {}
|
||||
print('calling compute_layout', Page, Page.x,Page.y, Surface, skip_updating_screen_top_for)
|
||||
compute_layout(Page, Page.x,Page.y, Surface, skip_updating_screen_top_for)
|
||||
-- continue the pipeline
|
||||
B(skip_updating_screen_top_for)
|
||||
-- TODO: ugly that we're manipulating editor objects twice
|
||||
print('end A', skip_updating_screen_top_for)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
update_editor_box = function(node, skip_updating_screen_top_for)
|
||||
if node.editor == nil then return end
|
||||
print('update box', node, node.editor.screen_top1.line, skip_updating_screen_top_for)
|
||||
edit.update_font_settings(node.editor, scale(20))
|
||||
if node ~= skip_updating_screen_top_for then
|
||||
print('update box: refreshing screen top', node.editor.screen_top1.line)
|
||||
if node.y > Viewport.y then
|
||||
node.editor.screen_top1.line = 1
|
||||
node.editor.screen_top1.pos = 1
|
||||
|
@ -9,9 +11,12 @@ update_editor_box = function(node, skip_updating_screen_top_for)
|
|||
else
|
||||
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, scale(Viewport.y-node.y))
|
||||
end
|
||||
else
|
||||
print('update box: NOT refreshing screen top', node.editor.screen_top1.line)
|
||||
end
|
||||
node.editor.left = math.floor(vx(node.x))
|
||||
node.editor.right = math.ceil(vx(node.x+node.w))
|
||||
node.editor.width = node.editor.right - node.editor.left
|
||||
Text.redraw_all(node.editor)
|
||||
print('end update box', node, skip_updating_screen_top_for)
|
||||
end
|
||||
|
|
51
text.lua
51
text.lua
|
@ -204,11 +204,11 @@ function Text.keychord_press(State, chord, readonly)
|
|||
end
|
||||
elseif State.cursor1.line > 1 then
|
||||
before = snapshot(State, State.cursor1.line-1, State.cursor1.line)
|
||||
-- join lines
|
||||
State.cursor1.pos = utf8.len(State.lines[State.cursor1.line-1].data)+1
|
||||
State.lines[State.cursor1.line-1].data = State.lines[State.cursor1.line-1].data..State.lines[State.cursor1.line].data
|
||||
table.remove(State.lines, State.cursor1.line)
|
||||
table.remove(State.line_cache, State.cursor1.line)
|
||||
-- join lines
|
||||
State.cursor1.pos = utf8.len(State.lines[State.cursor1.line-1].data)+1
|
||||
State.lines[State.cursor1.line-1].data = State.lines[State.cursor1.line-1].data..State.lines[State.cursor1.line].data
|
||||
table.remove(State.lines, State.cursor1.line)
|
||||
table.remove(State.line_cache, State.cursor1.line)
|
||||
State.cursor1.line = State.cursor1.line-1
|
||||
end
|
||||
if State.screen_top1.line > #State.lines then
|
||||
|
@ -250,8 +250,8 @@ function Text.keychord_press(State, chord, readonly)
|
|||
-- no change to State.cursor1.pos
|
||||
end
|
||||
elseif State.cursor1.line < #State.lines then
|
||||
-- join lines
|
||||
State.lines[State.cursor1.line].data = State.lines[State.cursor1.line].data..State.lines[State.cursor1.line+1].data
|
||||
-- join lines
|
||||
State.lines[State.cursor1.line].data = State.lines[State.cursor1.line].data..State.lines[State.cursor1.line+1].data
|
||||
table.remove(State.lines, State.cursor1.line+1)
|
||||
table.remove(State.line_cache, State.cursor1.line+1)
|
||||
end
|
||||
|
@ -363,7 +363,7 @@ function Text.pageup(State)
|
|||
while y >= State.top do
|
||||
--? print(y, top2.line, top2.screen_line, top2.screen_pos)
|
||||
if State.screen_top1.line == 1 and State.screen_top1.pos == 1 then break end
|
||||
y = y - State.line_height
|
||||
y = y - State.line_height
|
||||
top2 = Text.previous_screen_line(State, top2)
|
||||
end
|
||||
State.screen_top1 = Text.to1(State, top2)
|
||||
|
@ -435,42 +435,42 @@ function Text.up(State)
|
|||
end
|
||||
|
||||
function Text.down(State)
|
||||
--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
|
||||
print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
|
||||
assert(State.cursor1.pos)
|
||||
if Text.cursor_at_final_screen_line(State) then
|
||||
-- line is done, skip to next text line
|
||||
--? print('cursor at final screen line of its line')
|
||||
print('cursor at final screen line of its line')
|
||||
if State.cursor1.line < #State.lines then
|
||||
local new_cursor_line = State.cursor1.line+1
|
||||
State.cursor1.line = new_cursor_line
|
||||
State.cursor1.pos = Text.nearest_cursor_pos(State.lines[State.cursor1.line].data, State.cursor_x, State.left)
|
||||
--? print(State.cursor1.pos)
|
||||
print(State.cursor1.pos)
|
||||
end
|
||||
if State.cursor1.line > State.screen_bottom1.line then
|
||||
--? print('screen top before:', State.screen_top1.line, State.screen_top1.pos)
|
||||
--? print('scroll up preserving cursor')
|
||||
print('screen top before:', State.screen_top1.line, State.screen_top1.pos)
|
||||
print('scroll up preserving cursor')
|
||||
Text.snap_cursor_to_bottom_of_screen(State)
|
||||
--? print('screen top after:', State.screen_top1.line, State.screen_top1.pos)
|
||||
print('screen top after:', State.screen_top1.line, State.screen_top1.pos)
|
||||
end
|
||||
else
|
||||
-- move down one screen line in current line
|
||||
local scroll_down = Text.le1(State.screen_bottom1, State.cursor1)
|
||||
--? print('cursor is NOT at final screen line of its line')
|
||||
print('cursor is NOT at final screen line of its line')
|
||||
local screen_line_starting_pos, screen_line_index = Text.pos_at_start_of_screen_line(State, State.cursor1)
|
||||
Text.populate_screen_line_starting_pos(State, State.cursor1.line)
|
||||
local new_screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos[screen_line_index+1]
|
||||
--? print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
|
||||
print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
|
||||
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)
|
||||
local s = string.sub(State.lines[State.cursor1.line].data, new_screen_line_starting_byte_offset)
|
||||
State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
|
||||
--? print('cursor pos is now', State.cursor1.line, State.cursor1.pos)
|
||||
print('cursor pos is now', State.cursor1.line, State.cursor1.pos)
|
||||
if scroll_down then
|
||||
--? print('scroll up preserving cursor')
|
||||
print('scroll up preserving cursor')
|
||||
Text.snap_cursor_to_bottom_of_screen(State)
|
||||
--? print('screen top after:', State.screen_top1.line, State.screen_top1.pos)
|
||||
print('screen top after:', State.screen_top1.line, State.screen_top1.pos)
|
||||
end
|
||||
end
|
||||
--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
|
||||
print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
|
||||
end
|
||||
|
||||
function Text.start_of_line(State)
|
||||
|
@ -632,11 +632,11 @@ function Text.snap_cursor_to_bottom_of_screen(State)
|
|||
while true do
|
||||
--? print(y, 'top2:', top2.line, top2.screen_line, top2.screen_pos)
|
||||
if top2.line == 1 and top2.screen_line == 1 then break end
|
||||
local h = State.line_height
|
||||
if y - h < State.top then
|
||||
break
|
||||
end
|
||||
y = y - h
|
||||
local h = State.line_height
|
||||
if y - h < State.top then
|
||||
break
|
||||
end
|
||||
y = y - h
|
||||
top2 = Text.previous_screen_line(State, top2)
|
||||
end
|
||||
--? print('top2 finally:', top2.line, top2.screen_line, top2.screen_pos)
|
||||
|
@ -906,6 +906,7 @@ end
|
|||
-- slightly expensive since it redraws the screen
|
||||
function Text.cursor_out_of_screen(State)
|
||||
edit.draw(State, --[[should be drawn over]] Cursor_color)
|
||||
print('cursor out of screen?', State.cursor_y == nil)
|
||||
return State.cursor_y == nil
|
||||
-- this approach is cheaper and almost works, except on the final screen
|
||||
-- where file ends above bottom of screen
|
||||
|
|
Loading…
Reference in New Issue