lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

Suggestion to not auto-resize Fern if it's already toggled open and you resized it manually #309

Closed nickjj closed 3 years ago

nickjj commented 3 years ago

Hi,

I typically open fern with noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR><C-w>=

Steps to reproduce potential issue:

  1. Toggle fern open using the above mapping
  2. It will open at its correct size (working as intended)
  3. You manually resize fern by making it bigger or smaller
  4. You click into a code buffer that isn't fern
  5. You click back into fern

At this point fern will revert the customize size you manually dragged fern to and resize it based on your mapping.

This is problematic for me as someone who creates video recorded content. I often find myself wanting to make fern a little bit wider so I can see the full file name (this changes based on the length of file name), but every time I click back into the code and then back into fern, fern snaps to its original size and then I need to manually make it wider again. I had to do this manual resize "fix" about 10 times in a 5 minute video while jumping between files and explaining stuff.

Would it be possible to write a rule that says "if fern is already open and visible, do not adjust the size to the configured -width, instead leave it at whatever width it's currently at". And if fern is closed and toggling to be opened it would work as it does now and correctly open at your configured -width.

lambdalisue commented 3 years ago

Not sure if it's help but you may want to disable that feature by https://github.com/lambdalisue/fern.vim/blob/master/doc/fern.txt#L432

I'll read it more carefully later but it seems difficult to determine if the size change is caused by user or unexpected buffer relocation.

Additionally, for your case, there are two useful actions

nickjj commented 3 years ago

If I set let g:fern#disable_drawer_auto_resize = 1 then this happens (step 6 is different):

  1. Toggle fern open using the mapping in the original issue
  2. It will open at its correct size (working as intended)
  3. You manually resize fern by making it bigger or smaller
  4. You click into a code buffer that isn't fern
  5. You click back into fern
  6. Fern resizes itself to be 50% of the size of the entire Vim window and even if you resize it again, it always goes back to 50%
lambdalisue commented 3 years ago

Fern resizes itself to be 50% of the size of the entire Vim window and even if you resize it again, it always goes back to 50%

That's probably different issue and it sounds like <C-w>= is automatically fired in somewhere?

Please make a new issue with a minimal vimrc and procedure if you feel that behavior is caused by fern itself.

nickjj commented 3 years ago

That's probably different issue and it sounds like <C-w>= is automatically fired in somewhere?

I removed that and it's still the same issue where it snaps to 50% of the size.

nickjj commented 3 years ago

I'll be completely honest with you. I really like Fern and have been using it for ~6 months and you've gone above and beyond in a lot of cases to fix bugs, add features and I'm grateful for that but this resize issue is killing me.

It's very disruptive when creating video tutorials and giving talks because if I have Fern open and I'm switching between 2 files while talking about the code in real time I have to constantly resize Fern every time I switch between 2 files in order to make sure the full file name is visible (since I would drag it a little wider manually to see it). It causes a lot of stress when giving live talks and in some cases has ruined a number of videos where I had to go back and re-do them.

Any help on how to fix / resolve this would be much appreciated.

lambdalisue commented 3 years ago

I could not reproduce https://github.com/lambdalisue/fern.vim/issues/309#issuecomment-791923964

Please make a minimal vimrc and minimal descriptive steps to reproduce. Visit the above link and follow the instruction there.


What I did is

" Disable Vim's native pack feature
set packpath=

" Clone https://github.com/lambdalisue/fern.vim in somewhere
" and specify that directory to the below
set runtimepath^=~/ghq/github.com/lambdalisue/fern.vim

filetype plugin indent on
syntax on
"----------------------------------------------------------------

" Add extra settings here to reproduce the issue...
let g:fern#disable_drawer_auto_resize = 1

"----------------------------------------------------------------
echomsg "Custom minimal vimrc has loaded"

Then

  1. nvim -u ~/vimrc.min
  2. Execute :Fern . -drawer -reveal=% -toggle -width=35
  3. Resize window by :vertical resize 100
  4. Change window by <C-w>l
  5. Back window by <C-w>h

https://user-images.githubusercontent.com/546312/116719249-d20c7900-aa15-11eb-8a8c-3b939770f549.mp4

nickjj commented 3 years ago

Your steps are different than mine because you're not toggling Fern on and off.

Try these steps (altering your steps):

  1. nvim -u ~/vimrc.min
  2. Execute :Fern . -drawer -reveal=% -toggle -width=35
  3. Resize window by :vertical resize 100
  4. Execute :Fern . -drawer -reveal=% -toggle -width=35 (this will close Fern)
  5. Execute :Fern . -drawer -reveal=% -toggle -width=35 (this will open Fern at 50% width instead of step 3's size)

The issue is step 5 should not resize the window to 50%. It should continue using the custom width defined by step 3.

lambdalisue commented 3 years ago

Now, finally, I got the situation. Please remember that steps with actual commands like what you've given me last are quite important for understanding the situation...

Well, it's a kind feature of g:fern#disable_drawer_auto_resize while the buffer is closed so we need a new feature for that. I'll think about it.

lambdalisue commented 3 years ago

@nickjj https://github.com/lambdalisue/fern.vim/pull/332 Please give me feedback on that PR.

nickjj commented 3 years ago

Which combination of options should I use? When I set both options to 1 it still snaps to 50% width in the repeatable steps.

lambdalisue commented 3 years ago

@nickjj

Which combination of options should I use? When I set both options to 1 it still snaps to 50% width in the repeatable steps.

You should not use g:fern#disable_drawer_auto_resize. The original behavior has changed. Anyway, please try #333 instead which also changed the default behavior.

nickjj commented 3 years ago

With #333 f I remove those 2 settings and:

Then fern will reset its width to my configured 35 width instead of 50% this time. This is still an issue. But your repeatable steps without <CR> seems to work.

lambdalisue commented 3 years ago

I'm sorry but I cannot reproduce the issue with that information. I need to reproduce the issue on my environment to fix that issue.

I like the idea and I'd love to help your situation so please create a minimal vimrc and write minimal and descriptive procedure like what you gave me yesterday so that I can reproduce the issue.

nickjj commented 3 years ago

Those steps are how I'm able to reproduce the issue with Vim 8.1 btw. The only difference now is instead of running the command directly, it's bound to a key with <CR> with noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR> and instead of running the resize command directly you move and select files with the mouse.

lambdalisue commented 3 years ago

I'm sorry but I'm lost so

  1. Please write a minimal vimrc on a comment
  2. Please write a minimal descriptive procedure on a comment

I am expecting that your comment will look like


vimrc

" Disable Vim's native pack feature
set packpath=

" Clone https://github.com/lambdalisue/fern.vim in somewhere
" and specify that directory to the below
set runtimepath^=~/ghq/github.com/lambdalisue/fern.vim

filetype plugin indent on
syntax on
"----------------------------------------------------------------

" Add extra settings here to reproduce the issue...

"----------------------------------------------------------------
echomsg "Custom minimal vimrc has loaded"

procedure

  1. nvim -u ~/vimrc.min
  2. Execute :Fern . -drawer -reveal=% -toggle -width=35
  3. Resize window by :vertical resize 100
  4. Execute :Fern . -drawer -reveal=% -toggle -width=35 (this will close Fern)
  5. Execute :Fern . -drawer -reveal=% -toggle -width=35 (this will open Fern at 50% width instead of step 3's size)

Please copy & paste instead of referring even if something has not changed to make things clear.

lambdalisue commented 3 years ago

@nickjj I merged #333 so please create a new issue with minimal vimrc and procedure when you still have some issues.

nickjj commented 3 years ago

Thanks, I'll try it again but when I did before I was able to reproduce the issue once in a while with #333, but not always. I wonder if it's due to some combo of clicking, dragging and focusing windows that makes it reset the width.