From 32f0f4bd7a463ddc12dacf14b71552963875bd6a Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 1 Feb 2018 23:51:30 +0300 Subject: [PATCH] preserve page scroll position after [de]beautification --- edit/beautify.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/edit/beautify.js b/edit/beautify.js index cf86d86b..d667ecdf 100644 --- a/edit/beautify.js +++ b/edit/beautify.js @@ -46,8 +46,10 @@ function beautify(event) { scope.forEach(cm => { if (cm.beautifyChange && cm.beautifyChange[cm.changeGeneration()]) { delete cm.beautifyChange[cm.changeGeneration()]; + const {scrollX, scrollY} = window; cm.undo(); cm.scrollIntoView(cm.getCursor()); + window.scrollTo(scrollX, scrollY); undoable |= cm.beautifyChange[cm.changeGeneration()]; } }); @@ -71,7 +73,9 @@ function beautify(event) { for (let i = 0; i < pos.length; i += 2) { selections.push({anchor: pos[i], head: pos[i + 1]}); } + const {scrollX, scrollY} = window; cm.setSelections(selections); + window.scrollTo(scrollX, scrollY); cm.beautifyChange[cm.changeGeneration()] = true; undoButton.disabled = false; }