markonm / traces.vim

Range, pattern and substitute preview for Vim
MIT License
742 stars 13 forks source link

Minimized splits would open themselves after using traces.vim #19

Closed ychin closed 6 years ago

ychin commented 6 years ago

Repro

I have found that whenever using traces, a split window that's currently "minimized" (i.e. having 0 height) would open themselves after the highlight (e.g. :%s/foo/bar). A simple repro below after opening a new Vim instance with a fresh .vimrc:

:set winminheight=0
:split
<C-W>_
:%s/foo/bar

The fourth line would trigger traces' highlight code, and expand the first window which has been minimized.

Ideas

Digging through the code, it seems like the issue comes from the spurrious win_gotoid() calls from s:highlight() and traces#cmdl_leave(). Each time the script enter a new window via win_gotoid, if winheight is larger than winminheight, the window will get expanded causing this bug.

It seems to me a simple way to fix this is to not visit the other windows, maybe through a setting called g:traces_only_current_window=1 that will only update the current window instead of the other ones too. Also the following lines may have to be re-thought as well:

if bufname('%') !=# '[Command Line]'
  noautocmd call win_gotoid(alt_win)
  noautocmd call win_gotoid(cur_win)
endif

Other option may be to make sure to restore the proper heights of each window. That seems more error prone to me but it would allow us to keep the existing functionality of updating multiple windows.

markonm commented 6 years ago

Thanks for reporting the issue. I pushed a commit, please test. https://github.com/markonm/traces.vim/commit/e27b2a515989282122bd24eae8e16b05dbe9265e

ychin commented 6 years ago

I tested the commit (e27b2a5) and didn't see any issues! Thanks for fixing.