scroll position gets reset
Closed this issue · 2 comments
Every time I save my changes to my files the browser window refreshes and my scroll position goes back to the top.
I don't understand much about Browsersync but maybe there's some particular flag which can be set so that it injects changes instead of reloading the site?
This doesn't happen with the live-server npm package, have you considered using that instead? It seems to be a simpler solution. It hasn't been updated in 2 years but there's an apparently active fork:
https://github.com/ljcp/alive-server
Yes, that's a bit annoying. I couldn't find something in the browser-sync docs.
Also, yes I've considered refactoring this plugin to use live-server instead, or I might add live-server support while keeping browser-sync.
For now, you can add this (which I've been using for a couple of weeks to test live-server) to the plugin script and use live-server from NPM:
function! StartLiveServer()
let cmd = "live-server &"
call system(cmd)
echo "Live server started in the background."
endfunction
command! StartLiveServer call StartLiveServer()
As well as this to kill live-server on VimLeave:
function! KillAllLiveServerInstances()
let cmd = "pkill -f 'live-server'"
call system(cmd)
endfunction
augroup LiveServerKill
autocmd!
autocmd VimLeave * call KillAllLiveServerInstances()
augroup END
I'll have to do a bit more testing to make my final decision to move to live-server entirely or not.
live-server support has been fully added to the plugin.