otavioschwanck / arrow.nvim

Bookmark your files, separated by project, and quickly navigate through them.
Other
482 stars 23 forks source link

How do I call custom_actions entry? #51

Open Ajaymamtora opened 5 months ago

Ajaymamtora commented 5 months ago

How do I call my detour function via binding?

this is my config


function config.arrow()
  local mappings = {
    edit = "e",
    delete_mode = "d",
    clear_all_items = "C",
    toggle = "a", -- used as save if separate_save_and_remove is true
    open_vertical = "v",
    open_horizontal = "-",
    quit = "q",
    remove = "x", -- only used if separate_save_and_remove is true
    next_item = "]",
    prev_item = "[",
  }

  local detour_file = function(target_file_name, current_file_name)
  print("detour")
    local ok = require('detour').Detour() -- open a detour popup
    if not ok then
        return
    end

    vim.api.nvim_command("e " .. target_file_name)
  end

  local opts = {
    mappings = mappings,
    show_icons = true,
    separate_by_branch = false,
    separate_save_and_remove = true,
    leader_key = "J", -- Recommended to be a single key
    buffer_leader_key = "mj", -- Recommended to be a single key
    window = { -- controls the appearance and position of an arrow window (see nvim_open_win() for all options)
      width = "auto",
      height = "auto",
      row = "auto",
      col = "auto",
      border = "double",
    },
    per_buffer_config = {
      lines = 4, -- Number of lines showed on preview.
      sort_automatically = true, -- Auto sort buffer marks.
      treesitter_context = nil, -- it can be { line_shift_down = 2 }
    },
    save_key = "cwd", -- what will be used as root to save the bookmarks. Can be also `git_root`.
    global_bookmarks = false, -- if true, arrow will save files globally (ignores separate_by_branch)
    index_keys = "123456789zxcbnmZXVBNM,afghjklAFGHJKLwrtyuiopWRTYUIOP", -- keys mapped to bookmark index, i.e. 1st bookmark will be accessible by 1, and 12th - by c
    full_path_list = { "init" }, -- filenames on this list will ALWAYS show the file path too.
    custom_actions = {
      detour = detour_file,
    }
  }
  require("arrow").setup(opts)
end

I've tried adding mappings.detour but it doesnt do anything. I tried reading the code and the docs but I can't figure it out

xzbdmw commented 5 months ago

You should set

        custom_actions = {
            open = detour_file,
        },
Ajaymamtora commented 5 months ago

Thanks!

Ajaymamtora commented 5 months ago

Actually is there a way to declare a new item here? image

That way if i pressed a number itll do the default behaviour and open the file, but if I wanted to detour the selected file I could first press "F" for example then a number?

This way i still can quickly open a file and detour when I want to

xzbdmw commented 5 months ago

That should be easy to implement

Ajaymamtora commented 1 month ago

That should be easy to implement

hey are you still planning on implementing this? if not I can give it a go