Skip to content

Commit 99edcd4

Browse files
committed
treat more widgets as accept-* kind of widgets and make it configurable
1 parent 38c3ac8 commit 99edcd4

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

highlighters/cursor/cursor-highlighter.zsh

+4-5
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+
# widgets which accept lines may trigger removal of cursor highlighting
38+
_zsh_highlight_cursor_moved || _zsh_highlight_is_accept_line_type_widget
4039
}
4140

4241
# Cursor highlighting function.
4342
_zsh_highlight_cursor_highlighter()
4443
{
45-
[[ $WIDGET == accept-* ]] && return
46-
44+
_zsh_highlight_is_accept_line_type_widget && return
45+
4746
region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]")
4847
}

highlighters/main/main-highlighter.zsh

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +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-* ]] ||
63+
# widgets which accept lines may trigger removal of path_prefix highlighting
64+
_zsh_highlight_is_accept_line_type_widget ||
6565
_zsh_highlight_buffer_modified
6666
}
6767

@@ -455,7 +455,7 @@ _zsh_highlight_main_highlighter_check_path()
455455

456456
# If this word ends the buffer, check if it's the prefix of a valid path.
457457
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] &&
458-
[[ $WIDGET != accept-* ]]; then
458+
! _zsh_highlight_is_accept_line_type_widget; then
459459
local -a tmp
460460
tmp=( ${expanded_path}*(N) )
461461
(( $#tmp > 0 )) && style_override=path_prefix && return 0

zsh-syntax-highlighting.zsh

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ fi
5353
# Array declaring active highlighters names.
5454
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
5555

56+
# Array declaring accept-style widget names.
57+
typeset -ga ZSH_HIGHLIGHT_ACCEPTING_WIDGETS
58+
5659
# Update ZLE buffer syntax highlighting.
5760
#
5861
# Invokes each highlighter that needs updating.
@@ -174,6 +177,14 @@ _zsh_highlight_cursor_moved()
174177
[[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
175178
}
176179

180+
# Whether the current widget is an accept-line type widget.
181+
#
182+
# Returns 0 if the the current widget is an accept-line type widget.
183+
_zsh_highlight_is_accept_line_type_widget()
184+
{
185+
[[ $WIDGET == ${~"${:-(${(j:|:)ZSH_HIGHLIGHT_ACCEPTING_WIDGETS})}"} ]]
186+
}
187+
177188

178189
# -------------------------------------------------------------------------------------------------
179190
# Setup functions
@@ -284,3 +295,6 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
284295

285296
# Initialize the array of active highlighters if needed.
286297
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true
298+
299+
# Initialize the array of accept-style widgets if needed.
300+
[[ $#ZSH_HIGHLIGHT_ACCEPTING_WIDGETS -eq 0 ]] && ZSH_HIGHLIGHT_ACCEPTING_WIDGETS=('accept-*' zle-isearch-exit) || true

0 commit comments

Comments
 (0)