Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buggy screen refresh in gVim with a Netrw window #8820

Closed
gdupras opened this issue Aug 30, 2021 · 21 comments
Closed

Buggy screen refresh in gVim with a Netrw window #8820

gdupras opened this issue Aug 30, 2021 · 21 comments

Comments

@gdupras
Copy link

gdupras commented Aug 30, 2021

Describe the bug
In gVim, when a Netrw window is visible and the screen is refreshed, either
automatically or by doing CTRL-L, gVim twitches and can even change size.

To Reproduce

  1. gvim --clean
  2. :source $VIMRUNTIME/plugin/netrwPlugin.vim
  3. :Sexplore
  4. Do CTRL-L and note how gVim twitches. Elements of the GUI quickly
    disappear and reappear.
  5. :set guioptions=egL
  6. Do CTRL-L several times and note how the gVim window becomes narrower.

Expected behavior
No twitching when the screen is refreshed. gVim window should not change size.

Screenshots
https://user-images.githubusercontent.com/57042631/131352404-440db7f7-4269-4a74-8637-7629371f0e47.mp4

Environment (please complete the following information):

  • Vim 8.2.3386
  • OS: Windows 10
  • Terminal: GUI

Additional context
This bug does not affect Vim 8.2.3384. It also does not affect Vim run in a
terminal.

@gdupras
Copy link
Author

gdupras commented Sep 1, 2021

This bug also affects gVim 8.2.3386 GTK3 on Kubuntu 21.04.

@chrisbra
Copy link
Member

chrisbra commented Sep 1, 2021

Just a guess, but does :set guioptions+=k help?

@gdupras
Copy link
Author

gdupras commented Sep 1, 2021

It does not. With :set guioptions=egLk, I still see the tool bar and the menu bar flicker. The gVim window still gets narrower when the screen is refreshed.

@c64cosmin
Copy link

I ran in the same problem, did a git bisect to find the culprit
89a9c15 is the first bad commit.

The way I found out is described below, if this is not related, please let me know to open a new issue.

When I use :Ex the gVim windows flashes the toolbar and gets narrower by one character.
I also use https://www.vim.org/scripts/script.php?script_id=2596 in order to have F11 mapped to full screen(remove the border&titlebar). When I use F11, columns and lines are set to a big value, using :Ex in fullscreen will make gvim.exe run heavily for a minute (full CPU) before it displays the contents of directory.

I also use this script

function ToggleExplorer()
    if &ft == "netrw"
        if exists("w:netrw_rexfile")
            if w:netrw_rexfile == "" || w:netrw_rexfile == "NetrwTreeListing"
                exec 'q'
            else
                exec 'e ' . w:netrw_rexfile
            endif
        else
            if exists("w:netrw_rexlocal")
                Rexplore
            else
                exec 'q'
            endif
        endif
    else
        Explore
    endif
endfun

I use this to open/close the Explorer, with the bug above the script won't work correctly.
The expected result is that calling this function will open explorer, calling it again inside an explorer will close it, or close vim is that is the only buffer.
With the bug, explorer opens, gets narrower, calling the function again will just make the editor narrower.

Also using gvim in Windows 10, compiled using MSVC.

@gdupras
Copy link
Author

gdupras commented Sep 2, 2021

Removing these two lines solved the problem for me:

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index 5ea8319cf..252d664d6 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -1680,7 +1680,6 @@ fun! s:NetrwOptionsSave(vt)
   endif
   let {a:vt}netrw_fokeep    = &l:fo           " formatoptions
   let {a:vt}netrw_gdkeep    = &l:gd           " gdefault
-  let {a:vt}netrw_gokeep    = &l:go           " guioptions
   let {a:vt}netrw_hidkeep   = &l:hidden
   let {a:vt}netrw_imkeep    = &l:im
   let {a:vt}netrw_iskkeep   = &l:isk
@@ -1832,7 +1831,6 @@ fun! s:NetrwOptionsRestore(vt)
 "  call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
   call s:NetrwRestoreSetting(a:vt."netrw_fokeep"   ,"&l:fo")
   call s:NetrwRestoreSetting(a:vt."netrw_gdkeep"   ,"&l:gd")
-  call s:NetrwRestoreSetting(a:vt."netrw_gokeep"   ,"&l:go")
   call s:NetrwRestoreSetting(a:vt."netrw_hidkeep"  ,"&l:hidden")
 "  call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
   call s:NetrwRestoreSetting(a:vt."netrw_imkeep"   ,"&l:im")

These two lines were added recently, it 89a9c15. I don't know if this is the right solution though.

@k-takata
Copy link
Member

k-takata commented Sep 2, 2021

Cc @cecamp

@gdupras
Copy link
Author

gdupras commented Sep 2, 2021

Probably has something to do with

call s:NetrwSetSafeSetting("&go","begmr")

and this

vim/runtime/doc/pi_netrw.txt

Lines 3919 to 3920 in 04626c2

* Installed option bypass for |'guioptions'|
a/A settings

These lines were also added in 89a9c15.

@chrisbra
Copy link
Member

chrisbra commented Sep 2, 2021

Can you throw in a k into the NetrwSetSafeSetting call?

@c64cosmin
Copy link

Removing the

call s:NetrwSetSafeSetting("&go","begmr")

Does solve the issue on my side.
I am using
guioptions=!c

@brammool
Copy link
Contributor

brammool commented Sep 2, 2021 via email

@chrisbra
Copy link
Member

chrisbra commented Sep 2, 2021

I would guess it's the clipboard handling (e.g. the a and A flags).

@cecamp
Copy link
Collaborator

cecamp commented Sep 3, 2021

Let me know if v172a helps.

@gdupras
Copy link
Author

gdupras commented Sep 4, 2021

I've tried v172a but it does not fix this bug.

I've never installed a new version of Netrw before so I'm not entirely sure I did this correctly. I downloaded the netrw.vba.gz file, opened the file in Vim and did :so %. This installed the files in my vimfiles directory (I'm on Windows). I then opened a new instance of gVim, did :Se and the banner displays v172a. So I'm assuming I did install it correctly.

@gdupras
Copy link
Author

gdupras commented Sep 5, 2021

How about this patch, on top of v172a?

diff --git a/autoload/netrw.vim b/autoload/netrw.vim
index 81f89fc..7ce66d9 100644
--- a/autoload/netrw.vim
+++ b/autoload/netrw.vim
@@ -1751,7 +1751,7 @@ fun! s:NetrwOptionsSafe(islocal)
   if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
   if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
   setl fo=nroql2
-  call s:NetrwSetSafeSetting("&go","egmr")
+  if &go =~ '\ca' | call s:NetrwSetSafeSetting("&go",substitute(&go,'\ca','','g')) | endif
   call s:NetrwSetSafeSetting("&l:hid",0)
   call s:NetrwSetSafeSetting("&l:im",0)
   setl isk+=@ isk+=* isk+=/

@c64cosmin
Copy link

@gdupras Hello, thank you so much for your reply, the change above does solve my issue on my side.
Adding the other line of code
if &go =~ '\ca' | call s:NetrwSetSafeSetting("&go",substitute(&go,'\ca','','g')) | endif
won't add unexpected behavior in my GUI

@c64cosmin
Copy link

The fix above also removes flashing of the menu bar in gVim on GNOME too.

@brammool
Copy link
Contributor

brammool commented Oct 3, 2021

I'll tentatively include this, I don't know when @cecamp will send a new version.

@brammool brammool closed this as completed Oct 3, 2021
@cecamp
Copy link
Collaborator

cecamp commented Oct 3, 2021

I believe that netrw v172c already has this issue fixed. You may get it from my website: http://www.drchip.org/astronaut/vim/index.html

@zmajeed
Copy link

zmajeed commented Oct 27, 2021

I tried v172c in the latest vim 8.2 on Windows 10 - it has other bugs - :E in one window affects all windows across all tabs of the same file - say I have file1.c open in 3 windows in one tab and 2 windows in another tab - :E in any of these 5 windows opens the file explorer in all 5 windows and selecting file2.c replaces file1.c in all 5 windows with file2.c

Managed to revert to netrw v171e from https://github.com/eiginn/netrw - much thanks to @eiginn for this lifesaver! It not only eliminates the new bug but also does not exhibit the original issue of :E making the vim window flicker and narrow its size as well as mess up the sizes of the windows inside vim

@gdupras
Copy link
Author

gdupras commented Oct 27, 2021

Yes, I also had this issue with v172c. The current version of Vim (8.2.3565) has netrw v171 with the patch I suggested above. It has none of these issues (no flickering, no narrowing, no duplicated explorer window).

@zmajeed
Copy link

zmajeed commented Oct 27, 2021

Thanks for listing the vim version with your patch - I had looked at https://github.com/vim/vim-win32-installer/releases and did not see netrw mentioned in any recent build - then found eignn's repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants