Merge branch 'main' into fix-ui-responsiveness-regression

This commit is contained in:
Alexandre Pasmantier 2025-04-12 10:27:06 +00:00 committed by GitHub
commit fcc964f57c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 14 deletions

View File

@ -1,14 +1,18 @@
function tv_smart_autocomplete() { function tv_smart_autocomplete() {
# prefix (lhs of cursor)
local current_prompt="${READLINE_LINE:0:$READLINE_POINT}" local current_prompt="${READLINE_LINE:0:$READLINE_POINT}"
local output=$(tv --autocomplete-prompt "$current_prompt") local output=$(tv --autocomplete-prompt "$current_prompt" | tr '\n' ' ')
if [[ -n $output ]]; then if [[ -n $output ]]; then
# suffix (rhs of cursor)
local rhs="${READLINE_LINE:$READLINE_POINT}"
# add a space if the prompt does not end with one # add a space if the prompt does not end with one
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} " [[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "
READLINE_LINE=$current_prompt$output local lhs=$current_prompt$output
READLINE_POINT=${#READLINE_LINE} READLINE_LINE=$lhs$rhs
READLINE_POINT=${#lhs}
fi fi
} }

View File

@ -1,12 +1,13 @@
function tv_smart_autocomplete function tv_smart_autocomplete
# prefix (lhs of cursor)
set -l current_prompt (commandline -cp) set -l current_prompt (commandline -cp)
set -l output (tv --autocomplete-prompt "$current_prompt") set -l output (tv --autocomplete-prompt "$current_prompt")
if test -n "$output" if test -n "$output"
# add a space if the prompt does not end with one (unless the prompt is an implicit cd, e.g. '\.') # add a space if the prompt does not end with one (unless the prompt is an implicit cd, e.g. '\.')
string match -q -r '.*( |./)$' -- "$current_prompt" || set current_prompt "$current_prompt " string match -q -r '.*( |./)$' -- "$current_prompt" || set output " $output"
commandline -r "$current_prompt$output" commandline -i "$output"
commandline -f repaint commandline -f repaint
end end
end end

View File

@ -2,21 +2,24 @@ _tv_smart_autocomplete() {
emulate -L zsh emulate -L zsh
zle -I zle -I
# prefix (lhs of cursor)
local current_prompt local current_prompt
current_prompt=$LBUFFER current_prompt=$LBUFFER
local output local output
output=$(tv --autocomplete-prompt "$current_prompt" $* | tr '\n' ' ')
output=$(tv --autocomplete-prompt "$current_prompt" $*)
if [[ -n $output ]]; then if [[ -n $output ]]; then
zle reset-prompt # suffix (rhs of cursor)
RBUFFER="" local rhs=$RBUFFER
# add a space if the prompt does not end with one # add a space if the prompt does not end with one
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} " [[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "
LBUFFER=$current_prompt$output
LBUFFER=$current_prompt$output
CURSOR=${#LBUFFER}
RBUFFER=$rhs
zle reset-prompt
# uncomment this to automatically accept the line # uncomment this to automatically accept the line
# (i.e. run the command without having to press enter twice) # (i.e. run the command without having to press enter twice)
# zle accept-line # zle accept-line
@ -52,4 +55,3 @@ zle -N tv-shell-history _tv_shell_history
bindkey '{tv_smart_autocomplete_keybinding}' tv-smart-autocomplete bindkey '{tv_smart_autocomplete_keybinding}' tv-smart-autocomplete
bindkey '{tv_shell_history_keybinding}' tv-shell-history bindkey '{tv_shell_history_keybinding}' tv-shell-history