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

Clap files: file selection incorrect after modifying pattern #646

Closed
circld opened this issue Mar 1, 2021 · 3 comments
Closed

Clap files: file selection incorrect after modifying pattern #646

circld opened this issue Mar 1, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@circld
Copy link

circld commented Mar 1, 2021

Environment (please complete the following information):

  • OS: macOS Catalina 10.15.6
  • (Neo)Vim version: 0.4.4
  • vim-clap version: 0.23 (8b618fc)
  • Have you reproduced with a minimal vimrc: yes
  • Have you updated to the latest plugin version: yes
  • Have you upgraded to/compiled the latest Rust binary: yes

Describe the bug
After selecting multiple files to open using <tab> and updating the search pattern, the files selected change. Put differently, the selections appear to be index-based and when the list updates in response to a change in search pattern, the same indices are selected even though the filenames in those indices are now different.

Clap debug

            has cargo: 1
            has maple: /<user_path>/.vim/plugged/vim-clap/target/release/maple
           maple info: version 0.1.23, built for x86_64-apple-darwin by rustc 1.50.0 (cb75ad5db 2021-02-10).
         has +python3: 1
has py dynamic module: 1
            has ctags:
vim-clap: Ensure ctags executable is in your PATH and has the JSON output featurectags without JSON output support
    Current sync impl: Python
     Current FileType:
Third Party Providers: []
       Global Options:
    let g:clap#autoload_dir = '/<user_path>/.vim/plugged/vim-clap/autoload'
    let g:clap#provider_alias = {'gfiles': 'git_files', 'hist:': 'command_history', 'hist/': 'search_history'}
    let g:clap_background_shadow_blend = 50
    let g:clap_disable_bottom_top = 0
    let g:clap_disable_matches_indicator = v:false
    let g:clap_disable_optional_async = v:false
    let g:clap_disable_run_rooter = v:false
    let g:clap_enable_background_shadow = v:true
    let g:clap_enable_debug = v:false
    let g:clap_enable_icon = 0
    let g:clap_forerunner_status_sign = {'done': '•', 'running': '!', 'using_cache': '*'}
    let g:clap_insert_mode_only = v:false
    let g:clap_multi_selection_warning_silent = 0
    let g:clap_no_matches_msg = 'NO MATCHES FOUND'
    let g:clap_open_action = {'ctrl-v': 'vsplit', 'ctrl-x': 'split', 'ctrl-t': 'tab split'}
    let g:clap_open_preview = 'always'
    let g:clap_popup_border = 'rounded'
    let g:clap_preview_direction = 'LR'
    let g:clap_preview_size = 5
    let g:clap_providers_relaunch_code = '@@'
    let g:clap_search_box_border_style = 'nil'
    let g:clap_search_box_border_symbols = {'nil': ['', ''], 'curve': ['', ''], 'arrow': ['', '']}
  Provider Variables:
                     []

To Reproduce
Steps to reproduce the behavior:

  1. Create the minimal vimrc min.vim:
set nocompatible
set runtimepath^=/path/to/vim-clap
syntax on
filetype plugin indent on

call plug#begin('~/.vim/plugged')
Plug 'liuchengxu/vim-clap'
call plug#end()
  1. Start (neo)vim with command: vim -u min.vim

  2. Create a directory with the following structure:

base/
├─ sub1/
│  ├─ file1
|  ├─ ...
│  ├─ file100
├─ sub2/
│  ├─ file3
  1. Navigate to base/
  2. Enter :Clap files
  3. Select the first 5 entries
  4. Type sub2
  5. Note that the selections have updated to different files. Hitting <Enter> now will open the visible files, not the original selection.

Expected behavior

One of either:

  1. When a file is selected and the search pattern is changed, the selected file is persisted. This behavior would make Clap files much more powerful as it would allow the user to quickly add files adhering to different patterns to the quickfix list for easy navigation.
  2. If this behavior is not the desired behavior, then all selections should be cleared upon pattern change. I struggle to think of a use case where updating the selected files in place based on the pattern is desirable.

Screenshots

Selecting first 5:
image

Updating pattern:
image

Hitting enter:
image

@circld circld added the bug Something isn't working label Mar 1, 2021
@liuchengxu
Copy link
Owner

liuchengxu commented Mar 1, 2021

What I can do is clearing the old selections when the input updates, you have to reselect the items given the new input.

diff --git a/autoload/clap/api.vim b/autoload/clap/api.vim
index 0865aab..18aefb9 100644
--- a/autoload/clap/api.vim
+++ b/autoload/clap/api.vim
@@ -374,6 +374,7 @@ function! s:init_provider() abort
       return
     endif
     try
+      call clap#sign#reset()
       call self._().on_typed()
       call clap#preview#async_open_with_delay()
     catch

@circld
Copy link
Author

circld commented Mar 6, 2021

That would be better and more intuitive behavior for sure.

The ability to retain selected entries across different patterns within a single Clap search session would be amazing though. I imagine the current implementation is largely "stateless", and therefore persisting selections and displaying them would require some nontrivial changes to the existing implementation. Happy to make a separate feature request for this though.

@liuchengxu
Copy link
Owner

The current selections can be retained when the input updates, but they can't be displayed in the window anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants