simplify the palette state machine
This commit is contained in:
parent
837e3bef1b
commit
90e195dd64
76
commands.lua
76
commands.lua
|
@ -129,7 +129,7 @@ function draw_menu_bar()
|
||||||
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
|
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
|
||||||
App.color(Menu_border_color)
|
App.color(Menu_border_color)
|
||||||
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
|
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
|
||||||
if Display_settings.show_palette then
|
if Display_settings.palette then
|
||||||
-- TODO: continue to put shortcuts on the menu bar, enter commands/search strings one row down
|
-- TODO: continue to put shortcuts on the menu bar, enter commands/search strings one row down
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -195,41 +195,37 @@ end
|
||||||
function keychord_press_on_command_palette(chord, key)
|
function keychord_press_on_command_palette(chord, key)
|
||||||
if chord == 'escape' then
|
if chord == 'escape' then
|
||||||
-- forget text for next command
|
-- forget text for next command
|
||||||
Display_settings.palette_command = ''
|
Display_settings.palette = nil
|
||||||
Display_settings.show_palette = false
|
|
||||||
Display_settings.palette_alternative_index = 1
|
|
||||||
Display_settings.palette_candidates = nil
|
|
||||||
elseif chord == 'backspace' then
|
elseif chord == 'backspace' then
|
||||||
local len = utf8.len(Display_settings.palette_command)
|
local len = utf8.len(Display_settings.palette.command)
|
||||||
local byte_offset = Text.offset(Display_settings.palette_command, len)
|
local byte_offset = Text.offset(Display_settings.palette.command, len)
|
||||||
Display_settings.palette_command = string.sub(Display_settings.palette_command, 1, byte_offset-1)
|
Display_settings.palette.command = string.sub(Display_settings.palette.command, 1, byte_offset-1)
|
||||||
Display_settings.palette_alternative_index = 1
|
Display_settings.palette.alternative_index = 1
|
||||||
Display_settings.palette_candidates = candidates()
|
Display_settings.palette.candidates = candidates()
|
||||||
elseif chord == 'tab' then
|
elseif chord == 'tab' then
|
||||||
-- select top candidate, but don't submit
|
-- select top candidate, but don't submit
|
||||||
local candidates = Display_settings.palette_candidates
|
local p = Display_settings.palette
|
||||||
Display_settings.palette_command = command_string(candidates[Display_settings.palette_alternative_index])
|
p.command = command_string(p.candidates[p.alternative_index])
|
||||||
elseif chord == 'C-v' then
|
elseif chord == 'C-v' then
|
||||||
Display_settings.palette_command = Display_settings.palette_command..App.get_clipboard()
|
local p = Display_settings.palette
|
||||||
Display_settings.palette_candidates = candidates()
|
p.command = p.command..App.get_clipboard()
|
||||||
|
p.candidates = candidates()
|
||||||
elseif chord == 'return' then
|
elseif chord == 'return' then
|
||||||
-- submit selected candidate
|
-- submit selected candidate
|
||||||
local candidates = Display_settings.palette_candidates
|
local p = Display_settings.palette
|
||||||
if #candidates > 0 then
|
local candidates = Display_settings.palette.candidates
|
||||||
if file_exists(Directory..candidates[Display_settings.palette_alternative_index]) then
|
if #p.candidates > 0 then
|
||||||
command.open_file_in_next_column(candidates[Display_settings.palette_alternative_index])
|
if file_exists(Directory..p.candidates[p.alternative_index]) then
|
||||||
|
command.open_file_in_next_column(p.candidates[p.alternative_index])
|
||||||
else
|
else
|
||||||
run_command(command_string(candidates[Display_settings.palette_alternative_index]))
|
run_command(command_string(p.candidates[p.alternative_index]))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- try to run the command as if it contains args
|
-- try to run the command as if it contains args
|
||||||
run_command_with_args(Display_settings.palette_command)
|
run_command_with_args(p.command)
|
||||||
end
|
end
|
||||||
-- forget text for next command
|
-- forget text for next command
|
||||||
Display_settings.palette_command = ''
|
Display_settings.palette = nil
|
||||||
Display_settings.show_palette = false
|
|
||||||
Display_settings.palette_alternative_index = 1
|
|
||||||
Display_settings.palette_candidates = nil
|
|
||||||
-- clean up some columns if possible
|
-- clean up some columns if possible
|
||||||
if Cursor_pane.col < 45 then
|
if Cursor_pane.col < 45 then
|
||||||
while #Surface > 50 do
|
while #Surface > 50 do
|
||||||
|
@ -238,20 +234,20 @@ function keychord_press_on_command_palette(chord, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif chord == 'up' then
|
elseif chord == 'up' then
|
||||||
if Display_settings.palette_alternative_index > 1 then
|
if Display_settings.palette.alternative_index > 1 then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-1
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-1
|
||||||
end
|
end
|
||||||
elseif chord == 'down' then
|
elseif chord == 'down' then
|
||||||
if Display_settings.palette_alternative_index < #Display_settings.palette_candidates then
|
if Display_settings.palette.alternative_index < #Display_settings.palette.candidates then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index+1
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+1
|
||||||
end
|
end
|
||||||
elseif chord == 'left' then
|
elseif chord == 'left' then
|
||||||
if Display_settings.palette_alternative_index > Palette_alternatives_height then
|
if Display_settings.palette.alternative_index > Palette_alternatives_height then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-Palette_alternatives_height
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-Palette_alternatives_height
|
||||||
end
|
end
|
||||||
elseif chord == 'right' then
|
elseif chord == 'right' then
|
||||||
if Display_settings.palette_alternative_index <= #Display_settings.palette_candidates-Palette_alternatives_height then
|
if Display_settings.palette.alternative_index <= #Display_settings.palette.candidates-Palette_alternatives_height then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index+Palette_alternatives_height
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+Palette_alternatives_height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -276,8 +272,8 @@ function draw_command_palette()
|
||||||
App.color(Command_palette_border_color)
|
App.color(Command_palette_border_color)
|
||||||
love.graphics.rectangle('line', 0, Menu_status_bar_height, App.screen.width, 5+Palette_alternatives_height*Line_height+5)
|
love.graphics.rectangle('line', 0, Menu_status_bar_height, App.screen.width, 5+Palette_alternatives_height*Line_height+5)
|
||||||
Palette_cursor = {y=Menu_status_bar_height+5, x=5, nextx=5}
|
Palette_cursor = {y=Menu_status_bar_height+5, x=5, nextx=5}
|
||||||
for i,cmd in ipairs(Display_settings.palette_candidates) do
|
for i,cmd in ipairs(Display_settings.palette.candidates) do
|
||||||
add_command_to_palette(cmd, i == Display_settings.palette_alternative_index)
|
add_command_to_palette(cmd, i == Display_settings.palette.alternative_index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -330,8 +326,8 @@ function add_command_to_palette(s, cursor_highlight)
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_palette_input(x, y)
|
function draw_palette_input(x, y)
|
||||||
love.graphics.print(Display_settings.palette_command, x,y)
|
love.graphics.print(Display_settings.palette.command, x,y)
|
||||||
x = x+Display_settings.font:getWidth(Display_settings.palette_command)
|
x = x+Display_settings.font:getWidth(Display_settings.palette.command)
|
||||||
draw_cursor(x, y)
|
draw_cursor(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -346,14 +342,14 @@ end
|
||||||
function candidates()
|
function candidates()
|
||||||
-- slight context-sensitive tweaks
|
-- slight context-sensitive tweaks
|
||||||
local candidates = initial_candidates()
|
local candidates = initial_candidates()
|
||||||
if Display_settings.palette_command == '' then
|
if Display_settings.palette.command == '' then
|
||||||
return candidates
|
return candidates
|
||||||
elseif Display_settings.palette_command:sub(1,1) == '/' then
|
elseif Display_settings.palette.command:sub(1,1) == '/' then
|
||||||
return {}
|
return {}
|
||||||
else
|
else
|
||||||
local results = filter_candidates(candidates, Display_settings.palette_command)
|
local results = filter_candidates(candidates, Display_settings.palette.command)
|
||||||
if Display_settings.mode == 'normal' then
|
if Display_settings.mode == 'normal' then
|
||||||
append(results, file_candidates(Display_settings.palette_command))
|
append(results, file_candidates(Display_settings.palette.command))
|
||||||
end
|
end
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
24
run.lua
24
run.lua
|
@ -71,9 +71,7 @@ function run.initialize_globals()
|
||||||
x=0, y=0, -- <==== Top-left corner of the viewport into the surface
|
x=0, y=0, -- <==== Top-left corner of the viewport into the surface
|
||||||
column_width=400,
|
column_width=400,
|
||||||
show_debug=false,
|
show_debug=false,
|
||||||
show_palette=false,
|
palette=nil, -- {command='', alternative_index=1, candidates=nil}
|
||||||
palette_command='',
|
|
||||||
palette_alternative_index=1, palette_candidates=nil,
|
|
||||||
search_term='',
|
search_term='',
|
||||||
search_backup_x=nil, search_backup_y=nil, search_backup_cursor_pane=nil,
|
search_backup_x=nil, search_backup_y=nil, search_backup_cursor_pane=nil,
|
||||||
search_all_query=nil, search_all_terms=nil,
|
search_all_query=nil, search_all_terms=nil,
|
||||||
|
@ -457,7 +455,7 @@ function run.draw()
|
||||||
if Display_settings.mode == 'search_all' or Display_settings.mode == 'searching_all' then
|
if Display_settings.mode == 'search_all' or Display_settings.mode == 'searching_all' then
|
||||||
draw_command_palette_for_search_all()
|
draw_command_palette_for_search_all()
|
||||||
else
|
else
|
||||||
if Display_settings.show_palette then
|
if Display_settings.palette then
|
||||||
draw_command_palette()
|
draw_command_palette()
|
||||||
else
|
else
|
||||||
show_error()
|
show_error()
|
||||||
|
@ -596,7 +594,7 @@ function run.update(dt)
|
||||||
edit.update(pane, dt)
|
edit.update(pane, dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not Display_settings.show_palette and (Display_settings.mode == 'normal' or Display_settings.mode == 'search') and App.mouse_down(1) then
|
if not Display_settings.palette and (Display_settings.mode == 'normal' or Display_settings.mode == 'search') and App.mouse_down(1) then
|
||||||
-- pan the surface by dragging
|
-- pan the surface by dragging
|
||||||
plan_draw()
|
plan_draw()
|
||||||
end
|
end
|
||||||
|
@ -817,10 +815,10 @@ function run.text_input(t)
|
||||||
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
||||||
--? print('textinput', t)
|
--? print('textinput', t)
|
||||||
-- hotkeys operating on the cursor pane
|
-- hotkeys operating on the cursor pane
|
||||||
if Display_settings.show_palette then
|
if Display_settings.palette then
|
||||||
Display_settings.palette_command = Display_settings.palette_command..t
|
Display_settings.palette.command = Display_settings.palette.command..t
|
||||||
Display_settings.palette_alternative_index = 1
|
Display_settings.palette.alternative_index = 1
|
||||||
Display_settings.palette_candidates = candidates()
|
Display_settings.palette.candidates = candidates()
|
||||||
elseif Display_settings.mode == 'normal' then
|
elseif Display_settings.mode == 'normal' then
|
||||||
if Cursor_pane.col >= 1 then
|
if Cursor_pane.col >= 1 then
|
||||||
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
|
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
|
||||||
|
@ -893,12 +891,11 @@ function run.keychord_press(chord, key)
|
||||||
elseif chord == 'C-0' then
|
elseif chord == 'C-0' then
|
||||||
update_font_settings(20)
|
update_font_settings(20)
|
||||||
-- mode-specific hotkeys
|
-- mode-specific hotkeys
|
||||||
elseif Display_settings.show_palette then
|
elseif Display_settings.palette then
|
||||||
keychord_press_on_command_palette(chord, key)
|
keychord_press_on_command_palette(chord, key)
|
||||||
elseif Display_settings.mode == 'normal' then
|
elseif Display_settings.mode == 'normal' then
|
||||||
if chord == 'C-return' then
|
if chord == 'C-return' then
|
||||||
Display_settings.show_palette = true
|
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
|
||||||
Display_settings.palette_candidates = candidates()
|
|
||||||
elseif chord == 'C-f' then
|
elseif chord == 'C-f' then
|
||||||
command.commence_find_on_surface()
|
command.commence_find_on_surface()
|
||||||
elseif Cursor_pane.col >= 1 then
|
elseif Cursor_pane.col >= 1 then
|
||||||
|
@ -943,8 +940,7 @@ function run.keychord_press(chord, key)
|
||||||
interrupt_search_all()
|
interrupt_search_all()
|
||||||
elseif Display_settings.mode == 'maximize' then
|
elseif Display_settings.mode == 'maximize' then
|
||||||
if chord == 'C-return' then
|
if chord == 'C-return' then
|
||||||
Display_settings.show_palette = true
|
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
|
||||||
Display_settings.palette_candidates = candidates()
|
|
||||||
else
|
else
|
||||||
keychord_press_in_maximize_mode(chord, key)
|
keychord_press_in_maximize_mode(chord, key)
|
||||||
end
|
end
|
||||||
|
|
2
text.lua
2
text.lua
|
@ -93,7 +93,7 @@ function Text.draw_cursor(State, x, y, force)
|
||||||
if not State.editable and not force then
|
if not State.editable and not force then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Display_settings.show_palette then return end
|
if Display_settings.palette then return end
|
||||||
-- blink every 0.5s
|
-- blink every 0.5s
|
||||||
if math.floor(Cursor_time*2)%2 == 0 then
|
if math.floor(Cursor_time*2)%2 == 0 then
|
||||||
App.color(Cursor_color)
|
App.color(Cursor_color)
|
||||||
|
|
Loading…
Reference in New Issue