changeset 35464:ce3a147071f6 v9.1.0501

patch 9.1.0501: too complicated mapping restore in termdebug Commit: https://github.com/vim/vim/commit/46f2823807741ac91c51cf36ddabf293db26ab41 Author: Ubaldo Tiberi <ubaldo.tiberi@google.com> Date: Wed Jun 19 19:50:32 2024 +0200 patch 9.1.0501: too complicated mapping restore in termdebug Problem: too complicated mapping restore in termdebug Solution: simplify unmapping logic, add a few more tests (Ubaldo Tiberi) closes: #15046 Signed-off-by: Ubaldo Tiberi <ubaldo.tiberi@google.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 19 Jun 2024 20:00:08 +0200
parents fd2a8067aee3
children 6c310db41aac
files runtime/pack/dist/opt/termdebug/plugin/termdebug.vim src/testdir/test_termdebug.vim src/version.c
diffstat 3 files changed, 40 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -1224,33 +1224,25 @@ def DeleteCommands()
   delcommand Winbar
 
 
-  if !empty(saved_K_map) && saved_K_map.buffer
-    # pass
-  elseif !empty(saved_K_map) && !saved_K_map.buffer
-    nunmap K
+  if !empty(saved_K_map) && !saved_K_map.buffer
     mapset(saved_K_map)
   elseif empty(saved_K_map)
     silent! nunmap K
   endif
 
-  if !empty(saved_plus_map) && saved_plus_map.buffer
-    # pass
-  elseif !empty(saved_plus_map) && !saved_plus_map.buffer
-    nunmap +
+  if !empty(saved_plus_map) && !saved_plus_map.buffer
     mapset(saved_plus_map)
   elseif empty(saved_plus_map)
     silent! nunmap +
   endif
 
-  if !empty(saved_minus_map) && saved_minus_map.buffer
-    # pass
-  elseif !empty(saved_minus_map) && !saved_minus_map.buffer
-    nunmap -
+  if !empty(saved_minus_map) && !saved_minus_map.buffer
     mapset(saved_minus_map)
   elseif empty(saved_minus_map)
     silent! nunmap -
   endif
 
+
   if has('menu')
     # Remove the WinBar entries from all windows where it was added.
     var curwinid = win_getid()
--- a/src/testdir/test_termdebug.vim
+++ b/src/testdir/test_termdebug.vim
@@ -278,9 +278,20 @@ func Test_termdebug_mapping()
   call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
 
   %bw!
+
+  " -- Test that local-buffer mappings are restored in the correct buffers --
+  " local mappings for foo
+  file foo
   nnoremap <buffer> K :echom "bK"<cr>
   nnoremap <buffer> - :echom "b-"<cr>
   nnoremap <buffer> + :echom "b+"<cr>
+
+  " no mappings for 'bar'
+  enew
+  file bar
+
+  " Start termdebug from foo
+  buffer foo
   Termdebug
   call WaitForAssert({-> assert_equal(3, winnr('$'))})
   wincmd b
@@ -288,10 +299,33 @@ func Test_termdebug_mapping()
   call assert_true(maparg('-', 'n', 0, 1).buffer)
   call assert_true(maparg('+', 'n', 0, 1).buffer)
   call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
+
+  Source
+  buffer bar
+  call assert_false(maparg('K', 'n', 0, 1)->empty())
+  call assert_false(maparg('-', 'n', 0, 1)->empty())
+  call assert_false(maparg('+', 'n', 0, 1)->empty())
+  call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
+  call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
+  call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
   wincmd t
   quit!
   redraw!
   call WaitForAssert({-> assert_equal(1, winnr('$'))})
+
+  " Termdebug session ended. Buffer 'bar' shall have no mappings
+  call assert_true(bufname() ==# 'bar')
+  call assert_false(maparg('K', 'n', 0, 1)->empty())
+  call assert_false(maparg('-', 'n', 0, 1)->empty())
+  call assert_false(maparg('+', 'n', 0, 1)->empty())
+  call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
+  call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
+  call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
+
+  " Buffer 'foo' shall have the same mapping as before running the termdebug
+  " session
+  buffer foo
+  call assert_true(bufname() ==# 'foo')
   call assert_true(maparg('K', 'n', 0, 1).buffer)
   call assert_true(maparg('-', 'n', 0, 1).buffer)
   call assert_true(maparg('+', 'n', 0, 1).buffer)
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    501,
+/**/
     500,
 /**/
     499,