Skip to content

Commit 2ba33bb

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 1d855a3 commit 2ba33bb

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

highlighters/cursor/cursor-highlighter.zsh

+3-4
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
_zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor
4847
}

highlighters/main/main-highlighter.zsh

+3-4
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.
@@ -485,7 +484,7 @@ _zsh_highlight_main_highlighter_check_path()
485484

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

highlighters/main/test-data/path_prefix2.zsh

+1-1
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 default" # /bin/s

zsh-syntax-highlighting.zsh

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ _zsh_highlight_bind_widgets || {
325325
return 1
326326
}
327327

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

0 commit comments

Comments
 (0)