Skip to content

Commit

Permalink
Keep current cursor or top line in view when resizing Console to avoi…
Browse files Browse the repository at this point in the history
…d losing user context (elastic#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
  • Loading branch information
nreese committed Aug 25, 2017
1 parent 889fbe9 commit ad760fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/core_plugins/console/public/src/input_resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions src/core_plugins/console/public/src/smart_resize.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ad760fe

Please sign in to comment.