Commit Graph

20 Commits

Author SHA1 Message Date
Daniel Portales a98dd4abcf Fix region_highlight entries leaking across accept/edit cycles
Before this change, the highlight module tracked only the most recent
plugin-owned entry in a scalar (_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT) and
relied on a parameter-expansion subtraction to remove it:

    region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")

That has two failure modes:

1. The tracked string is expanded as a zsh glob pattern. If the user's
   ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE contains characters like `#`
   (e.g. `fg=#RRGGBB`), the entry is never removed and orphans
   accumulate in region_highlight across redraws. See #789.

2. Only one entry can be tracked at a time. When apply is called
   repeatedly without a successful reset (which happens under fast edits
   and widget-wrapping interactions), every apply overwrites the tracked
   reference and previous entries are orphaned.

Both manifest as stale suggestion colors bleeding onto accepted text,
typically in combination with zsh-syntax-highlighting (whose entries
interleave with ours in region_highlight).

Changes:

* Track every plugin-owned entry in an array
  (_ZSH_AUTOSUGGEST_OWNED_HIGHLIGHTS).

* On zsh 5.9+, tag each entry with `memo=zsh-autosuggestions` and on
  reset strip by memo in a single pass — robust regardless of how other
  plugins manipulate region_highlight. This matches the mechanism
  zsh-syntax-highlighting has used since 0.8.0.

* On zsh < 5.9, remove owned entries by literal string comparison
  (loop, not pattern expansion) to avoid the `#`-as-glob issue.

* _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT is retained and kept in sync for
  backwards compatibility with any external consumer.

Adds spec/highlight_spec.rb covering:
  - round-trip with a hex-colored style (regression for #789)
  - reset does not touch foreign region_highlight entries
  - accumulated orphans from repeated apply calls are all cleaned up

Supersedes #790 (which used `shift -p region_highlight` — incorrect
when another plugin has appended the most-recent entry).

Fixes #789, #698.
2026-04-20 07:52:36 -06:00
Eric Freese a50468ef4b Update changelog for v0.7.1 release 2024-11-15 12:35:58 -07:00
Eric Freese 74ba3739bb Update changelog for v0.7.0 release 2021-06-04 16:02:12 -06:00
Eric Freese 03f59df502 Update changelog for v0.6.4 release 2020-01-06 21:04:43 -07:00
Eric Freese 6769c941ba Update changelog for v0.6.3 release 2019-06-24 09:10:42 -06:00
Eric Freese 66a6de3fb5 Update changelog for v0.6.2 release 2019-06-22 16:52:42 -06:00
Eric Freese f178efb847 Update changelog for v0.6.1 release 2019-06-18 11:04:04 -06:00
Eric Freese 43ba841742 Update changelog for v0.6.0 release 2019-06-15 21:39:10 -06:00
Eric Freese 528e338e57 Update changelog for v0.5.2 release 2019-04-11 10:15:13 -06:00
Eric Freese 3ee91c731c Update changelog for v0.5.1 release 2019-04-03 10:51:48 -06:00
Eric Freese 0d994d4732 Update changelog for v0.5.0 release 2018-11-24 09:56:52 -07:00
Eric Freese b003b2238a Update changelog for v0.4.3 release 2018-05-21 10:46:03 -06:00
Eric Freese 15931f04ff v0.4.2 2017-12-06 08:30:12 -07:00
Eric Freese 9f9237ab8a v0.4.1 2017-11-28 10:07:49 -07:00
Eric Freese 29257230fe Add missing issue/pr numbers from last version 2017-11-28 10:07:49 -07:00
Eric Freese 281ed9bbf7 v0.4.0 changelog updates 2017-05-10 15:05:43 -06:00
Eric Freese 9333f0653f Update changelog for v0.3.3 2016-10-17 07:43:56 -06:00
Eric Freese 96eb0fae77 Changelog updates for v0.3.2 2016-05-28 08:18:52 -06:00
Eric Freese 87facd9b85 bump version v0.3.1 2016-03-14 22:33:26 -06:00
Eric Freese b54c8a15c6 Add changelog 2016-03-14 17:07:04 -06:00