Skip to content

Commit 8167f00

Browse files
m0viedanielshahaf
authored andcommitted
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 b7b20d5 commit 8167f00

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-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
@@ -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.
@@ -596,7 +595,7 @@ _zsh_highlight_main_highlighter_check_path()
596595

597596
# If this word ends the buffer, check if it's the prefix of a valid path.
598597
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] &&
599-
[[ $WIDGET != accept-* ]]; then
598+
[[ $WIDGET != zle-line-finish ]]; then
600599
local -a tmp
601600
tmp=( ${expanded_path}*(N) )
602601
(( $#tmp > 0 )) && REPLY=path_prefix && return 0

highlighters/main/test-data/path_prefix2.zsh

+1-1
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

+6
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ _zsh_highlight_bind_widgets()
252252
# Override ZLE widgets to make them invoke _zsh_highlight.
253253
local -U widgets_to_bind
254254
widgets_to_bind=(${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)})
255+
256+
# Always wrap special zle-line-finish widget. This is needed to decide if the
257+
# current line ends and special highlighting logic needs to be applied.
258+
# E.g. remove cursor imprint, don't highlight partial paths, ...
259+
widgets_to_bind+=(zle-line-finish)
260+
255261
local cur_widget
256262
for cur_widget in $widgets_to_bind; do
257263
case $widgets[$cur_widget] in

0 commit comments

Comments
 (0)