From 9d304cd8b220e935df71683437f126d6742a6ac1 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 25 Aug 2017 14:50:08 -0600 Subject: [PATCH] Keep current cursor or top line in view when resizing Console to avoid losing user context (#13695) (#13712) * 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 | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core_plugins/console/public/src/input_resize.js b/src/core_plugins/console/public/src/input_resize.js index 7ef2a9b004abb7..642a96103b6a3a 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 @@ export default 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 0e52ce06080e53..611db5f4df00a8 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'; export default 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; }