source: up/down in file navigator

[?]
Sep 18, 2022, 7:37 AM
MDGHRTIFMMWBQZPIUCPE6ZM65Z4UOEQOHYDGH6J3M7MNQ6DCMR4AC

Dependencies

  • [2] KKMFQDR4 editing source code from within the app

Change contents

  • edit in commands.lua at line 107
    [2.207173]
    [2.207173]
    log(2, 'file navigator: '..chord)
    log(2, ('cursor initially at %d %s'):format(File_navigation.index, File_navigation.candidates[File_navigation.index]))
  • edit in commands.lua at line 122
    [2.207707]
    [2.207707]
    end
    elseif chord == 'down' then
    file_navigator_down()
    elseif chord == 'up' then
    file_navigator_up()
    end
    end
    function file_navigator_up()
    local y, x, width = file_coord(File_navigation.index)
    local index = file_index(y-Editor_state.line_height, x, width)
    if index then
    File_navigation.index = index
    end
    end
    function file_navigator_down()
    local y, x, width = file_coord(File_navigation.index)
    local index = file_index(y+Editor_state.line_height, x, width)
    if index then
    File_navigation.index = index
    end
    end
    function file_coord(index)
    local y,x = Menu_status_bar_height, 5
    for i,filename in ipairs(File_navigation.candidates) do
    local width = App.width(to_text(filename))
    if x + width > App.screen.width - 5 then
    y = y + Editor_state.line_height
    x = 5
    end
    if i == index then
    return y, x, width
    end
    x = x + width + 30
    end
    end
    function file_index(fy, fx, fwidth)
    log_start('file index')
    log(2, ('for %d %d %d'):format(fy, fx, fwidth))
    local y,x = Menu_status_bar_height, 5
    local best_guess, best_guess_x, best_guess_width
    for i,filename in ipairs(File_navigation.candidates) do
    local width = App.width(to_text(filename))
    if x + width > App.screen.width - 5 then
    y = y + Editor_state.line_height
    x = 5
  • edit in commands.lua at line 172
    [2.207715]
    [2.207715]
    if y == fy then
    log(2, ('%d: correct row; considering %d %s %d %d'):format(y, i, filename, x, width))
    if best_guess == nil then
    log(2, 'nil')
    best_guess = i
    best_guess_x = x
    best_guess_width = width
    elseif math.abs(fx + fwidth/2 - x - width/2) < math.abs(fx + fwidth/2 - best_guess_x - best_guess_width/2) then
    best_guess = i
    best_guess_x = x
    best_guess_width = width
    end
    log(2, ('best guess now %d %s %d %d'):format(best_guess, File_navigation.candidates[best_guess], best_guess_x, best_guess_width))
    end
    x = x + width + 30
  • edit in commands.lua at line 188
    [2.207721]
    [2.207721]
    log_end('file index')
    return best_guess