Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I call custom_actions entry? #51

Open
Ajaymamtora opened this issue Apr 21, 2024 · 5 comments
Open

How do I call custom_actions entry? #51

Ajaymamtora opened this issue Apr 21, 2024 · 5 comments

Comments

@Ajaymamtora
Copy link

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
Copy link
Contributor

xzbdmw commented Apr 22, 2024

You should set

        custom_actions = {
            open = detour_file,
        },

@Ajaymamtora
Copy link
Author

Thanks!

@Ajaymamtora
Copy link
Author

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
Copy link
Contributor

xzbdmw commented Apr 22, 2024

That should be easy to implement

@Ajaymamtora
Copy link
Author

That should be easy to implement

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants