Skip to content

Commit 276d31e

Browse files
committed
'driver': 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 zsh-users#259. Fixes zsh-users#284.
1 parent ae02016 commit 276d31e

File tree

4 files changed

+13
-9
lines changed

4 files changed

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

highlighters/main/main-highlighter.zsh

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

7069
# Helper to deal with tokens crossing line boundaries.
@@ -595,7 +594,7 @@ _zsh_highlight_main_highlighter_check_path()
595594

596595
# If this word ends the buffer, check if it's the prefix of a valid path.
597596
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] &&
598-
[[ $WIDGET != accept-* ]]; then
597+
[[ $WIDGET != zle-line-finish ]]; then
599598
local -a tmp
600599
tmp=( ${expanded_path}*(N) )
601600
(( $#tmp > 0 )) && REPLY=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
@@ -31,7 +31,7 @@
3131
# Related to path_prefix.zsh
3232

3333
BUFFER='ls /bin/s'
34-
WIDGET=accept-line
34+
WIDGET=zle-line-finish
3535

3636
expected_region_highlight=(
3737
"4 9 default" # /bin/s

zsh-syntax-highlighting.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ _zsh_highlight_bind_widgets()
237237
# Override ZLE widgets to make them invoke _zsh_highlight.
238238
local -U widgets_to_bind
239239
widgets_to_bind=(${${(f)"$(builtin zle -la)"}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)})
240+
241+
# Always wrap special zle-line-finish widget. This is needed to decide if the
242+
# current line ends and special highlighting logic needs to be applied.
243+
# E.g. remove cursor imprint, don't highlight partial paths, ...
244+
widgets_to_bind+=(zle-line-finish)
245+
240246
local cur_widget
241247
for cur_widget in $widgets_to_bind; do
242248
case $widgets[$cur_widget] in

0 commit comments

Comments
 (0)