first stab at supporting wrapping in cursor up
Looks pretty clean.
This commit is contained in:
parent
1c20d514f2
commit
7e6705a113
11
manual_tests
11
manual_tests
|
@ -14,3 +14,14 @@ backspace
|
||||||
|
|
||||||
enter
|
enter
|
||||||
cursor_pos == 0 -> insert empty line above current line
|
cursor_pos == 0 -> insert empty line above current line
|
||||||
|
|
||||||
|
scrolling:
|
||||||
|
given moby dick, a file containing all text:
|
||||||
|
page up moves top line on screen to bottom
|
||||||
|
page down moves bottom line on screen to top
|
||||||
|
cursor remains on screen
|
||||||
|
cursor remains on text line
|
||||||
|
'up' arrow with cursor at top of screen scrolls up one line (drawings still fully in or out)
|
||||||
|
if top line wrapped before, it scrolls up by only one screen line
|
||||||
|
'down' arrow with cursor at bottom of screen scrolls down one line (drawings still fully in or out)
|
||||||
|
if top line wrapped before, it scrolls down by only one screen line
|
||||||
|
|
35
text.lua
35
text.lua
|
@ -19,7 +19,7 @@ function Text.draw(line, line_width, line_index)
|
||||||
local frag_width = math.floor(frag_text:getWidth()*Zoom)
|
local frag_width = math.floor(frag_text:getWidth()*Zoom)
|
||||||
if x + frag_width > line_width then
|
if x + frag_width > line_width then
|
||||||
assert(x > 25) -- no overfull lines
|
assert(x > 25) -- no overfull lines
|
||||||
if line_index > Screen_top_line or pos >= Top_screen_line_starting_pos then
|
if line_index > Screen_top_line or pos > Top_screen_line_starting_pos then
|
||||||
y = y + math.floor(15*Zoom)
|
y = y + math.floor(15*Zoom)
|
||||||
end
|
end
|
||||||
x = 25
|
x = 25
|
||||||
|
@ -219,19 +219,28 @@ function Text.keychord_pressed(chord)
|
||||||
save_to_disk(Lines, Filename)
|
save_to_disk(Lines, Filename)
|
||||||
elseif chord == 'up' then
|
elseif chord == 'up' then
|
||||||
assert(Lines[Cursor_line].mode == 'text')
|
assert(Lines[Cursor_line].mode == 'text')
|
||||||
-- previous text line
|
if Top_screen_line_starting_pos == 1 then
|
||||||
local new_cursor_line = Cursor_line
|
-- top line is done; skip to previous text line
|
||||||
while new_cursor_line > 1 do
|
local new_cursor_line = Cursor_line
|
||||||
new_cursor_line = new_cursor_line-1
|
while new_cursor_line > 1 do
|
||||||
if Lines[new_cursor_line].mode == 'text' then
|
new_cursor_line = new_cursor_line-1
|
||||||
local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
|
if Lines[new_cursor_line].mode == 'text' then
|
||||||
Cursor_line = new_cursor_line
|
local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
|
||||||
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
|
Cursor_line = new_cursor_line
|
||||||
break
|
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
if Cursor_line < Screen_top_line then
|
||||||
if Cursor_line < Screen_top_line then
|
Screen_top_line = Cursor_line
|
||||||
Screen_top_line = Cursor_line
|
end
|
||||||
|
else
|
||||||
|
-- scroll up just one screen line in current line
|
||||||
|
local screen_line_index = table.find(Lines[Cursor_line].screen_line_starting_pos, Top_screen_line_starting_pos)
|
||||||
|
assert(screen_line_index > 1)
|
||||||
|
Top_screen_line_starting_pos = Lines[Cursor_line].screen_line_starting_pos[screen_line_index-1]
|
||||||
|
local s = string.sub(Lines[Cursor_line].data, Top_screen_line_starting_pos)
|
||||||
|
Cursor_pos = Text.nearest_cursor_pos(s, Cursor_x)
|
||||||
end
|
end
|
||||||
elseif chord == 'down' then
|
elseif chord == 'down' then
|
||||||
assert(Lines[Cursor_line].mode == 'text')
|
assert(Lines[Cursor_line].mode == 'text')
|
||||||
|
|
Loading…
Reference in New Issue