clean up all the mess since commit fe4e1395d0
In the process we find a new bug. Scrolling with keyboard is overly eager to clamp screen_top to bottom of screen when the top used to be within the viewport. Until recently, scrolling past the bottom when the margin was visible would move the cursor correctly but pan the surface to the top of the viewport. Slightly jarring, but good enough.
This commit is contained in:
parent
ed08869d25
commit
8d9af77ab1
2
0019-B
2
0019-B
|
@ -1,5 +1,4 @@
|
|||
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
|
||||
|
@ -23,5 +22,4 @@ print('B', skip_updating_screen_top_for)
|
|||
end
|
||||
end
|
||||
end
|
||||
print('end B', skip_updating_screen_top_for)
|
||||
end
|
||||
|
|
91
0020-Page
91
0020-Page
|
@ -9,68 +9,37 @@ Page = {
|
|||
doc='prose goes here, on the left half of the window',
|
||||
margin=Margin_left,
|
||||
data={
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'10',
|
||||
'11',
|
||||
'12',
|
||||
'13',
|
||||
'14',
|
||||
'15',
|
||||
'16',
|
||||
'17',
|
||||
'18',
|
||||
'19',
|
||||
'20',
|
||||
'21',
|
||||
'22',
|
||||
'23',
|
||||
'24',
|
||||
'25',
|
||||
'26',
|
||||
'27',
|
||||
'28',
|
||||
'29',
|
||||
'30',
|
||||
'31',
|
||||
'32',
|
||||
'33',
|
||||
'34',
|
||||
'35',
|
||||
'36',
|
||||
'37',
|
||||
'38',
|
||||
'39',
|
||||
'40',
|
||||
'41',
|
||||
'42',
|
||||
'43',
|
||||
'44',
|
||||
'45',
|
||||
'46',
|
||||
'47',
|
||||
'48',
|
||||
'49',
|
||||
'50',
|
||||
'51',
|
||||
'52',
|
||||
'53',
|
||||
'54',
|
||||
'55',
|
||||
'56',
|
||||
'57',
|
||||
'58',
|
||||
'59',
|
||||
'60',
|
||||
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'mno',
|
||||
'Acb',
|
||||
'g',
|
||||
'hij',
|
||||
'klm',
|
||||
'nop',
|
||||
},
|
||||
width=400, bg={r=0,g=0.8,b=0}
|
||||
width=400, bg={r=1,g=1,b=0}
|
||||
},
|
||||
-- a table on the right
|
||||
{ type='rows', name='searches', margin=50, data={
|
||||
{ type='text', data={''},},
|
||||
{ type='cols', data={
|
||||
{ type='text', data={'search:'},},
|
||||
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
|
||||
}},
|
||||
{ type='text', data={'table:'},},
|
||||
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
|
||||
{ type='rows', width=90, data={
|
||||
{type='text', data={'abc'},},
|
||||
{type='text', data={'abc'},},
|
||||
}},
|
||||
{ type='rows', width=90, data={
|
||||
{type='text', data={'def'},},
|
||||
{type='text', data={'def'},},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
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
|
||||
|
@ -103,6 +100,5 @@ end
|
|||
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
|
||||
|
|
|
@ -20,11 +20,8 @@ on.keychord_press = function(chord, key)
|
|||
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
|
||||
edit.keychord_press(Cursor_node.editor, 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, 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,7 +32,6 @@ 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
|
||||
|
|
12
0028-A
12
0028-A
|
@ -1,11 +1,17 @@
|
|||
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
|
||||
-- translate Page and Page2 to Surface
|
||||
Surface = {}
|
||||
print('calling compute_layout', Page, Page.x,Page.y, Surface, skip_updating_screen_top_for)
|
||||
local red = false
|
||||
for x=-1000,2000,300 do
|
||||
for y=-10000,10000,200 do
|
||||
add_thick_line({type='line', data={x,y, x+200,y+200, x,y+400}, r=red and 1 or 0,g=red and 0 or 0.5,b=0}, 10)
|
||||
red = not red
|
||||
end
|
||||
end
|
||||
compute_layout(Page, Page.x,Page.y, Surface, skip_updating_screen_top_for)
|
||||
compute_layout(Page2, Page2.x,Page2.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
|
||||
|
|
|
@ -3,6 +3,7 @@ Page2 = {
|
|||
-- page
|
||||
type='text',
|
||||
data={
|
||||
"Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off--then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.",
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
|
@ -63,7 +64,6 @@ Page2 = {
|
|||
'58',
|
||||
'59',
|
||||
'60',
|
||||
|
||||
},
|
||||
width=400, bg={r=0,g=0.8,b=0}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
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
|
||||
|
@ -11,12 +9,9 @@ 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,7 +906,6 @@ 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