Skip to content

Commit

Permalink
remove autoScroll and $blockScrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Oct 28, 2017
1 parent 485cd35 commit bde5b19
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 62 deletions.
2 changes: 0 additions & 2 deletions lib/ace/autocomplete/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ var AcePopup = function(parentNode) {
return this.screenWidth = 0;
};

popup.$blockScrolling = Infinity;

// public
popup.isOpen = false;
popup.isTopdown = false;
Expand Down
5 changes: 3 additions & 2 deletions lib/ace/commands/default_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ exports.commands = [{
}, {
name: "gotoline",
bindKey: bindKey("Ctrl-L", "Command-L"),
exec: function(editor) {
var line = parseInt(prompt("Enter line number:"), 10);
exec: function(editor, line) {
if (typeof line !== "number")
line = parseInt(prompt("Enter line number:"), 10);
if (!isNaN(line)) {
editor.gotoLine(line);
}
Expand Down
30 changes: 0 additions & 30 deletions lib/ace/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ var Editor = function(renderer, session) {

this.keyBinding = new KeyBinding(this);

this.$blockScrolling = 0;
this.$search = new Search().set({
wrap: true
});
Expand Down Expand Up @@ -155,8 +154,6 @@ Editor.$uid = 0;
args: commadEvent.args,
scrollTop: this.renderer.scrollTop
};
if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined)
this.$blockScrolling++;
};

this.endOperation = function(e) {
Expand All @@ -165,8 +162,6 @@ Editor.$uid = 0;
return this.curOp = null;
this._signal("beforeEndOperation");
var command = this.curOp.command;
if (command.name && this.$blockScrolling > 0)
this.$blockScrolling--;
var scrollIntoView = command && command.scrollIntoView;
if (scrollIntoView) {
switch (scrollIntoView) {
Expand Down Expand Up @@ -363,9 +358,7 @@ Editor.$uid = 0;

this.onChangeMode();

this.$blockScrolling += 1;
this.onCursorChange();
this.$blockScrolling -= 1;

this.onScrollTopChange();
this.onScrollLeftChange();
Expand Down Expand Up @@ -735,14 +728,6 @@ Editor.$uid = 0;
this.onCursorChange = function() {
this.$cursorChange();

if (!this.$blockScrolling) {
config.warn("Automatically scrolling cursor into view after selection change",
"this will be disabled in the next version",
"set editor.$blockScrolling = Infinity to disable this message"
);
this.renderer.scrollCursorIntoView();
}

this.$highlightBrackets();
this.$highlightTags();
this.$updateHighlightActiveLine();
Expand Down Expand Up @@ -1853,7 +1838,6 @@ Editor.$uid = 0;
var config = this.renderer.layerConfig;
var rows = dir * Math.floor(config.height / config.lineHeight);

this.$blockScrolling++;
if (select === true) {
this.selection.$moveSelection(function(){
this.moveCursorBy(rows, 0);
Expand All @@ -1862,7 +1846,6 @@ Editor.$uid = 0;
this.selection.moveCursorBy(rows, 0);
this.selection.clearSelection();
}
this.$blockScrolling--;

var scrollTop = renderer.scrollTop;

Expand Down Expand Up @@ -1987,9 +1970,7 @@ Editor.$uid = 0;
* @related Selection.selectAll
**/
this.selectAll = function() {
this.$blockScrolling += 1;
this.selection.selectAll();
this.$blockScrolling -= 1;
};

/**
Expand Down Expand Up @@ -2201,11 +2182,9 @@ Editor.$uid = 0;
this.selection.clearSelection();
this.session.unfold({row: lineNumber - 1, column: column || 0});

this.$blockScrolling += 1;
// todo: find a way to automatically exit multiselect mode
this.exitMultiSelectMode && this.exitMultiSelectMode();
this.moveCursorTo(lineNumber - 1, column || 0);
this.$blockScrolling -= 1;

if (!this.isRowFullyVisible(lineNumber - 1))
this.scrollToLine(lineNumber - 1, true, animate);
Expand Down Expand Up @@ -2391,8 +2370,6 @@ Editor.$uid = 0;
if (!ranges.length)
return replaced;

this.$blockScrolling += 1;

var selection = this.getSelectionRange();
this.selection.moveTo(0, 0);

Expand All @@ -2403,7 +2380,6 @@ Editor.$uid = 0;
}

this.selection.setSelectionRange(selection);
this.$blockScrolling -= 1;

return replaced;
};
Expand Down Expand Up @@ -2501,10 +2477,8 @@ Editor.$uid = 0;
};

this.revealRange = function(range, animate) {
this.$blockScrolling += 1;
this.session.unfold(range);
this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;

var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
Expand All @@ -2517,9 +2491,7 @@ Editor.$uid = 0;
* @related UndoManager.undo
**/
this.undo = function() {
this.$blockScrolling++;
this.session.getUndoManager().undo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);
};

Expand All @@ -2528,9 +2500,7 @@ Editor.$uid = 0;
* @related UndoManager.redo
**/
this.redo = function() {
this.$blockScrolling++;
this.session.getUndoManager().redo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);
};

Expand Down
12 changes: 10 additions & 2 deletions lib/ace/editor_navigation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
var doc = this.createEditSession(200, 10);
var editor = new Editor(new MockRenderer(), doc);

editor.navigateFileEnd();
editor.execCommand("gotoend");
var cursor = editor.getCursorPosition();

assert.ok(editor.getFirstVisibleRow() <= cursor.row);
Expand All @@ -64,7 +64,7 @@ module.exports = {
var editor = new Editor(new MockRenderer(), doc);

editor.moveCursorTo(editor.getLastVisibleRow() + 20);
editor.navigateFileStart();
editor.execCommand("gotostart");

assert.equal(editor.getFirstVisibleRow(), 0);
},
Expand All @@ -73,31 +73,37 @@ module.exports = {
var editor = new Editor(new MockRenderer(), this.createEditSession(200, 5));

editor.navigateTo(0, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(101);
assert.position(editor.getCursorPosition(), 100, 0);
assert.equal(editor.getFirstVisibleRow(), 89);

editor.navigateTo(100, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(11);
assert.position(editor.getCursorPosition(), 10, 0);
assert.equal(editor.getFirstVisibleRow(), 0);

editor.navigateTo(100, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(6);
assert.position(editor.getCursorPosition(), 5, 0);
assert.equal(0, editor.getFirstVisibleRow(), 0);

editor.navigateTo(100, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(1);
assert.position(editor.getCursorPosition(), 0, 0);
assert.equal(editor.getFirstVisibleRow(), 0);

editor.navigateTo(0, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(191);
assert.position(editor.getCursorPosition(), 190, 0);
assert.equal(editor.getFirstVisibleRow(), 179);

editor.navigateTo(0, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(196);
assert.position(editor.getCursorPosition(), 195, 0);
assert.equal(editor.getFirstVisibleRow(), 180);
Expand All @@ -107,11 +113,13 @@ module.exports = {
var editor = new Editor(new MockRenderer(), this.createEditSession(200, 5));

editor.navigateTo(0, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(12);
assert.position(editor.getCursorPosition(), 11, 0);
assert.equal(editor.getFirstVisibleRow(), 0);

editor.navigateTo(30, 0);
editor.renderer.scrollCursorIntoView();
editor.gotoLine(33);
assert.position(editor.getCursorPosition(), 32, 0);
assert.equal(editor.getFirstVisibleRow(), 30);
Expand Down
8 changes: 0 additions & 8 deletions lib/ace/mouse/default_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ function DefaultHandlers(mouseHandler) {
if (button !== 0) {
var selectionRange = editor.getSelectionRange();
var selectionEmpty = selectionRange.isEmpty();
editor.$blockScrolling++;
if (selectionEmpty || button == 1)
editor.selection.moveToPosition(pos);
editor.$blockScrolling--;
// 2: contextmenu, 1: linux paste
if (button == 2) {
editor.textInput.onContextMenu(ev.domEvent);
Expand Down Expand Up @@ -108,7 +106,6 @@ function DefaultHandlers(mouseHandler) {
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
var editor = this.editor;
// allow double/triple click handlers to change selection
editor.$blockScrolling++;
if (this.mousedownEvent.getShiftKey())
editor.selection.selectToPosition(pos);
else if (!waitForClickSelection)
Expand All @@ -120,13 +117,11 @@ function DefaultHandlers(mouseHandler) {
}
editor.setStyle("ace_selecting");
this.setState("select");
editor.$blockScrolling--;
};

this.select = function() {
var anchor, editor = this.editor;
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
editor.$blockScrolling++;
if (this.$clickSelection) {
var cmp = this.$clickSelection.comparePoint(cursor);

Expand All @@ -142,15 +137,13 @@ function DefaultHandlers(mouseHandler) {
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
}
editor.selection.selectToPosition(cursor);
editor.$blockScrolling--;
editor.renderer.scrollCursorIntoView();
};

this.extendSelectionBy = function(unitName) {
var anchor, editor = this.editor;
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
var range = editor.selection[unitName](cursor.row, cursor.column);
editor.$blockScrolling++;
if (this.$clickSelection) {
var cmpStart = this.$clickSelection.comparePoint(range.start);
var cmpEnd = this.$clickSelection.comparePoint(range.end);
Expand All @@ -174,7 +167,6 @@ function DefaultHandlers(mouseHandler) {
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
}
editor.selection.selectToPosition(cursor);
editor.$blockScrolling--;
editor.renderer.scrollCursorIntoView();
};

Expand Down
4 changes: 0 additions & 4 deletions lib/ace/mouse/dragdrop_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ function DragdropHandler(mouseHandler) {
var vMovement = !prevCursor || cursor.row != prevCursor.row;
var hMovement = !prevCursor || cursor.column != prevCursor.column;
if (!cursorMovedTime || vMovement || hMovement) {
editor.$blockScrolling += 1;
editor.moveCursorToPosition(cursor);
editor.$blockScrolling -= 1;
cursorMovedTime = now;
cursorPointOnCaretMoved = {x: x, y: y};
} else {
Expand Down Expand Up @@ -277,9 +275,7 @@ function DragdropHandler(mouseHandler) {
clearInterval(timerId);
editor.session.removeMarker(dragSelectionMarker);
dragSelectionMarker = null;
editor.$blockScrolling += 1;
editor.selection.fromOrientedRange(range);
editor.$blockScrolling -= 1;
if (editor.isFocused() && !isInternal)
editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
range = null;
Expand Down
9 changes: 0 additions & 9 deletions lib/ace/mouse/multi_select_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ function onMouseDown(e) {

var oldRange = selection.rangeList.rangeAtPoint(pos);


editor.$blockScrolling++;
editor.inVirtualSelectionMode = true;

if (shift) {
Expand All @@ -134,7 +132,6 @@ function onMouseDown(e) {
}
selection.addRange(tmpSel);
}
editor.$blockScrolling--;
editor.inVirtualSelectionMode = false;
});

Expand All @@ -151,7 +148,6 @@ function onMouseDown(e) {
return;
screenCursor = newCursor;

editor.$blockScrolling++;
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();

Expand All @@ -161,9 +157,7 @@ function onMouseDown(e) {
rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
rectSel.forEach(editor.addSelectionMarker, editor);
editor.updateSelectionMarkers();
editor.$blockScrolling--;
};
editor.$blockScrolling++;
if (isMultiSelect && !accel) {
selection.toSingleRange();
} else if (!isMultiSelect && accel) {
Expand All @@ -175,7 +169,6 @@ function onMouseDown(e) {
screenAnchor = session.documentToScreenPosition(selection.lead);
else
selection.moveToPosition(pos);
editor.$blockScrolling--;

screenCursor = {row: -1, column: -1};

Expand All @@ -184,7 +177,6 @@ function onMouseDown(e) {
editor.removeSelectionMarkers(rectSel);
if (!rectSel.length)
rectSel = [selection.toOrientedRange()];
editor.$blockScrolling++;
if (initialRange) {
editor.removeSelectionMarker(initialRange);
selection.toSingleRange(initialRange);
Expand All @@ -193,7 +185,6 @@ function onMouseDown(e) {
selection.addRange(rectSel[i]);
editor.inVirtualSelectionMode = false;
editor.$mouseHandler.$clickSelection = null;
editor.$blockScrolling--;
};

var onSelectionInterval = blockSelect;
Expand Down
5 changes: 0 additions & 5 deletions lib/ace/multi_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ var Editor = require("./editor").Editor;
if (!ranges.length)
return 0;

this.$blockScrolling += 1;
var selection = this.multiSelect;

if (!additive)
Expand All @@ -599,8 +598,6 @@ var Editor = require("./editor").Editor;
if (range && selection.rangeList.rangeAtPoint(range.start))
selection.addRange(range, true);

this.$blockScrolling -= 1;

return ranges.length;
};

Expand Down Expand Up @@ -715,10 +712,8 @@ var Editor = require("./editor").Editor;
var newRange = find(session, needle, dir);
if (newRange) {
newRange.cursor = dir == -1 ? newRange.start : newRange.end;
this.$blockScrolling += 1;
this.session.unfold(newRange);
this.multiSelect.addRange(newRange);
this.$blockScrolling -= 1;
this.renderer.scrollCursorIntoView(null, 0.5);
}
if (skip)
Expand Down

0 comments on commit bde5b19

Please sign in to comment.