tommcdo / vim-exchange

Easy text exchange operator for Vim
MIT License
756 stars 23 forks source link

Persist highlighting status when changing color schemes #54

Open jchros opened 3 years ago

jchros commented 3 years ago

Before #53, the highlighting of exchange regions was lost when the color scheme is changed, ignoring the user's preference; this bug was caused by the execution of :highlight clear at the beginning of the color scheme, losing the link between the internal _exchange_region highlight group and the ExchangeRegion group. #53 fixed this bug by defaulting the link, making it resilient to color scheme changes.

However, this fix introduced the opposite bug; when changing the color scheme, the highlighting of exchange regions is always enabled, regardless of the user's preference, and :XchangeHighlightToggle fails to disable it, as demonstrated in the video below:

https://user-images.githubusercontent.com/28897513/102714182-39c6f080-42cd-11eb-816a-00a68bc1f4ef.mov

In this pull request, these issues are fixed by adding an autocmd restoring the link between _exchange_region and ExchangeRegion every time the color scheme changes if the highlighting is enabled.

The changes introduced in #53 are reverted, since they conflict with those introduced by this fix.

A follow-up on #52.

Alternatives considered

Toggle highlighting twice

While simpler than the changes introduced in this pull request, I rejected this approach because it feels like a hack to me.

Keep existing behavior, but set s:enable_highlighting to a true value

I rejected this approach since it does not honor the user's preference.