From ad760fec6c20383b9fd75495ffb5b4f600b3d82b Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 25 Aug 2017 12:32:24 -0600 Subject: [PATCH] Keep current cursor or top line in view when resizing Console to avoid losing user context (#13695) * keep current cursor or top line in view when resizing to avoid losing user context * rename variable to more descriptive name * move state from editor to smart_resize --- .../console/public/src/input_resize.js | 2 ++ .../console/public/src/smart_resize.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/core_plugins/console/public/src/input_resize.js b/src/core_plugins/console/public/src/input_resize.js index 237ff81039e763..f11e59c37d077e 100644 --- a/src/core_plugins/console/public/src/input_resize.js +++ b/src/core_plugins/console/public/src/input_resize.js @@ -24,6 +24,8 @@ module.exports = function (input, output) { $resizer.addClass('active'); var startWidth = $left.width(); var startX = event.pageX; + input.resize.topRow = input.renderer.layerConfig.firstRow; + output.resize.topRow = output.renderer.layerConfig.firstRow; function onMove(event) { setEditorWidth(startWidth + event.pageX - startX) diff --git a/src/core_plugins/console/public/src/smart_resize.js b/src/core_plugins/console/public/src/smart_resize.js index 5f943d1579e140..49724cb9a5f8a6 100644 --- a/src/core_plugins/console/public/src/smart_resize.js +++ b/src/core_plugins/console/public/src/smart_resize.js @@ -1,6 +1,16 @@ -import { throttle } from 'lodash'; +import { get, throttle } from 'lodash'; module.exports = function (editor) { const resize = editor.resize; - return throttle(() => resize.call(editor), 35) -}; + const throttledResize = throttle(() => { + + resize.call(editor); + + // Keep current top line in view when resizing to avoid losing user context + let userRow = get(throttledResize, 'topRow', 0); + if (userRow !== 0) { + editor.renderer.scrollToLine(userRow, false, false, () => {}); + } + }, 35); + return throttledResize; +}