zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
19.55k stars 1.32k forks source link

Lose highlighted substring? #872

Closed tmpm697 closed 1 year ago

tmpm697 commented 2 years ago

I'm using this plugin and this but with latest update from master, substring search is not highlight all of its portion.

i.g: for i in -- this is substring to search through history, but only i in is highlighted and it will blinking on for part.

This issue happens recently and I did test with latest tag 0.8.0-alpha1-pre-redrawhook and it worked.

danielshahaf commented 2 years ago

I'm using this plugin and this but with latest update from master, substring search is not highlight all of its portion.

i.g: for i in -- this is substring to search through history, but only i in is highlighted.

This issue happens recently and I did test with latest tag 0.8.0-alpha1-pre-redrawhook and it worked.

What changed recently?

What are the values of $ZSH_VERSION and $ZSH_HIGHLIGHT_REVISION and the revision of zsh-history-substring-search when the problem occurs?

Can yoiu bisect z-sy-h, keeping the versions of zsh and z-h-s-s constant? (It might well be the commit on master that's immediately after the tag; that tag wasn't a release but a marker of the point just before a topic branch merge.)

Can you reproduce the problem under 'zsh -f' after manually sourcing just those two plugins (by running the 'source' builtin at the prompt twice)?

Can you post more detailed reproduction steps? Assume no knowledge of third-party plugins.

tmpm697 commented 2 years ago

This is steps:

1. zsh -df
2. source zsh-history-substring-search.zsh
3. source zsh-syntax-highlighting.zsh
4. source zsh-autosuggestions.zsh
5. 
zle -N history-substring-search-up
zle -N history-substring-search-down
zle -N autosuggest-accept
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
<enter>
> for i in $(seq 1 10);d do ; done
> for i in<multiple ctrl-p here to match previous typed above command>
6. observer `for` is blinking

setup:

substring: 4abed97
highlighting: caa749d
auto suggestion: a411ef3
danielshahaf commented 2 years ago

The steps need an explicit bindkey -e since the default keymap isn't always emacs.

I tried following your steps and I can reproduce a problem, but not the same one as you.

What I see is:

The dumped $region_highlight entries lack a memo=zsh-syntax-highlighting annotation, whereas all other entries have those.

Which plugin would mark the first six characters as bold white-on-red or bold white-on-magenta?

The above is with zsh 5.9 and the same versions as you:

% for 1 in */ ; printf "%s\t%s\n" $(cd $1 && git rev-parse HEAD) $1:t 
a411ef3e0992d4839f0732ebeb9823024afaaaa8        zsh-autosuggestions
4abed97b6e67eb5590b39bcd59080aa23192f25d        zsh-history-substring-search
caa749d030d22168445c4cb97befd406d2828db0        zsh-syntax-highlighting
danielshahaf commented 2 years ago

By the way, zsh-history-substring-search overrides and reimplements some zsh-syntax-highlighting implementation details:

https://github.com/zsh-users/zsh-history-substring-search/blob/4abed97b6e67eb5590b39bcd59080aa23192f25d/zsh-history-substring-search.zsh#L102-L195

That's not supported. It falls under "If it breaks, you get to keep both pieces.". zsh-history-substring-search needs to stop doing that.

I don't know whether that does or doesn't cause this issue (#872).

tmpm697 commented 1 year ago

But why use syntax-highlight tag 0.8.0-alpha1-pre-redrawhook works? this is what should look like:

but master branch gives:

danielshahaf commented 1 year ago

I don't know. You're welcome to bisect this, of course, but my previous comment in this issue stands: your configuration is unsupported. No one should be defining functions named _zsh_highlight* except z-sy-h itself and authors of third-party highlighters conforming to z-sy-h's API; however, your configuration uses plugins that do exactly this.

tmpm697 commented 1 year ago

So use z-sy-h with z-h-s-s is not supported due to override _zsh_highlight function?. It's plugins, not configuration. I'd stay with 0.8.0 for a while, thanks for clarifying.

danielshahaf commented 1 year ago

You can try to upgrade but manually disable the new codepath. (The old codepath is still there for compatibility with older versions of zsh.) Other than that, that's right, use of plugins that redefine z-sy-h's internal functions is unsupported.

danielshahaf commented 1 year ago

Looks like someone PR'd this on the z-h-s-s side, https://github.com/zsh-users/zsh-history-substring-search/pull/135.