Fixed editor scrolling behavior

This commit is contained in:
benweet 2014-08-11 00:44:54 +01:00
parent cd89897580
commit ea234a7c1b
2 changed files with 7 additions and 8 deletions

View File

@ -114,6 +114,7 @@ define([
function SelectionMgr() { function SelectionMgr() {
var self = this; var self = this;
var lastSelectionStart = 0, lastSelectionEnd = 0;
this.selectionStart = 0; this.selectionStart = 0;
this.selectionEnd = 0; this.selectionEnd = 0;
this.cursorY = 0; this.cursorY = 0;
@ -216,6 +217,10 @@ define([
selection.removeAllRanges(); selection.removeAllRanges();
selection.addRange(range, this.selectionStart > this.selectionEnd); selection.addRange(range, this.selectionStart > this.selectionEnd);
}; };
var saveLastSelection = _.debounce(function() {
lastSelectionStart = self.selectionStart;
lastSelectionEnd = self.selectionEnd;
}, 50);
this.setSelectionStartEnd = function(start, end) { this.setSelectionStartEnd = function(start, end) {
if(start === undefined) { if(start === undefined) {
start = this.selectionStart; start = this.selectionStart;
@ -233,6 +238,7 @@ define([
this.selectionEnd = end; this.selectionEnd = end;
fileDesc.editorStart = start; fileDesc.editorStart = start;
fileDesc.editorEnd = end; fileDesc.editorEnd = end;
saveLastSelection();
}; };
this.saveSelectionState = (function() { this.saveSelectionState = (function() {
function save() { function save() {
@ -273,11 +279,6 @@ define([
} }
var nextTickAdjustScroll = false; var nextTickAdjustScroll = false;
var lastSelectionStart, lastSelectionEnd;
var saveLastSelection = _.debounce(function() {
lastSelectionStart = self.selectionStart;
lastSelectionEnd = self.selectionEnd;
}, 50);
var debouncedSave = utils.debounce(function() { var debouncedSave = utils.debounce(function() {
save(); save();
if(lastSelectionStart == self.selectionStart && lastSelectionEnd == self.selectionEnd) { if(lastSelectionStart == self.selectionStart && lastSelectionEnd == self.selectionEnd) {
@ -295,7 +296,6 @@ define([
else { else {
save(); save();
} }
saveLastSelection();
}; };
})(); })();
this.getSelectedText = function() { this.getSelectedText = function() {
@ -787,6 +787,7 @@ define([
} }
inputElt.focus = focus; inputElt.focus = focus;
inputElt.adjustCursorPosition = adjustCursorPosition;
Object.defineProperty(inputElt, 'value', { Object.defineProperty(inputElt, 'value', {
get: function() { get: function() {

View File

@ -228,8 +228,6 @@ define([
comments.onEditorPopover = function() { comments.onEditorPopover = function() {
closeCurrentPopover(); closeCurrentPopover();
editor.focus();
editor.adjustCursorPosition();
}; };
comments.onDiscussionCreated = function(fileDesc) { comments.onDiscussionCreated = function(fileDesc) {