Merge pull request #2076 from ajaxorg/no-auto-scroll

Disable automatic scroll into view
This commit is contained in:
Lennart Kats 2014-08-10 10:55:18 +02:00
commit 5348712ce2
9 changed files with 50 additions and 68 deletions

View file

@ -240,6 +240,7 @@ var AcePopup = function(parentNode) {
popup.on("changeSelection", function() { popup.on("changeSelection", function() {
if (popup.isOpen) if (popup.isOpen)
popup.setRow(popup.selection.lead.row); popup.setRow(popup.selection.lead.row);
popup.renderer.scrollCursorIntoView();
}); });
popup.hide = function() { popup.hide = function() {

View file

@ -205,12 +205,14 @@ exports.commands = [{
bindKey: bindKey("Shift-Up", "Shift-Up"), bindKey: bindKey("Shift-Up", "Shift-Up"),
exec: function(editor) { editor.getSelection().selectUp(); }, exec: function(editor) { editor.getSelection().selectUp(); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true readOnly: true
}, { }, {
name: "golineup", name: "golineup",
bindKey: bindKey("Up", "Up|Ctrl-P"), bindKey: bindKey("Up", "Up|Ctrl-P"),
exec: function(editor, args) { editor.navigateUp(args.times); }, exec: function(editor, args) { editor.navigateUp(args.times); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true readOnly: true
}, { }, {
name: "selecttoend", name: "selecttoend",
@ -395,12 +397,21 @@ exports.commands = [{
bindKey: bindKey("Ctrl-P", "Ctrl-P"), bindKey: bindKey("Ctrl-P", "Ctrl-P"),
exec: function(editor) { editor.jumpToMatching(); }, exec: function(editor) { editor.jumpToMatching(); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true readOnly: true
}, { }, {
name: "selecttomatching", name: "selecttomatching",
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"), bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
exec: function(editor) { editor.jumpToMatching(true); }, exec: function(editor) { editor.jumpToMatching(true); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true
}, {
name: "expandToMatching",
bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
exec: function(editor) { editor.jumpToMatching(true, true); },
multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true readOnly: true
}, { }, {
name: "passKeysToBrowser", name: "passKeysToBrowser",
@ -458,11 +469,13 @@ exports.commands = [{
name: "modifyNumberUp", name: "modifyNumberUp",
bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"), bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
exec: function(editor) { editor.modifyNumber(1); }, exec: function(editor) { editor.modifyNumber(1); },
scrollIntoView: "cursor",
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {
name: "modifyNumberDown", name: "modifyNumberDown",
bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"), bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
exec: function(editor) { editor.modifyNumber(-1); }, exec: function(editor) { editor.modifyNumber(-1); },
scrollIntoView: "cursor",
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {
name: "replace", name: "replace",
@ -629,7 +642,7 @@ exports.commands = [{
var isBackwards = editor.selection.isBackwards(); var isBackwards = editor.selection.isBackwards();
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor(); var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead(); var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange()); var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
var selectedCount = selectedText.replace(/\n\s*/, " ").length; var selectedCount = selectedText.replace(/\n\s*/, " ").length;
var insertLine = editor.session.doc.getLine(selectionStart.row); var insertLine = editor.session.doc.getLine(selectionStart.row);
@ -640,7 +653,7 @@ exports.commands = [{
curLine = " " + curLine; curLine = " " + curLine;
} }
insertLine += curLine; insertLine += curLine;
}; }
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) { if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
// Don't insert a newline at the end of the document // Don't insert a newline at the end of the document

View file

@ -35,41 +35,49 @@ exports.defaultCommands = [{
name: "addCursorAbove", name: "addCursorAbove",
exec: function(editor) { editor.selectMoreLines(-1); }, exec: function(editor) { editor.selectMoreLines(-1); },
bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"}, bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorBelow", name: "addCursorBelow",
exec: function(editor) { editor.selectMoreLines(1); }, exec: function(editor) { editor.selectMoreLines(1); },
bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"}, bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorAboveSkipCurrent", name: "addCursorAboveSkipCurrent",
exec: function(editor) { editor.selectMoreLines(-1, true); }, exec: function(editor) { editor.selectMoreLines(-1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"}, bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorBelowSkipCurrent", name: "addCursorBelowSkipCurrent",
exec: function(editor) { editor.selectMoreLines(1, true); }, exec: function(editor) { editor.selectMoreLines(1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"}, bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectMoreBefore", name: "selectMoreBefore",
exec: function(editor) { editor.selectMore(-1); }, exec: function(editor) { editor.selectMore(-1); },
bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"}, bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectMoreAfter", name: "selectMoreAfter",
exec: function(editor) { editor.selectMore(1); }, exec: function(editor) { editor.selectMore(1); },
bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"}, bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectNextBefore", name: "selectNextBefore",
exec: function(editor) { editor.selectMore(-1, true); }, exec: function(editor) { editor.selectMore(-1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"}, bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectNextAfter", name: "selectNextAfter",
exec: function(editor) { editor.selectMore(1, true); }, exec: function(editor) { editor.selectMore(1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"}, bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "splitIntoLines", name: "splitIntoLines",
@ -79,11 +87,13 @@ exports.defaultCommands = [{
}, { }, {
name: "alignCursors", name: "alignCursors",
exec: function(editor) { editor.alignCursors(); }, exec: function(editor) { editor.alignCursors(); },
bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"} bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
scrollIntoView: "cursor"
}, { }, {
name: "findAll", name: "findAll",
exec: function(editor) { editor.findAll(); }, exec: function(editor) { editor.findAll(); },
bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"}, bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
scrollIntoView: "cursor",
readonly: true readonly: true
}]; }];
@ -92,6 +102,7 @@ exports.multiSelectCommands = [{
name: "singleSelection", name: "singleSelection",
bindKey: "esc", bindKey: "esc",
exec: function(editor) { editor.exitMultiSelectMode(); }, exec: function(editor) { editor.exitMultiSelectMode(); },
scrollIntoView: "cursor",
readonly: true, readonly: true,
isAvailable: function(editor) {return editor && editor.inMultiSelectMode} isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
}]; }];

View file

@ -82,7 +82,6 @@ var Editor = function(renderer, session) {
this.$mouseHandler = new MouseHandler(this); this.$mouseHandler = new MouseHandler(this);
new FoldHandler(this); new FoldHandler(this);
this.$blockScrolling = 0;
this.$search = new Search().set({ this.$search = new Search().set({
wrap: true wrap: true
}); });
@ -183,7 +182,6 @@ var Editor = function(renderer, session) {
if (this.curOp) { if (this.curOp) {
var command = this.curOp.command; var command = this.curOp.command;
if (command && command.scrollIntoView) { if (command && command.scrollIntoView) {
this.$blockScrolling--;
switch (command.scrollIntoView) { switch (command.scrollIntoView) {
case "center": case "center":
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
@ -371,9 +369,7 @@ var Editor = function(renderer, session) {
this.onChangeMode(); this.onChangeMode();
this.$blockScrolling += 1;
this.onCursorChange(); this.onCursorChange();
this.$blockScrolling -= 1;
this.onScrollTopChange(); this.onScrollTopChange();
this.onScrollLeftChange(); this.onScrollLeftChange();
@ -732,10 +728,6 @@ var Editor = function(renderer, session) {
this.onCursorChange = function() { this.onCursorChange = function() {
this.$cursorChange(); this.$cursorChange();
if (!this.$blockScrolling) {
this.renderer.scrollCursorIntoView();
}
this.$highlightBrackets(); this.$highlightBrackets();
this.$highlightTags(); this.$highlightTags();
this.$updateHighlightActiveLine(); this.$updateHighlightActiveLine();
@ -921,9 +913,28 @@ var Editor = function(renderer, session) {
// todo this should change when paste becomes a command // todo this should change when paste becomes a command
if (this.$readOnly) if (this.$readOnly)
return; return;
var e = {text: text}; var e = {text: text};
this._signal("paste", e); this._signal("paste", e);
this.insert(e.text, true); text = e.text;
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
this.insert(text);
} else {
var lines = text.split(/\r\n|\r|\n/);
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
return this.commands.exec("insertstring", this, text);
for (var i = ranges.length; i--;) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
}
this.renderer.scrollCursorIntoView();
}; };
@ -1831,7 +1842,6 @@ var Editor = function(renderer, session) {
var config = this.renderer.layerConfig; var config = this.renderer.layerConfig;
var rows = dir * Math.floor(config.height / config.lineHeight); var rows = dir * Math.floor(config.height / config.lineHeight);
this.$blockScrolling++;
if (select === true) { if (select === true) {
this.selection.$moveSelection(function(){ this.selection.$moveSelection(function(){
this.moveCursorBy(rows, 0); this.moveCursorBy(rows, 0);
@ -1840,7 +1850,6 @@ var Editor = function(renderer, session) {
this.selection.moveCursorBy(rows, 0); this.selection.moveCursorBy(rows, 0);
this.selection.clearSelection(); this.selection.clearSelection();
} }
this.$blockScrolling--;
var scrollTop = renderer.scrollTop; var scrollTop = renderer.scrollTop;
@ -1965,9 +1974,7 @@ var Editor = function(renderer, session) {
* @related Selection.selectAll * @related Selection.selectAll
**/ **/
this.selectAll = function() { this.selectAll = function() {
this.$blockScrolling += 1;
this.selection.selectAll(); this.selection.selectAll();
this.$blockScrolling -= 1;
}; };
/** /**
@ -2179,11 +2186,9 @@ var Editor = function(renderer, session) {
this.selection.clearSelection(); this.selection.clearSelection();
this.session.unfold({row: lineNumber - 1, column: column || 0}); this.session.unfold({row: lineNumber - 1, column: column || 0});
this.$blockScrolling += 1;
// todo: find a way to automatically exit multiselect mode // todo: find a way to automatically exit multiselect mode
this.exitMultiSelectMode && this.exitMultiSelectMode(); this.exitMultiSelectMode && this.exitMultiSelectMode();
this.moveCursorTo(lineNumber - 1, column || 0); this.moveCursorTo(lineNumber - 1, column || 0);
this.$blockScrolling -= 1;
if (!this.isRowFullyVisible(lineNumber - 1)) if (!this.isRowFullyVisible(lineNumber - 1))
this.scrollToLine(lineNumber - 1, true, animate); this.scrollToLine(lineNumber - 1, true, animate);
@ -2369,7 +2374,6 @@ var Editor = function(renderer, session) {
if (!ranges.length) if (!ranges.length)
return replaced; return replaced;
this.$blockScrolling += 1;
var selection = this.getSelectionRange(); var selection = this.getSelectionRange();
this.selection.moveTo(0, 0); this.selection.moveTo(0, 0);
@ -2381,7 +2385,6 @@ var Editor = function(renderer, session) {
} }
this.selection.setSelectionRange(selection); this.selection.setSelectionRange(selection);
this.$blockScrolling -= 1;
return replaced; return replaced;
}; };
@ -2479,10 +2482,8 @@ var Editor = function(renderer, session) {
}; };
this.revealRange = function(range, animate) { this.revealRange = function(range, animate) {
this.$blockScrolling += 1;
this.session.unfold(range); this.session.unfold(range);
this.selection.setSelectionRange(range); this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;
var scrollTop = this.renderer.scrollTop; var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5); this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
@ -2495,9 +2496,7 @@ var Editor = function(renderer, session) {
* @related UndoManager.undo * @related UndoManager.undo
**/ **/
this.undo = function() { this.undo = function() {
this.$blockScrolling++;
this.session.getUndoManager().undo(); this.session.getUndoManager().undo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
}; };
@ -2506,9 +2505,7 @@ var Editor = function(renderer, session) {
* @related UndoManager.redo * @related UndoManager.redo
**/ **/
this.redo = function() { this.redo = function() {
this.$blockScrolling++;
this.session.getUndoManager().redo(); this.session.getUndoManager().redo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
}; };

View file

@ -514,6 +514,8 @@ var inputBuffer = exports.inputBuffer = {
this.reset(); this.reset();
} }
handleCursorMove(editor); handleCursorMove(editor);
if (editor.curOp && editor.curOp.selectionChanged)
editor.renderer.scrollCursorIntoView();
}, },
isAccepting: function(type) { isAccepting: function(type) {

View file

@ -91,14 +91,12 @@ module.exports = {
count = count || 1; count = count || 1;
switch (param) { switch (param) {
case "c": case "c":
editor.$blockScrolling++;
editor.selection.$moveSelection(function() { editor.selection.$moveSelection(function() {
editor.selection.moveCursorBy(count - 1, 0); editor.selection.moveCursorBy(count - 1, 0);
}); });
var rows = editor.$getSelectedRows(); var rows = editor.$getSelectedRows();
range = new Range(rows.first, 0, rows.last, Infinity); range = new Range(rows.first, 0, rows.last, Infinity);
editor.session.remove(range); editor.session.remove(range);
editor.$blockScrolling--;
util.insertMode(editor); util.insertMode(editor);
break; break;
default: default:

View file

@ -197,9 +197,7 @@ function DragdropHandler(mouseHandler) {
var vMovement = !prevCursor || cursor.row != prevCursor.row; var vMovement = !prevCursor || cursor.row != prevCursor.row;
var hMovement = !prevCursor || cursor.column != prevCursor.column; var hMovement = !prevCursor || cursor.column != prevCursor.column;
if (!cursorMovedTime || vMovement || hMovement) { if (!cursorMovedTime || vMovement || hMovement) {
editor.$blockScrolling += 1;
editor.moveCursorToPosition(cursor); editor.moveCursorToPosition(cursor);
editor.$blockScrolling -= 1;
cursorMovedTime = now; cursorMovedTime = now;
cursorPointOnCaretMoved = {x: x, y: y}; cursorPointOnCaretMoved = {x: x, y: y};
} else { } else {
@ -273,9 +271,7 @@ function DragdropHandler(mouseHandler) {
clearInterval(timerId); clearInterval(timerId);
editor.session.removeMarker(dragSelectionMarker); editor.session.removeMarker(dragSelectionMarker);
dragSelectionMarker = null; dragSelectionMarker = null;
editor.$blockScrolling += 1;
editor.selection.fromOrientedRange(range); editor.selection.fromOrientedRange(range);
editor.$blockScrolling -= 1;
if (editor.isFocused() && !isInternal) if (editor.isFocused() && !isInternal)
editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly()); editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
range = null; range = null;

View file

@ -112,7 +112,6 @@ function onMouseDown(e) {
var oldRange = selection.rangeList.rangeAtPoint(pos); var oldRange = selection.rangeList.rangeAtPoint(pos);
editor.$blockScrolling++;
editor.inVirtualSelectionMode = true; editor.inVirtualSelectionMode = true;
if (shift) { if (shift) {
@ -134,7 +133,6 @@ function onMouseDown(e) {
} }
selection.addRange(tmpSel); selection.addRange(tmpSel);
} }
editor.$blockScrolling--;
editor.inVirtualSelectionMode = false; editor.inVirtualSelectionMode = false;
}); });
@ -181,7 +179,6 @@ function onMouseDown(e) {
editor.removeSelectionMarkers(rectSel); editor.removeSelectionMarkers(rectSel);
if (!rectSel.length) if (!rectSel.length)
rectSel = [selection.toOrientedRange()]; rectSel = [selection.toOrientedRange()];
editor.$blockScrolling++;
if (initialRange) { if (initialRange) {
editor.removeSelectionMarker(initialRange); editor.removeSelectionMarker(initialRange);
selection.toSingleRange(initialRange); selection.toSingleRange(initialRange);
@ -190,7 +187,6 @@ function onMouseDown(e) {
selection.addRange(rectSel[i]); selection.addRange(rectSel[i]);
editor.inVirtualSelectionMode = false; editor.inVirtualSelectionMode = false;
editor.$mouseHandler.$clickSelection = null; editor.$mouseHandler.$clickSelection = null;
editor.$blockScrolling--;
}; };
var onSelectionInterval = blockSelect; var onSelectionInterval = blockSelect;

View file

@ -557,33 +557,6 @@ var Editor = require("./editor").Editor;
} }
}; };
// todo this should change when paste becomes a command
this.onPaste = function(text) {
if (this.$readOnly)
return;
var e = {text: text};
this._signal("paste", e);
text = e.text;
if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
return this.insert(text);
var lines = text.split(/\r\n|\r|\n/);
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
return this.commands.exec("insertstring", this, text);
for (var i = ranges.length; i--;) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
};
/** /**
* Finds and selects all the occurences of `needle`. * Finds and selects all the occurences of `needle`.
* @param {String} The text to find * @param {String} The text to find
@ -608,7 +581,6 @@ var Editor = require("./editor").Editor;
if (!ranges.length) if (!ranges.length)
return 0; return 0;
this.$blockScrolling += 1;
var selection = this.multiSelect; var selection = this.multiSelect;
if (!additive) if (!additive)
@ -621,8 +593,6 @@ var Editor = require("./editor").Editor;
if (range && selection.rangeList.rangeAtPoint(range.start)) if (range && selection.rangeList.rangeAtPoint(range.start))
selection.addRange(range, true); selection.addRange(range, true);
this.$blockScrolling -= 1;
return ranges.length; return ranges.length;
}; };
@ -737,10 +707,8 @@ var Editor = require("./editor").Editor;
var newRange = find(session, needle, dir); var newRange = find(session, needle, dir);
if (newRange) { if (newRange) {
newRange.cursor = dir == -1 ? newRange.start : newRange.end; newRange.cursor = dir == -1 ? newRange.start : newRange.end;
this.$blockScrolling += 1;
this.session.unfold(newRange); this.session.unfold(newRange);
this.multiSelect.addRange(newRange); this.multiSelect.addRange(newRange);
this.$blockScrolling -= 1;
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
} }
if (skip) if (skip)