extract a couple of functions
This commit is contained in:
parent
12b1d19761
commit
fd7d36fefd
29
commands.lua
29
commands.lua
|
@ -124,9 +124,7 @@ function add_file_to_menu(x,y, s, cursor_highlight)
|
||||||
end
|
end
|
||||||
button(Editor_state, 'menu', {x=x-5, y=y-2, w=width+5*2, h=Editor_state.line_height+2*2, color=colortable(color),
|
button(Editor_state, 'menu', {x=x-5, y=y-2, w=width+5*2, h=Editor_state.line_height+2*2, color=colortable(color),
|
||||||
onpress1 = function()
|
onpress1 = function()
|
||||||
local candidate = guess_source(s..'.lua')
|
navigate_to_file(s)
|
||||||
source.switch_to_file(candidate)
|
|
||||||
Show_file_navigator = false
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
App.color(Menu_command_color)
|
App.color(Menu_command_color)
|
||||||
|
@ -135,21 +133,26 @@ function add_file_to_menu(x,y, s, cursor_highlight)
|
||||||
return x,y
|
return x,y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function navigate_to_file(s)
|
||||||
|
local candidate = guess_source(s..'.lua')
|
||||||
|
source.switch_to_file(candidate)
|
||||||
|
reset_file_navigator()
|
||||||
|
end
|
||||||
|
|
||||||
|
function reset_file_navigator()
|
||||||
|
Show_file_navigator = false
|
||||||
|
File_navigation.index = 1
|
||||||
|
File_navigation.filter = ''
|
||||||
|
File_navigation.candidates = File_navigation.all_candidates
|
||||||
|
end
|
||||||
|
|
||||||
function keychord_pressed_on_file_navigator(chord, key)
|
function keychord_pressed_on_file_navigator(chord, key)
|
||||||
log(2, 'file navigator: '..chord)
|
log(2, 'file navigator: '..chord)
|
||||||
log(2, {name='file_navigator_state', files=File_navigation.candidates, index=File_navigation.index})
|
log(2, {name='file_navigator_state', files=File_navigation.candidates, index=File_navigation.index})
|
||||||
if chord == 'escape' then
|
if chord == 'escape' then
|
||||||
Show_file_navigator = false
|
reset_file_navigator()
|
||||||
File_navigation.index = 1
|
|
||||||
File_navigation.filter = ''
|
|
||||||
File_navigation.candidates = File_navigation.all_candidates
|
|
||||||
elseif chord == 'return' then
|
elseif chord == 'return' then
|
||||||
local candidate = guess_source(File_navigation.candidates[File_navigation.index]..'.lua')
|
navigate_to_file(File_navigation.candidates[File_navigation.index])
|
||||||
source.switch_to_file(candidate)
|
|
||||||
Show_file_navigator = false
|
|
||||||
File_navigation.index = 1
|
|
||||||
File_navigation.filter = ''
|
|
||||||
File_navigation.candidates = File_navigation.all_candidates
|
|
||||||
elseif chord == 'backspace' then
|
elseif chord == 'backspace' then
|
||||||
local len = utf8.len(File_navigation.filter)
|
local len = utf8.len(File_navigation.filter)
|
||||||
local byte_offset = Text.offset(File_navigation.filter, len)
|
local byte_offset = Text.offset(File_navigation.filter, len)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user