Support literal newlines, part 2
This commit is contained in:
		
							parent
							
								
									52ece975c3
								
							
						
					
					
						commit
						c2b9327b07
					
				|  | @ -102,28 +102,24 @@ _zsh_highlight_main_highlighter() | ||||||
|     local substr_color=0 |     local substr_color=0 | ||||||
|     local style_override="" |     local style_override="" | ||||||
|     [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false |     [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false | ||||||
|     # advance $start_pos, skipping over whitespace in $buf. |  | ||||||
|     ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) |  | ||||||
|     ((end_pos=$start_pos+${#arg})) |  | ||||||
| 
 | 
 | ||||||
|     # Deal with faked colons. |     # advance $start_pos, skipping over whitespace in $buf. | ||||||
|     # |  | ||||||
|     # We can't use the (Z+n+) flag because that elides the end-of-command |  | ||||||
|     # token altogether, so 'echo foo\necho bar' (two commands) becomes |  | ||||||
|     # indistinguishable from 'echo foo echo bar' (one command with three |  | ||||||
|     # words for arguments). |  | ||||||
|     if [[ $arg == ';' ]] ; then |     if [[ $arg == ';' ]] ; then | ||||||
|       if [[ $buf[start_pos+1] == ';' ]] ; then |       # We're looking for either a semicolon or a newline, whichever comes | ||||||
|         # Literally-input colon. That's the normal case. |       # first.  Both of these are rendered as a ";" (SEPER) by the ${(z)..} | ||||||
|       elif [[ $buf[start_pos] == $'\n' ]] ; then |       # flag. | ||||||
|         # Newline token rendered as a colon.  Empirically we're off-by-one. |       # | ||||||
|         (( start_pos -= 1 )) |       # We can't use the (Z+n+) flag because that elides the end-of-command | ||||||
|         (( end_pos -= 1 )) |       # token altogether, so 'echo foo\necho bar' (two commands) becomes | ||||||
|       else |       # indistinguishable from 'echo foo echo bar' (one command with three | ||||||
|         # Currently, there aren't any other sources of ";" (SEPER) tokens |       # words for arguments). | ||||||
|         # besides literally-input semicolons and (Z+n+)-converted newlines, |       local needle=$'[;\n]' | ||||||
|         # If that ever changes, handle them here. |       integer offset=${${buf[start_pos+1,-1]}[(i)$needle]} | ||||||
|       fi |       (( start_pos += offset )) | ||||||
|  |       (( end_pos += offset )) | ||||||
|  |     else | ||||||
|  |       ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) | ||||||
|  |       ((end_pos=$start_pos+${#arg})) | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|     # Parse the sudo command line |     # Parse the sudo command line | ||||||
|  |  | ||||||
|  | @ -29,12 +29,12 @@ | ||||||
| # ------------------------------------------------------------------------------------------------- | # ------------------------------------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
| PREBUFFER=$'echo foo; echo bar\n\n\n' | PREBUFFER=$'echo foo; echo bar\n\n\n' | ||||||
| BUFFER='echo baz; echo qux' | BUFFER=' echo baz; echo qux' | ||||||
| 
 | 
 | ||||||
| expected_region_highlight=( | expected_region_highlight=( | ||||||
|   "0 4 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo |   "1 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo | ||||||
|   "5 7 $ZSH_HIGHLIGHT_STYLES[default]" # baz |   "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # baz | ||||||
|   "8 9 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon |   "9 10 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon | ||||||
|   "11 14 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo |   "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo | ||||||
|   "16 18 $ZSH_HIGHLIGHT_STYLES[default]" # qux |   "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux | ||||||
| ) | ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue