Skip to content

navigating menu siblings directly from the bar. #228

@bheadwhite

Description

@bheadwhite

hi. of course let me begin, thanks for creating this great plugin! i have a use case that im exploring and i wonder if im just going about it all wrong.

step one: i'd like to enter the dropbar focus using api:pick, and focus on the dropbar symbol that is relevant to my cursor position.
step two: i'd like to traverse up and down in that menu (this works beautifully)
step three: i'd like to traverse to the sibling top level drop bar menus. aka...
if i enter pick mode and i only have 3 options (a, b, c) i get into c, by way of my keyboard shortcut, and then if i can call pick again on a relative number :pick(-1) or :pick(+1)... id like move from c => b, and then back to c

i was able to hack my way to that behavior on version 10 (commit d0c78c5) ... the commit right after that breaks my workaround.

is this behavior currently supported and im just missing it in the docs or is it within the scope of the project to support? im couped to version 10 for now to support my use cases.. thanks so much!

local initial_idx = nil
local current_bar = nil

function activate_top_level_components()
  current_bar = require("dropbar.utils").bar.get_current()
  if not current_bar then
    return
  end

  for _, component in ipairs(current_bar.components) do
    if component.name_hl == "DropBarFileName" then
      if current_bar.components[component.bar_idx + 1] ~= nil then
        current_idx = component.bar_idx + 1
      else
        current_idx = component.bar_idx
      end
      initial_idx = current_idx
      break
    end
  end
end

function handleEnterDropBarUp()
  local dropbar_t = require("dropbar.utils").bar.get_current()
  if not dropbar_t then
    -- send up key
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Up>", true, true, true), "n", true)
    return
  end

  activate_top_level_components()
  if not current_bar then
    return
  end

  if not current_idx or current_bar.components[current_idx] == nil then
    return
  end

  current_bar:pick(current_idx)
end

function handleEnterDropBarDown()
  local dropbar_t = require("dropbar.utils").bar.get_current()
  if not dropbar_t then
    -- send up key
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Down>", true, true, true), "n", true)
    return
  end
  activate_top_level_components()
  if not current_bar then
    return
  end
  if not current_idx or current_bar.components[current_idx] == nil then
    return
  end

  current_bar:pick(current_idx)
end

vim.keymap.set("n", "K", handleEnterDropBarUp, { noremap = true, silent = true })
vim.keymap.set("n", "J", handleEnterDropBarDown, { noremap = true, silent = true })
vim.keymap.set("n", "H", function()
  local dropbar = require("dropbar.api").get_current_dropbar()

  if dropbar == nil then
    local menu = require("dropbar.utils").menu.get_current()
    if menu == nil or current_bar == nil or current_idx == 1 then
      return
    end

    current_idx = current_idx - 1

    menu:close()
    current_bar:pick(current_idx)
    return
  end

  if not dropbar.in_pick_mode then
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("_", true, true, true), "n", true)
    return
  end
end, { noremap = true, silent = true })

vim.keymap.set("n", "L", function()
  local dropbar = require("dropbar.api").get_current_dropbar()

  if dropbar == nil then
    local menu = require("dropbar.utils").menu.get_current()
    if menu == nil or current_idx + 1 > initial_idx or current_bar == nil then
      return
    end

    current_idx = current_idx + 1
    menu:close()

    current_bar:pick(current_idx)
    return
  end

  if not dropbar.in_pick_mode then
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("$", true, true, true), "n", true)
    return
  end
end, { noremap = true, silent = true })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions