extract couple of functions
This commit is contained in:
parent
cb943b9aeb
commit
9892bc5d7c
76
text.lua
76
text.lua
|
@ -769,41 +769,9 @@ function Text.keychord_pressed(chord)
|
||||||
Text.insert_at_cursor('\t')
|
Text.insert_at_cursor('\t')
|
||||||
save_to_disk(Lines, Filename)
|
save_to_disk(Lines, Filename)
|
||||||
elseif chord == 'left' then
|
elseif chord == 'left' then
|
||||||
assert(Lines[Cursor1.line].mode == 'text')
|
Text.left()
|
||||||
if Cursor1.pos > 1 then
|
|
||||||
Cursor1.pos = Cursor1.pos-1
|
|
||||||
else
|
|
||||||
local new_cursor_line = Cursor1.line
|
|
||||||
while new_cursor_line > 1 do
|
|
||||||
new_cursor_line = new_cursor_line-1
|
|
||||||
if Lines[new_cursor_line].mode == 'text' then
|
|
||||||
Cursor1.line = new_cursor_line
|
|
||||||
Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Cursor1.line < Screen_top1.line then
|
|
||||||
Screen_top1.line = Cursor1.line
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif chord == 'right' then
|
elseif chord == 'right' then
|
||||||
assert(Lines[Cursor1.line].mode == 'text')
|
Text.right()
|
||||||
if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
|
|
||||||
Cursor1.pos = Cursor1.pos+1
|
|
||||||
else
|
|
||||||
local new_cursor_line = Cursor1.line
|
|
||||||
while new_cursor_line <= #Lines-1 do
|
|
||||||
new_cursor_line = new_cursor_line+1
|
|
||||||
if Lines[new_cursor_line].mode == 'text' then
|
|
||||||
Cursor1.line = new_cursor_line
|
|
||||||
Cursor1.pos = 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Cursor1.line > Screen_bottom1.line then
|
|
||||||
Screen_top1.line = Cursor1.line
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif chord == 'home' then
|
elseif chord == 'home' then
|
||||||
Cursor1.pos = 1
|
Cursor1.pos = 1
|
||||||
elseif chord == 'end' then
|
elseif chord == 'end' then
|
||||||
|
@ -957,6 +925,46 @@ function Text.keychord_pressed(chord)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Text.left()
|
||||||
|
assert(Lines[Cursor1.line].mode == 'text')
|
||||||
|
if Cursor1.pos > 1 then
|
||||||
|
Cursor1.pos = Cursor1.pos-1
|
||||||
|
else
|
||||||
|
local new_cursor_line = Cursor1.line
|
||||||
|
while new_cursor_line > 1 do
|
||||||
|
new_cursor_line = new_cursor_line-1
|
||||||
|
if Lines[new_cursor_line].mode == 'text' then
|
||||||
|
Cursor1.line = new_cursor_line
|
||||||
|
Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Cursor1.line < Screen_top1.line then
|
||||||
|
Screen_top1.line = Cursor1.line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Text.right()
|
||||||
|
assert(Lines[Cursor1.line].mode == 'text')
|
||||||
|
if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
|
||||||
|
Cursor1.pos = Cursor1.pos+1
|
||||||
|
else
|
||||||
|
local new_cursor_line = Cursor1.line
|
||||||
|
while new_cursor_line <= #Lines-1 do
|
||||||
|
new_cursor_line = new_cursor_line+1
|
||||||
|
if Lines[new_cursor_line].mode == 'text' then
|
||||||
|
Cursor1.line = new_cursor_line
|
||||||
|
Cursor1.pos = 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Cursor1.line > Screen_bottom1.line then
|
||||||
|
Screen_top1.line = Cursor1.line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Text.pos_at_start_of_cursor_screen_line()
|
function Text.pos_at_start_of_cursor_screen_line()
|
||||||
if Lines[Cursor1.line].screen_line_starting_pos == nil then
|
if Lines[Cursor1.line].screen_line_starting_pos == nil then
|
||||||
return 1,1
|
return 1,1
|
||||||
|
|
Loading…
Reference in New Issue