weirongxu / coc-explorer

📁 Explorer for coc.nvim
MIT License
1.14k stars 45 forks source link

"explorer.buffer.tabOnly" shows only one buffer in current tab #494

Closed sainnhe closed 2 years ago

sainnhe commented 2 years ago

Describe the bug

When "explorer.buffer.tabOnly" is set to true, the buffer section should show all buffers in current tab, but in fact only the currently opened buffer will be shown.

Minimal vimrc

mini.vim:

set nocompatible
set runtimepath^=/Users/sainnhe/.local/share/nvim/plugins/coc.nvim
filetype plugin indent on
syntax on
set hidden
let g:coc_data_home = fnamemodify(stdpath('data'), ':p') . 'coc'
let g:coc_global_extensions = [
      \ 'coc-explorer',
      \ ]

coc-settings.json:

{
    "explorer.icon.enableNerdfont": true,
    "explorer.keyMappingMode": "none",
    "explorer.buffer.tabOnly": true,
    "explorer.keyMappings.global": {
        "s": "toggleSelection",
        "<leader>": "actionMenu",

        "h": "indentPrev",
        "l": "indentNext",
        "o": ["expandable?", ["expanded?", "collapse", "expand"], "open"],
        "<cr>": "open",
        "t": "open:tab",
        "<bs>": "gotoParent",

        "Y": "copyFilepath",
        "y": "copyFilename",
        "c": "copyFile",
        "x": "cutFile",
        "p": "pasteFile",
        "d": "delete",
        "D": "deleteForever",

        "n": "addFile",
        "N": "addDirectory",
        "r": "rename",

        ".": "toggleHidden",
        "R": "refresh",
        "<C-p>": "preview",

        "?": "help",
        "<esc>": "esc",
        "e": "systemExecute",

        "f": "searchRecursive",

        "gf": "gotoSource:file",
        "gb": "gotoSource:buffer",

        "gk": "gitPrev",
        "gj": "gitNext",
        "ga": "gitStage",
        "gu": "gitUnstage"
    },
}

Steps to reproduce this bug

  1. Navigate to a directory that contains at least 2 files (e.g. file1 and file2);
  2. Launch nvim via nvim -u /path/to/mini.vim file1;
  3. Execute :CocCommand explorer;
  4. Expand the buffer section, file1 is shown here;
  5. Press o to open another file file2;
  6. Now only file2 is shown in buffer section.

Expected behavior

Both file1 and file2 should be shown in buffer section.

weirongxu commented 2 years ago

This is by design, it seems that vim's buffer is not associated with tab. So tabOnly is designed using tabpagebuflist() function.

Or do you have any suggestions for improvement?

sainnhe commented 2 years ago

IMO, it's possible to maintain a dictionary variable that contains all the tabs to which a buffer belongs.

For example, create an autocmd triggered by BufAdd event which will update a t:var. This t:var is a dictionary, the key is bufnum, and the value is a list that contains all tabs this buffer belongs to.

weirongxu commented 2 years ago

It seems pretty good, I can maintain an array of tabs in my buffer object to do buffer filtering

sainnhe commented 2 years ago

Thanks! It works now. But there seems to be a bug in buffer.tabOnly mode:

If you set "explorer.buffer.tabOnly": true, in coc-settings.json and use nvim to open a file $ nvim filename.txt, the buffer section will be empty at the very beginning.

weirongxu commented 2 years ago

Thanks for the reply, it has been fixed in 0.21.2

sainnhe commented 2 years ago

Thank you! I can confirm that this has been fixed now.