Keep current cursor or top line in view when resizing Console to avoid losing user context (#13695) (#13710)

* 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
This commit is contained in:
Nathan Reese 2017-08-25 14:49:44 -06:00 committed by GitHub
parent 889fbe92a8
commit 6436a1f566
2 changed files with 15 additions and 3 deletions

View file

@ -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)

View file

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