patch 9.1.1728: termdebug: cannot evaluate visual selected expression

Problem:  termdebug: cannot evaluate visual selected expression
Solution: Add support for visual mode, mapped to K by default (bennyyip)

closes: #18184

Signed-off-by: bennyyip <yebenmy@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
bennyyip
2025-09-02 20:06:20 +02:00
committed by Christian Brabandt
parent 1c36a85237
commit 884290ebf0
4 changed files with 26 additions and 3 deletions

View File

@ -1,4 +1,4 @@
*terminal.txt* For Vim version 9.1. Last change: 2025 Jul 08
*terminal.txt* For Vim version 9.1. Last change: 2025 Sep 02
VIM REFERENCE MANUAL by Bram Moolenaar
@ -1467,7 +1467,8 @@ Inspecting variables ~
`:Evaluate` evaluate the expression under the cursor
`K` same (see |termdebug_map_K| to disable)
`:Evaluate` {expr} evaluate {expr}
`:'<,'>Evaluate` evaluate the Visually selected text
`:'<,'>Evaluate`
`{Visual}K` evaluate the Visually selected text
This is similar to using "print" in the gdb window.
You can usually shorten `:Evaluate` to `:Ev`.

View File

@ -4,7 +4,7 @@ vim9script
# Author: Bram Moolenaar
# Copyright: Vim license applies, see ":help license"
# Last Change: 2025 Aug 24
# Last Change: 2025 Sep 02
# Converted to Vim9: Ubaldo Tiberi <ubaldo.tiberi@gmail.com>
# WORK IN PROGRESS - The basics works stable, more to come
@ -139,6 +139,7 @@ var winbar_winids: list<number>
var saved_mousemodel: string
var saved_K_map: dict<any>
var saved_visual_K_map: dict<any>
var saved_plus_map: dict<any>
var saved_minus_map: dict<any>
@ -218,6 +219,7 @@ def InitScriptVariables()
saved_K_map = maparg('K', 'n', false, true)
saved_plus_map = maparg('+', 'n', false, true)
saved_minus_map = maparg('-', 'n', false, true)
saved_visual_K_map = maparg('K', 'x', false, true)
if has('menu')
saved_mousemodel = &mousemodel
@ -1204,6 +1206,9 @@ def InstallCommands()
if !empty(saved_K_map) && !saved_K_map.buffer || empty(saved_K_map)
nnoremap K :Evaluate<CR>
endif
if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer || empty(saved_visual_K_map)
xnoremap K :Evaluate<CR>
endif
endif
map = true
@ -1299,6 +1304,12 @@ def DeleteCommands()
silent! nunmap K
endif
if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer
mapset(saved_visual_K_map)
elseif empty(saved_visual_K_map)
silent! xunmap K
endif
if !empty(saved_plus_map) && !saved_plus_map.buffer
mapset(saved_plus_map)
elseif empty(saved_plus_map)