keep cursor on screen when pressing 'down'
This commit is contained in:
parent
e3dc4c330b
commit
e420245ee3
2
main.lua
2
main.lua
|
@ -111,7 +111,7 @@ function love.draw()
|
||||||
end
|
end
|
||||||
local y = 15
|
local y = 15
|
||||||
for line_index,line in ipairs(Lines) do
|
for line_index,line in ipairs(Lines) do
|
||||||
if y > Screen_height then break end
|
if y + math.floor(15*Zoom) > Screen_height then break end
|
||||||
if line_index >= Screen_top_line then
|
if line_index >= Screen_top_line then
|
||||||
Screen_bottom_line = line_index
|
Screen_bottom_line = line_index
|
||||||
if line.mode == 'text' and line.data == '' then
|
if line.mode == 'text' and line.data == '' then
|
||||||
|
|
6
text.lua
6
text.lua
|
@ -3,7 +3,7 @@ Text = {}
|
||||||
|
|
||||||
local utf8 = require 'utf8'
|
local utf8 = require 'utf8'
|
||||||
|
|
||||||
local Debug_new_render = true
|
local Debug_new_render = false
|
||||||
|
|
||||||
function Text.draw(line, line_width, line_index)
|
function Text.draw(line, line_width, line_index)
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
|
@ -123,7 +123,7 @@ end
|
||||||
|
|
||||||
-- Don't handle any keys here that would trigger love.textinput above.
|
-- Don't handle any keys here that would trigger love.textinput above.
|
||||||
function Text.keychord_pressed(chord)
|
function Text.keychord_pressed(chord)
|
||||||
Debug_new_render = true
|
--? Debug_new_render = true
|
||||||
if chord == 'return' then
|
if chord == 'return' then
|
||||||
local byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
|
local byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
|
||||||
table.insert(Lines, Cursor_line+1, {mode='text', data=string.sub(Lines[Cursor_line].data, byte_offset)})
|
table.insert(Lines, Cursor_line+1, {mode='text', data=string.sub(Lines[Cursor_line].data, byte_offset)})
|
||||||
|
@ -286,6 +286,7 @@ function Text.keychord_pressed(chord)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
print(Cursor_line, Cursor_pos, Screen_bottom_line)
|
||||||
if Cursor_line > Screen_bottom_line then
|
if Cursor_line > Screen_bottom_line then
|
||||||
print('screen top before:', Screen_top_line, Top_screen_line_starting_pos)
|
print('screen top before:', Screen_top_line, Top_screen_line_starting_pos)
|
||||||
Screen_top_line = Cursor_line
|
Screen_top_line = Cursor_line
|
||||||
|
@ -302,6 +303,7 @@ function Text.keychord_pressed(chord)
|
||||||
local s = string.sub(Lines[Cursor_line].data, new_screen_line_starting_pos)
|
local s = string.sub(Lines[Cursor_line].data, new_screen_line_starting_pos)
|
||||||
Cursor_pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1
|
Cursor_pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1
|
||||||
print('cursor pos is now '..tostring(Cursor_pos))
|
print('cursor pos is now '..tostring(Cursor_pos))
|
||||||
|
Screen_top_line = Cursor_line
|
||||||
Text.scroll_up_while_cursor_on_screen()
|
Text.scroll_up_while_cursor_on_screen()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user