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 (#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
  • Loading branch information
nreese authored Aug 25, 2017
1 parent 854f795 commit 9d304cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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 @@ 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)
Expand Down
14 changes: 12 additions & 2 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';

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;
}

0 comments on commit 9d304cd

Please sign in to comment.