Skip to content

Commit b07c408

Browse files
committed
always bind zle-line-finish and use it instead of accept-*
Special handling for cursor imprint or partial path highlighting is needed in more cases than accept-*. For example when accepting a line from isearch, no accept-* widget is invoked. The proper way is to use zle-line-finish. Trumps #259. Fixes #284.
1 parent ebccec2 commit b07c408

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

highlighters/cursor/cursor-highlighter.zsh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@
3434
# Whether the cursor highlighter should be called or not.
3535
_zsh_highlight_cursor_highlighter_predicate()
3636
{
37-
# accept-* may trigger removal of cursor highlighting
38-
[[ $WIDGET == accept-* ]] ||
39-
_zsh_highlight_cursor_moved
37+
# remove cursor highlighting when the line is finished
38+
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved
4039
}
4140

4241
# Cursor highlighting function.
4342
_zsh_highlight_cursor_highlighter()
4443
{
45-
[[ $WIDGET == accept-* ]] && return
44+
[[ $WIDGET == zle-line-finish ]] && return
4645

4746
region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]")
4847
}

highlighters/main/main-highlighter.zsh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@
6060
# Whether the highlighter should be called or not.
6161
_zsh_highlight_main_highlighter_predicate()
6262
{
63-
# accept-* may trigger removal of path_prefix highlighting
64-
[[ $WIDGET == accept-* ]] ||
65-
_zsh_highlight_buffer_modified
63+
# may need to remove path_prefix highlighting when the line ends
64+
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified
6665
}
6766

6867
# Helper to deal with tokens crossing line boundaries.
@@ -486,7 +485,7 @@ _zsh_highlight_main_highlighter_check_path()
486485

487486
# If this word ends the buffer, check if it's the prefix of a valid path.
488487
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] &&
489-
[[ $WIDGET != accept-* ]]; then
488+
[[ $WIDGET != zle-line-finish ]]; then
490489
local -a tmp
491490
tmp=( ${expanded_path}*(N) )
492491
(( $#tmp > 0 )) && style_override=path_prefix && return 0

highlighters/main/test-data/path_prefix2.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight
3434
BUFFER='ls /bin/s'
35-
WIDGET=accept-line
35+
WIDGET=zle-line-finish
3636

3737
expected_region_highlight=(
3838
"4 9 $ZSH_HIGHLIGHT_STYLES[default]" # /bin/s

zsh-syntax-highlighting.zsh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ _zsh_highlight_bind_widgets || {
308308
return 1
309309
}
310310

311+
# Always wrap special zle-line-finish widget. This is needed to decide if the
312+
# current line ends and special highlighting logic needs to be applied.
313+
# E.g. remove cursor imprint, don't highlight partial paths, ...
314+
_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish
315+
311316
# Resolve highlighters directory location.
312317
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
313318
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2

0 commit comments

Comments
 (0)