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

The file path returned by the yank:path contains too many backslashes. #391

Closed
toriwasa opened this issue Feb 8, 2022 · 7 comments · Fixed by #392
Closed

The file path returned by the yank:path contains too many backslashes. #391

toriwasa opened this issue Feb 8, 2022 · 7 comments · Fixed by #392
Labels
bug Something isn't working help wanted Extra attention is needed windows Windows specific issue

Comments

@toriwasa
Copy link

toriwasa commented Feb 8, 2022

Describe the bug:

When I select a child node and use yank:path with Drives or C:\ displayed in the root directory,
the file path returned by yank:path contains too many backslashes in the part immediately after the drive name.

If there is no Drives or C:\ in the root directory, the file path returned by yank:path is normal.

yank:path result

root directory path selected node path yank:path result
Drives Drives
Drives C:\ C:\\
Drives C:\parent\child C:\\\parent\child
C:\ C:\ C:\
C:\ C:\parent\child C:\\parent\child
C:\parent C:\parent\child C:\parent\child

Environment:

OS: Windows11 Version 10.0.22000.434
Terminal: Windows Terminal 1.12.10334.0
Vim: NVIM v0.6.1

To Reproduce:

Case 1:

  1. launch Neovim.
  2. enter :Fern /.
  3. C:\ displayed in the root directory.
  4. select a child node (e.g. C:\parent\child) and use yank:path.
  5. C:\\parent\child yanked.

Case 2:

  1. launch Neovim.
  2. enter :Fern /.
  3. C:\ displayed in the root directory.
  4. hit <C-h>, leave action invoke.
  5. Drives displayed in the root directory.
  6. select a child node (e.g. C:\parent\child) and use yank:path.
  7. C:\\\parent\child yanked.

Expected behavior:

Only one backslash should appear in the part of the file path immediately after the drive name.

Additional Context:

When I select the child node I described above and run rename,
the file path displayed as the rename target also shows too many backslashes, just like this issue.

However, even if I execute rename with too many backslashes in the file path, the rename will be completed without any problem.

This behavior is probably related to the above issue, so I will describe it here.

@lambdalisue lambdalisue added bug Something isn't working help wanted Extra attention is needed windows Windows specific issue labels Feb 8, 2022
lambdalisue added a commit that referenced this issue Feb 8, 2022
@lambdalisue
Copy link
Owner

@toriwasa Could you try #392?

@toriwasa
Copy link
Author

toriwasa commented Feb 8, 2022

I have tried #392 in the following ways.

I am not familiar with how to use the Pull Request as my plugin.
If there is something wrong with the way I did it, please point it out.

(I use Powershell)
> cd ~\Git
> git clone https://github.com/lambdalisue/fern.vim.git
> cd ~\Git\fern.vim\
> gh pr checkout 392
(I use vim-plug to install fern.vim)
> rm -Recurse ~\.vim\plugged\fern.vim
> cp -Recurse ~\Git\fern.vim ~\.vim\plugged\fern.vim

Then I tried again To Reproduce: and Additional Context.
But in both yank:path and rename cases, the file paths with too many backslashes remained unchanged.

@lambdalisue
Copy link
Owner

It seems you properly use the PR version.
Hum... then I need to investigate it a bit deeper...

@toriwasa
Copy link
Author

toriwasa commented Feb 9, 2022

I'm not sure that the information below will help you modify your code,
but here are some additional results from executing yank:bufname.

yank:path and yank:bufname result
(I tried with #392)

root directory path selected node path yank:path result yank:bufname result
Drives Drives fern:///file:///
Drives C:\ C:\\ fern:///file:///C:$
Drives C:\parent\child C:\\\parent\child fern:///file:///C:/parent/child$
C:\ C:\ C:\ fern:///file:///C:$
C:\ C:\parent\child C:\\parent\child fern:///file:///C:/parent/child$
C:\parent C:\parent\child C:\parent\child fern:///file:///C:/parent/child$

From the above results, it seems that unlike the yank:path results, the yank:bufname results correctly display the file path.

@lambdalisue
Copy link
Owner

lambdalisue commented Feb 10, 2022

It seems simplify does not affect backslashes and

--- a/autoload/fern/scheme/file/provider.vim
+++ b/autoload/fern/scheme/file/provider.vim
@@ -118,7 +118,7 @@ endif
​
 if s:is_windows
   let s:windows_drive_nodes = fern#scheme#file#util#list_drives(s:CancellationToken.none)
-          \.then(s:AsyncLambda.map_f({ v -> s:safe(funcref('s:node', [v . '\'])) }))
+          \.then(s:AsyncLambda.map_f({ v -> s:safe(funcref('s:node', [v])) }))
           \.then(s:AsyncLambda.filter_f({ v -> !empty(v) }))
 endif
​
--- a/autoload/fern/scheme/file/util.vim
+++ b/autoload/fern/scheme/file/util.vim
@@ -36,8 +36,9 @@ if exists('*readdir')
   function! fern#scheme#file#util#list_entries_readdir(path, ...) abort
     let l:Profile = fern#profile#start('fern#scheme#file#util#list_entries_readdir')
     let s = s:is_windows ? '\' : '/'
-    return s:Promise.resolve(readdir(a:path))
-          \.then(s:AsyncLambda.map_f({ v -> a:path . s . v }))
+    let path = a:path . (a:path[-1:] ==# s ? '' : s)
+    return s:Promise.resolve(readdir(path))
+          \.then(s:AsyncLambda.map_f({ v -> path . v }))
           \.finally({ -> Profile() })
   endfunction
 endif

This patch may fix the issue (thanks to @ichizok on vim-jp Slack https://vim-jp.slack.com/archives/CLKR04BEF/p1644392038457259)

I need to investigate it.

@lambdalisue
Copy link
Owner

@toriwasa Could you try #392 again? I've applied a modified version of the above patch.

@toriwasa
Copy link
Author

That's great!
Thanks for your fix.
I've tried #392 above again, and confirmed that no backslash duplication occurs for both To Reproduce: case 1 and case 2!
I also checked for rename and did not reproduce the duplicate backslashes.
I think this issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed windows Windows specific issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants