]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0464: runtime(netrw): bookmarking directory uses current dir v9.2.0464
authorJ. Paulo Seibt <jpseibt@gmail.com>
Sun, 10 May 2026 16:50:02 +0000 (16:50 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 10 May 2026 16:55:18 +0000 (16:55 +0000)
Problem:  runtime(netrw): bookmarking directory uses current dir
Solution: Correctly handle netrw actual directory (J. Paulo Seibt)

fixes:  #10481
closes: #20169

Signed-off-by: J. Paulo Seibt <jpseibt@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/pack/dist/opt/netrw/autoload/netrw.vim
src/testdir/test_plugin_netrw.vim
src/version.c

index 90fd70472a63e87d3275cf649493668ac6ce62cf..7d73af8fae1731aa16f1f29c95b1d1a8069ce89b 100644 (file)
@@ -1,7 +1,7 @@
 " Creator:    Charles E Campbell
 " Previous Maintainer: Luca Saccarola <github.e41mv@aleeas.com>
 " Maintainer: This runtime file is looking for a new maintainer.
-" Last Change: 2026 May 05
+" Last Change: 2026 May 10
 " Copyright:  Copyright (C) 2016 Charles E. Campbell {{{1
 "             Permission is hereby granted to use and distribute this code,
 "             with or without modifications, provided that this copyright
@@ -8989,11 +8989,10 @@ function s:MakeBookmark(fname)
     if index(g:netrw_bookmarklist,a:fname) == -1
         " curdir not currently in g:netrw_bookmarklist, so include it
         if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
-            call add(g:netrw_bookmarklist,a:fname.'/')
-        elseif a:fname !~ '/'
-            call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
+            " Directory without a trailing slash
+            call add(g:netrw_bookmarklist, s:NetrwFile(a:fname) . '/')
         else
-            call add(g:netrw_bookmarklist,a:fname)
+            call add(g:netrw_bookmarklist, s:NetrwFile(a:fname))
         endif
         call sort(g:netrw_bookmarklist)
     endif
index b66bb4a72ed5472e431702d91d268f381e4cf294..5a86c29b7b4cc4f2934852bbcd62320d64bb0660 100644 (file)
@@ -165,6 +165,13 @@ function Test_NetrwUnMarkFile()
     " wipe out the test buffer
     bw
 endfunction
+
+function Test_MakeBookmark(netrw_curdir, fname)
+  new
+  let b:netrw_curdir = a:netrw_curdir
+  call s:MakeBookmark(a:fname)
+  bw
+endfunction
 " }}}
 END
 
@@ -676,4 +683,38 @@ func Test_netrw_unmark_all()
   call Test_NetrwUnMarkFile()
 endfunc
 
+" Creating a bookmark from a marked file should use b:netrw_curdir as head directory
+func Test_netrw_bookmark_marked_file()
+  let save_keepdir = g:netrw_keepdir
+  let save_workdir = getcwd()
+  let save_bookmarklist = exists('g:netrw_bookmarklist') ? g:netrw_bookmarklist : v:null
+
+  " Make sure Vim's working directory diverge from Netrw's
+  let g:netrw_keepdir = 1
+  let g:netrw_bookmarklist = []
+  let test_workdir = 'Xtest_workdir'
+  let test_netrw_curdir = test_workdir . '/Xtest_netrw_curdir'
+  call mkdir(test_netrw_curdir, 'p')
+  call writefile([], test_netrw_curdir . '/test_file')
+
+  execute 'cd ' . test_workdir
+  call Test_MakeBookmark(test_netrw_curdir, 'test_file')
+
+  call assert_equal(1, len(g:netrw_bookmarklist))
+  call assert_match(test_netrw_curdir . '/test_file', g:netrw_bookmarklist[0])
+
+  " Tear down
+  execute 'cd ' . save_workdir
+  call delete(test_workdir, 'rf')
+
+  let g:netrw_keepdir = save_keepdir
+  if save_bookmarklist is v:null
+    unlet g:netrw_bookmarklist
+  else
+    let g:netrw_bookmarklist = save_bookmarklist
+  endif
+
+  bw!
+endfunc
+
 " vim:ts=8 sts=2 sw=2 et
index 1e9a692ea10954625d3aab417fb509a584021c94..339bc4459361b44ebf3ef8a108db5dd4c80cbde8 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    464,
 /**/
     463,
 /**/