Don't highlight syntax elements as paths.
Without this, redirections, history expansions, and command separators would be matched by path_approx. A test case is simply LBUFFER="<" RBUFFER="" (highlighted as redirection with this fix and as path_approx without it). Fixes zsh-users/zsh-syntax-highlighting#204.
This commit is contained in:
		
							parent
							
								
									4ec821b2b1
								
							
						
					
					
						commit
						79e8c2dd48
					
				|  | @ -178,15 +178,17 @@ _zsh_highlight_main_highlighter() | ||||||
|                             # (For array assignments, the command doesn't start until the ")" token.) |                             # (For array assignments, the command doesn't start until the ")" token.) | ||||||
|                             new_expression=true; highlight_glob=true |                             new_expression=true; highlight_glob=true | ||||||
|                           fi |                           fi | ||||||
|                         elif _zsh_highlight_main_highlighter_check_path; then |  | ||||||
|                           style=$ZSH_HIGHLIGHT_STYLES[path] |  | ||||||
|                         elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then |                         elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then | ||||||
|                           style=$ZSH_HIGHLIGHT_STYLES[history-expansion] |                           style=$ZSH_HIGHLIGHT_STYLES[history-expansion] | ||||||
|                         elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then |                         elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then | ||||||
|                           style=$ZSH_HIGHLIGHT_STYLES[redirection] |                           style=$ZSH_HIGHLIGHT_STYLES[redirection] | ||||||
|                           redirection=true |                           redirection=true | ||||||
|                         else |                         else | ||||||
|                           style=$ZSH_HIGHLIGHT_STYLES[unknown-token] |                           if _zsh_highlight_main_highlighter_check_path; then | ||||||
|  |                             style=$ZSH_HIGHLIGHT_STYLES[path] | ||||||
|  |                           else | ||||||
|  |                             style=$ZSH_HIGHLIGHT_STYLES[unknown-token] | ||||||
|  |                           fi | ||||||
|                         fi |                         fi | ||||||
|                         ;; |                         ;; | ||||||
|       esac |       esac | ||||||
|  | @ -212,8 +214,7 @@ _zsh_highlight_main_highlighter() | ||||||
|                  ;; |                  ;; | ||||||
|         '`'*)    style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; |         '`'*)    style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; | ||||||
|         *[*?]*)  $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; |         *[*?]*)  $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; | ||||||
|         *)       if _zsh_highlight_main_highlighter_check_path; then |         *)       if false; then | ||||||
|                    style=$ZSH_HIGHLIGHT_STYLES[path] |  | ||||||
|                  elif [[ $arg[0,1] = $histchars[0,1] ]]; then |                  elif [[ $arg[0,1] = $histchars[0,1] ]]; then | ||||||
|                    style=$ZSH_HIGHLIGHT_STYLES[history-expansion] |                    style=$ZSH_HIGHLIGHT_STYLES[history-expansion] | ||||||
|                  elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then |                  elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then | ||||||
|  | @ -221,7 +222,11 @@ _zsh_highlight_main_highlighter() | ||||||
|                  elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then |                  elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then | ||||||
|                    style=$ZSH_HIGHLIGHT_STYLES[redirection] |                    style=$ZSH_HIGHLIGHT_STYLES[redirection] | ||||||
|                  else |                  else | ||||||
|                    style=$ZSH_HIGHLIGHT_STYLES[default] |                    if _zsh_highlight_main_highlighter_check_path; then | ||||||
|  |                      style=$ZSH_HIGHLIGHT_STYLES[path] | ||||||
|  |                    else | ||||||
|  |                      style=$ZSH_HIGHLIGHT_STYLES[default] | ||||||
|  |                    fi | ||||||
|                  fi |                  fi | ||||||
|                  ;; |                  ;; | ||||||
|       esac |       esac | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue