fix move lines with multiple cursors
This commit is contained in:
parent
917420636b
commit
f6d88bc10c
4 changed files with 159 additions and 144 deletions
|
|
@ -359,23 +359,19 @@ exports.commands = [{
|
|||
}, {
|
||||
name: "copylinesup",
|
||||
bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
|
||||
exec: function(editor) { editor.copyLinesUp(); },
|
||||
multiSelectAction: "forEachLine"
|
||||
exec: function(editor) { editor.copyLinesUp(); }
|
||||
}, {
|
||||
name: "movelinesup",
|
||||
bindKey: bindKey("Alt-Up", "Option-Up"),
|
||||
exec: function(editor) { editor.moveLinesUp(); },
|
||||
multiSelectAction: "forEachLine"
|
||||
exec: function(editor) { editor.moveLinesUp(); }
|
||||
}, {
|
||||
name: "copylinesdown",
|
||||
bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
|
||||
exec: function(editor) { editor.copyLinesDown(); },
|
||||
multiSelectAction: "forEachLine"
|
||||
exec: function(editor) { editor.copyLinesDown(); }
|
||||
}, {
|
||||
name: "movelinesdown",
|
||||
bindKey: bindKey("Alt-Down", "Option-Down"),
|
||||
exec: function(editor) { editor.moveLinesDown(); },
|
||||
multiSelectAction: "forEachLine"
|
||||
exec: function(editor) { editor.moveLinesDown(); }
|
||||
}, {
|
||||
name: "del",
|
||||
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (c) 2010, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
|
|
@ -51,9 +51,9 @@ var config = require("./config");
|
|||
/**
|
||||
*
|
||||
*
|
||||
* The main entry point into the Ace functionality.
|
||||
* The main entry point into the Ace functionality.
|
||||
*
|
||||
* The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen.
|
||||
* The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen.
|
||||
*
|
||||
* Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them.
|
||||
* @class Editor
|
||||
|
|
@ -100,7 +100,7 @@ var Editor = function(renderer, session) {
|
|||
* Sets a new key handler, such as "vim" or "windows".
|
||||
* @param {String} keyboardHandler The new key handler
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setKeyboardHandler = function(keyboardHandler) {
|
||||
if (typeof keyboardHandler == "string" && keyboardHandler) {
|
||||
|
|
@ -116,11 +116,11 @@ var Editor = function(renderer, session) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the keyboard handler, such as "vim" or "windows".
|
||||
*
|
||||
* @returns {String}
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.getKeyboardHandler = function() {
|
||||
return this.keyBinding.getKeyboardHandler();
|
||||
|
|
@ -247,7 +247,7 @@ var Editor = function(renderer, session) {
|
|||
return this.session;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets the current document to `val`.
|
||||
* @param {String} val The new value to set for the document
|
||||
* @param {Number} cursorPos Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end
|
||||
|
|
@ -268,7 +268,7 @@ var Editor = function(renderer, session) {
|
|||
return val;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the current session's content.
|
||||
*
|
||||
* @returns {String}
|
||||
|
|
@ -279,7 +279,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Returns the currently highlighted selection.
|
||||
* @returns {String} The highlighted selection
|
||||
**/
|
||||
|
|
@ -287,11 +287,11 @@ var Editor = function(renderer, session) {
|
|||
return this.selection;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:VirtualRenderer.onResize}
|
||||
* @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed
|
||||
*
|
||||
*
|
||||
*
|
||||
* @related VirtualRenderer.onResize
|
||||
**/
|
||||
this.resize = function(force) {
|
||||
|
|
@ -308,9 +308,9 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.setTheme(theme);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:VirtualRenderer.getTheme}
|
||||
*
|
||||
*
|
||||
* @returns {String} The set theme
|
||||
* @related VirtualRenderer.getTheme
|
||||
**/
|
||||
|
|
@ -322,14 +322,14 @@ var Editor = function(renderer, session) {
|
|||
* {:VirtualRenderer.setStyle}
|
||||
* @param {String} style A class name
|
||||
*
|
||||
*
|
||||
*
|
||||
* @related VirtualRenderer.setStyle
|
||||
**/
|
||||
this.setStyle = function(style) {
|
||||
this.renderer.setStyle(style);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:VirtualRenderer.unsetStyle}
|
||||
* @related VirtualRenderer.unsetStyle
|
||||
**/
|
||||
|
|
@ -340,8 +340,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Set a new font size (in pixels) for the editor text.
|
||||
* @param {String} size A font size ( _e.g._ "12px")
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setFontSize = function(size) {
|
||||
if (typeof size == "number")
|
||||
|
|
@ -375,7 +375,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Brings the current `textInput` into focus.
|
||||
**/
|
||||
this.focus = function() {
|
||||
|
|
@ -398,7 +398,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Blurs the current `textInput`.
|
||||
**/
|
||||
this.blur = function() {
|
||||
|
|
@ -407,9 +407,9 @@ var Editor = function(renderer, session) {
|
|||
|
||||
/**
|
||||
* Emitted once the editor comes into focus.
|
||||
* @event focus
|
||||
*
|
||||
*
|
||||
* @event focus
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.onFocus = function() {
|
||||
if (this.$isFocused)
|
||||
|
|
@ -423,8 +423,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Emitted once the editor has been blurred.
|
||||
* @event blur
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.onBlur = function() {
|
||||
if (!this.$isFocused)
|
||||
|
|
@ -440,12 +440,12 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Emitted whenever the document is changed.
|
||||
* Emitted whenever the document is changed.
|
||||
* @event change
|
||||
* @param {Object} e Contains a single property, `data`, which has the delta of changes
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.onDocumentChange = function(e) {
|
||||
var delta = e.data;
|
||||
|
|
@ -473,14 +473,14 @@ var Editor = function(renderer, session) {
|
|||
this.onScrollTopChange = function() {
|
||||
this.renderer.scrollToY(this.session.getScrollTop());
|
||||
};
|
||||
|
||||
|
||||
this.onScrollLeftChange = function() {
|
||||
this.renderer.scrollToX(this.session.getScrollLeft());
|
||||
};
|
||||
|
||||
/**
|
||||
* Emitted when the selection changes.
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.onCursorChange = function() {
|
||||
this.$cursorChange();
|
||||
|
|
@ -508,7 +508,7 @@ var Editor = function(renderer, session) {
|
|||
session.$highlightLineMarker = null;
|
||||
} else if (!session.$highlightLineMarker && highlight) {
|
||||
var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
|
||||
range.id = session.addMarker(range, "ace_active-line", "screenLine");
|
||||
range.id = session.addMarker(range, "ace_active-line", "screenLine");
|
||||
session.$highlightLineMarker = range;
|
||||
} else if (highlight) {
|
||||
session.$highlightLineMarker.start.row = highlight.row;
|
||||
|
|
@ -536,7 +536,7 @@ var Editor = function(renderer, session) {
|
|||
|
||||
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
|
||||
this.session.highlight(re);
|
||||
|
||||
|
||||
this._emit("changeSelection");
|
||||
};
|
||||
|
||||
|
|
@ -616,10 +616,10 @@ var Editor = function(renderer, session) {
|
|||
|
||||
/**
|
||||
* Emitted when text is copied.
|
||||
* @event copy
|
||||
* @event copy
|
||||
* @param {String} text The copied text
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
/**
|
||||
*
|
||||
|
|
@ -665,7 +665,7 @@ var Editor = function(renderer, session) {
|
|||
**/
|
||||
this.onPaste = function(text) {
|
||||
// todo this should change when paste becomes a command
|
||||
if (this.$readOnly)
|
||||
if (this.$readOnly)
|
||||
return;
|
||||
this._emit("paste", text);
|
||||
this.insert(text);
|
||||
|
|
@ -679,8 +679,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Inserts `text` into wherever the cursor is pointing.
|
||||
* @param {String} text The new text to add
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.insert = function(text) {
|
||||
var session = this.session;
|
||||
|
|
@ -780,10 +780,10 @@ var Editor = function(renderer, session) {
|
|||
this.keyBinding.onCommandKey(e, hashId, keyCode);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Pass in `true` to enable overwrites in your session, or `false` to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emites the `changeOverwrite` event.
|
||||
* @param {Boolean} overwrite Defines wheter or not to set overwrites
|
||||
*
|
||||
*
|
||||
*
|
||||
* @related EditSession.setOverwrite
|
||||
**/
|
||||
|
|
@ -791,7 +791,7 @@ var Editor = function(renderer, session) {
|
|||
this.session.setOverwrite(overwrite);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns `true` if overwrites are enabled; `false` otherwise.
|
||||
* @returns {Boolean}
|
||||
* @related EditSession.getOverwrite
|
||||
|
|
@ -800,7 +800,7 @@ var Editor = function(renderer, session) {
|
|||
return this.session.getOverwrite();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets the value of overwrite to the opposite of whatever it currently is.
|
||||
* @related EditSession.toggleOverwrite
|
||||
**/
|
||||
|
|
@ -861,7 +861,7 @@ var Editor = function(renderer, session) {
|
|||
this.getSelectionStyle = function() {
|
||||
return this.getOption("selectionStyle");
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether or not the current line should be highlighted.
|
||||
* @param {Boolean} shouldHighlight Set to `true` to highlight the current line
|
||||
|
|
@ -911,7 +911,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* If `showInvisibiles` is set to `true`, invisible characters—like spaces or new lines—are show in the editor.
|
||||
* @param {Boolean} showInvisibles Specifies whether or not to show invisible characters
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setShowInvisibles = function(showInvisibles) {
|
||||
this.renderer.setShowInvisibles(showInvisibles);
|
||||
|
|
@ -936,7 +936,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* If `showPrintMargin` is set to `true`, the print margin is shown in the editor.
|
||||
* @param {Boolean} showPrintMargin Specifies whether or not to show the print margin
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setShowPrintMargin = function(showPrintMargin) {
|
||||
this.renderer.setShowPrintMargin(showPrintMargin);
|
||||
|
|
@ -970,7 +970,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change.
|
||||
* @param {Boolean} readOnly Specifies whether the editor can be modified or not
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setReadOnly = function(readOnly) {
|
||||
this.setOption("readOnly", readOnly);
|
||||
|
|
@ -987,7 +987,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef}
|
||||
* @param {Boolean} enabled Enables or disables behaviors
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setBehavioursEnabled = function (enabled) {
|
||||
this.setOption("behavioursEnabled", enabled);
|
||||
|
|
@ -995,7 +995,7 @@ var Editor = function(renderer, session) {
|
|||
|
||||
/**
|
||||
* Returns `true` if the behaviors are currently enabled. {:BehaviorsDef}
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.getBehavioursEnabled = function () {
|
||||
|
|
@ -1006,7 +1006,7 @@ var Editor = function(renderer, session) {
|
|||
* Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets
|
||||
* when such a character is typed in.
|
||||
* @param {Boolean} enabled Enables or disables wrapping behaviors
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setWrapBehavioursEnabled = function (enabled) {
|
||||
this.setOption("wrapBehavioursEnabled", enabled);
|
||||
|
|
@ -1046,7 +1046,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace.
|
||||
* @param {String} dir The direction of the deletion to occur, either "left" or "right"
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.remove = function(dir) {
|
||||
if (this.selection.isEmpty()){
|
||||
|
|
@ -1191,7 +1191,7 @@ var Editor = function(renderer, session) {
|
|||
|
||||
/**
|
||||
* Inserts an indentation into the current cursor position or indents the selected lines.
|
||||
*
|
||||
*
|
||||
* @related EditSession.indentRows
|
||||
**/
|
||||
this.indent = function() {
|
||||
|
|
@ -1261,7 +1261,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Given the currently selected range, this function either comments all the lines, or uncomments all of them.
|
||||
**/
|
||||
this.toggleCommentLines = function() {
|
||||
|
|
@ -1293,7 +1293,7 @@ var Editor = function(renderer, session) {
|
|||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* If the character before the cursor is a number, this functions changes its value by `amount`.
|
||||
* @param {Number} amount The value to change the numeral by (can be negative to decrease value)
|
||||
|
|
@ -1318,14 +1318,14 @@ var Editor = function(renderer, session) {
|
|||
|
||||
var t = parseFloat(nr.value);
|
||||
t *= Math.pow(10, decimals);
|
||||
|
||||
|
||||
|
||||
if(fp !== nr.end && column < fp){
|
||||
amount *= Math.pow(10, nr.end - column - 1);
|
||||
} else {
|
||||
amount *= Math.pow(10, nr.end - column);
|
||||
}
|
||||
|
||||
|
||||
t += amount;
|
||||
t /= Math.pow(10, decimals);
|
||||
var nnr = t.toFixed(decimals);
|
||||
|
|
@ -1340,8 +1340,8 @@ var Editor = function(renderer, session) {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Removes all the lines in the current selection
|
||||
* @related EditSession.remove
|
||||
**/
|
||||
|
|
@ -1367,17 +1367,16 @@ var Editor = function(renderer, session) {
|
|||
var row = range.start.row;
|
||||
doc.duplicateLines(row, row);
|
||||
} else {
|
||||
var reverse = sel.isBackwards()
|
||||
var point = sel.isBackwards() ? range.start : range.end;
|
||||
var point = reverse ? range.start : range.end;
|
||||
var endPoint = doc.insert(point, doc.getTextRange(range), false);
|
||||
range.start = point;
|
||||
range.end = endPoint;
|
||||
|
||||
|
||||
sel.setSelectionRange(range, reverse)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Shifts all the selected lines down one row.
|
||||
*
|
||||
* @returns {Number} On success, it returns -1.
|
||||
|
|
@ -1389,7 +1388,7 @@ var Editor = function(renderer, session) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Shifts all the selected lines up one row.
|
||||
* @returns {Number} On success, it returns -1.
|
||||
* @related EditSession.moveLinesDown
|
||||
|
|
@ -1400,28 +1399,25 @@ var Editor = function(renderer, session) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this:
|
||||
* ```json
|
||||
* { row: newRowLocation, column: newColumnLocation }
|
||||
* ```
|
||||
* @param {Range} fromRange The range of text you want moved within the document
|
||||
* @param {Object} toPosition The location (row and column) where you want to move the text to
|
||||
*
|
||||
*
|
||||
* @returns {Range} The new range where the text was moved to.
|
||||
* @related EditSession.moveText
|
||||
**/
|
||||
this.moveText = function(range, toPosition) {
|
||||
if (this.$readOnly)
|
||||
return null;
|
||||
|
||||
return this.session.moveText(range, toPosition);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Copies all the selected lines up one row.
|
||||
* @returns {Number} On success, returns 0.
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.copyLinesUp = function() {
|
||||
this.$moveLines(function(firstRow, lastRow) {
|
||||
|
|
@ -1430,7 +1426,7 @@ var Editor = function(renderer, session) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Copies all the selected lines down one row.
|
||||
* @returns {Number} On success, returns the number of new rows added; in other words, `lastRow - firstRow + 1`.
|
||||
* @related EditSession.duplicateLines
|
||||
|
|
@ -1446,29 +1442,43 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Executes a specific function, which can be anything that manipulates selected lines, such as copying them, duplicating them, or shifting them.
|
||||
* @param {Function} mover A method to call on each selected row
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.$moveLines = function(mover) {
|
||||
var rows = this.$getSelectedRows();
|
||||
var selection = this.selection;
|
||||
if (!selection.isMultiLine()) {
|
||||
var range = selection.getRange();
|
||||
var reverse = selection.isBackwards();
|
||||
}
|
||||
|
||||
var linesMoved = mover.call(this, rows.first, rows.last);
|
||||
|
||||
if (range) {
|
||||
range.start.row += linesMoved;
|
||||
range.end.row += linesMoved;
|
||||
selection.setSelectionRange(range, reverse);
|
||||
}
|
||||
else {
|
||||
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
|
||||
selection.$moveSelection(function() {
|
||||
selection.moveCursorTo(rows.first+linesMoved, 0);
|
||||
});
|
||||
if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
|
||||
var range = selection.toOrientedRange();
|
||||
var rows = this.$getSelectedRows(range);
|
||||
var linesMoved = mover.call(this, rows.first, rows.last);
|
||||
range.moveBy(linesMoved, 0);
|
||||
selection.fromOrientedRange(range);
|
||||
} else {
|
||||
var ranges = selection.rangeList.ranges;
|
||||
selection.rangeList.detach(this.session);
|
||||
|
||||
for (var i = ranges.length; i--; ) {
|
||||
var rangeIndex = i;
|
||||
var rows = ranges[i].collapseRows();
|
||||
var last = rows.end.row;
|
||||
var first = rows.start.row;
|
||||
while (i--) {
|
||||
var rows = ranges[i].collapseRows();
|
||||
if (first - rows.end.row <= 1)
|
||||
first = rows.end.row;
|
||||
else
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
|
||||
var linesMoved = mover.call(this, first, last);
|
||||
while (rangeIndex >= i) {
|
||||
ranges[rangeIndex].moveBy(linesMoved, 0);
|
||||
rangeIndex--;
|
||||
}
|
||||
}
|
||||
selection.fromOrientedRange(selection.ranges[0]);
|
||||
selection.rangeList.attach(this.session);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1502,7 +1512,7 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.hideComposition();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:VirtualRenderer.getFirstVisibleRow}
|
||||
*
|
||||
* @returns {Number}
|
||||
|
|
@ -1512,7 +1522,7 @@ var Editor = function(renderer, session) {
|
|||
return this.renderer.getFirstVisibleRow();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:VirtualRenderer.getLastVisibleRow}
|
||||
*
|
||||
* @returns {Number}
|
||||
|
|
@ -1525,7 +1535,7 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Indicates if the row is currently visible on the screen.
|
||||
* @param {Number} row The row to check
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.isRowVisible = function(row) {
|
||||
|
|
@ -1535,8 +1545,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Indicates if the entire row is currently visible on the screen.
|
||||
* @param {Number} row The row to check
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.isRowFullyVisible = function(row) {
|
||||
|
|
@ -1618,7 +1628,7 @@ var Editor = function(renderer, session) {
|
|||
this.$moveByPage(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves the editor to the specified row.
|
||||
* @related VirtualRenderer.scrollToRow
|
||||
**/
|
||||
|
|
@ -1626,14 +1636,14 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.scrollToRow(row);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Scrolls to a line. If `center` is `true`, it puts the line in middle of screen (or attempts to).
|
||||
* @param {Number} line The line to scroll to
|
||||
* @param {Boolean} center If `true`
|
||||
* @param {Boolean} center If `true`
|
||||
* @param {Boolean} animate If `true` animates scrolling
|
||||
* @param {Function} callback Function to be called when the animation has finished
|
||||
*
|
||||
*
|
||||
*
|
||||
* @related VirtualRenderer.scrollToLine
|
||||
**/
|
||||
this.scrollToLine = function(line, center, animate, callback) {
|
||||
|
|
@ -1652,9 +1662,9 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.alignCursor(pos, 0.5);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the current position of the cursor.
|
||||
* @returns {Object} An object that looks something like this:
|
||||
* @returns {Object} An object that looks something like this:
|
||||
*
|
||||
* ```json
|
||||
* { row: currRow, column: currCol }
|
||||
|
|
@ -1666,7 +1676,7 @@ var Editor = function(renderer, session) {
|
|||
return this.selection.getCursor();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the screen position of the cursor.
|
||||
* @returns {Number}
|
||||
* @related EditSession.documentToScreenPosition
|
||||
|
|
@ -1675,7 +1685,7 @@ var Editor = function(renderer, session) {
|
|||
return this.session.documentToScreenPosition(this.getCursorPosition());
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:Selection.getRange}
|
||||
* @returns {Range}
|
||||
* @related Selection.getRange
|
||||
|
|
@ -1685,7 +1695,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Selects all the text in editor.
|
||||
* @related Selection.selectAll
|
||||
**/
|
||||
|
|
@ -1695,7 +1705,7 @@ var Editor = function(renderer, session) {
|
|||
this.$blockScrolling -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:Selection.clearSelection}
|
||||
* @related Selection.clearSelection
|
||||
**/
|
||||
|
|
@ -1703,7 +1713,7 @@ var Editor = function(renderer, session) {
|
|||
this.selection.clearSelection();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves the cursor to the specified row and column. Note that this does not de-select the current selection.
|
||||
* @param {Number} row The new row number
|
||||
* @param {Number} column The new column number
|
||||
|
|
@ -1715,10 +1725,10 @@ var Editor = function(renderer, session) {
|
|||
this.selection.moveCursorTo(row, column);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves the cursor to the position indicated by `pos.row` and `pos.column`.
|
||||
* @param {Object} pos An object with two properties, row and column
|
||||
*
|
||||
*
|
||||
*
|
||||
* @related Selection.moveCursorToPosition
|
||||
**/
|
||||
|
|
@ -1726,7 +1736,7 @@ var Editor = function(renderer, session) {
|
|||
this.selection.moveCursorToPosition(pos);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves the cursor's row and column to the next matching bracket.
|
||||
*
|
||||
**/
|
||||
|
|
@ -1746,7 +1756,7 @@ var Editor = function(renderer, session) {
|
|||
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
|
||||
range = this.session.getBracketRange(pos);
|
||||
}
|
||||
|
||||
|
||||
pos = range && range.cursor || pos;
|
||||
if (pos) {
|
||||
if (select) {
|
||||
|
|
@ -1766,7 +1776,7 @@ var Editor = function(renderer, session) {
|
|||
* @param {Number} lineNumber The line number to go to
|
||||
* @param {Number} column A column number to go to
|
||||
* @param {Boolean} animate If `true` animates scolling
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.gotoLine = function(lineNumber, column, animate) {
|
||||
this.selection.clearSelection();
|
||||
|
|
@ -1780,7 +1790,7 @@ var Editor = function(renderer, session) {
|
|||
this.scrollToLine(lineNumber - 1, true, animate);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Moves the cursor to the specified row and column. Note that this does de-select the current selection.
|
||||
* @param {Number} row The new row number
|
||||
* @param {Number} column The new column number
|
||||
|
|
@ -1796,8 +1806,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection.
|
||||
* @param {Number} times The number of times to change navigation
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.navigateUp = function(times) {
|
||||
this.selection.clearSelection();
|
||||
|
|
@ -1808,8 +1818,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection.
|
||||
* @param {Number} times The number of times to change navigation
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.navigateDown = function(times) {
|
||||
this.selection.clearSelection();
|
||||
|
|
@ -1820,8 +1830,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection.
|
||||
* @param {Number} times The number of times to change navigation
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.navigateLeft = function(times) {
|
||||
if (!this.selection.isEmpty()) {
|
||||
|
|
@ -1840,8 +1850,8 @@ var Editor = function(renderer, session) {
|
|||
/**
|
||||
* Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection.
|
||||
* @param {Number} times The number of times to change navigation
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.navigateRight = function(times) {
|
||||
if (!this.selection.isEmpty()) {
|
||||
|
|
@ -1858,7 +1868,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the start of the current line. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateLineStart = function() {
|
||||
|
|
@ -1867,7 +1877,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the end of the current line. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateLineEnd = function() {
|
||||
|
|
@ -1876,7 +1886,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the end of the current file. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateFileEnd = function() {
|
||||
|
|
@ -1887,7 +1897,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the start of the current file. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateFileStart = function() {
|
||||
|
|
@ -1898,7 +1908,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the word immediately to the right of the current position. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateWordRight = function() {
|
||||
|
|
@ -1907,7 +1917,7 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Moves the cursor to the word immediately to the left of the current position. Note that this does de-select the current selection.
|
||||
**/
|
||||
this.navigateWordLeft = function() {
|
||||
|
|
@ -1988,7 +1998,7 @@ var Editor = function(renderer, session) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:Search.getOptions} For more information on `options`, see [[Search `Search`]].
|
||||
* @related Search.getOptions
|
||||
* @returns {Object}
|
||||
|
|
@ -1997,7 +2007,7 @@ var Editor = function(renderer, session) {
|
|||
return this.$search.getOptions();
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]].
|
||||
* @param {String} needle The text to search for (optional)
|
||||
* @param {Object} options An object defining various search properties
|
||||
|
|
@ -2045,7 +2055,7 @@ var Editor = function(renderer, session) {
|
|||
this.selection.setRange(range);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
|
||||
* @param {Object} options search options
|
||||
* @param {Boolean} animate If `true` animate scrolling
|
||||
|
|
@ -2057,7 +2067,7 @@ var Editor = function(renderer, session) {
|
|||
this.find({skipCurrent: true, backwards: false}, options, animate);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
|
||||
* @param {Object} options search options
|
||||
* @param {Boolean} animate If `true` animate scrolling
|
||||
|
|
@ -2081,7 +2091,7 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.animateScrolling(scrollTop);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:UndoManager.undo}
|
||||
* @related UndoManager.undo
|
||||
**/
|
||||
|
|
@ -2092,7 +2102,7 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.scrollCursorIntoView(null, 0.5);
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* {:UndoManager.redo}
|
||||
* @related UndoManager.redo
|
||||
**/
|
||||
|
|
@ -2103,16 +2113,16 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.scrollCursorIntoView(null, 0.5);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
/**
|
||||
*
|
||||
* Cleans up the entire editor.
|
||||
**/
|
||||
this.destroy = function() {
|
||||
this.renderer.destroy();
|
||||
this._emit("destroy", this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Enables automatic scrolling of the cursor into view when editor itself is inside scrollable element
|
||||
* @param {Boolean} enable default true
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -482,13 +482,13 @@ var Editor = require("./editor").Editor;
|
|||
this.inVirtualSelectionMode = true;
|
||||
for (var i = rangeList.ranges.length; i--;) {
|
||||
if ($byLines) {
|
||||
while (i > 0 && rangeList.ranges[i].start.row == rangeList.ranges[i].end.row)
|
||||
while (i > 0 && rangeList.ranges[i].start.row == rangeList.ranges[i - 1].end.row)
|
||||
i--;
|
||||
}
|
||||
tmpSel.fromOrientedRange(rangeList.ranges[i]);
|
||||
this.selection = session.selection = tmpSel;
|
||||
cmd.exec(this, args || {});
|
||||
tmpSel.toOrientedRange(rangeList.ranges[i]);
|
||||
tmpSel.toOrientedRange(rangeList.ranges[i]);
|
||||
}
|
||||
tmpSel.detach();
|
||||
|
||||
|
|
|
|||
|
|
@ -516,6 +516,15 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
screenPosEnd.row, screenPosEnd.column
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/* experimental */
|
||||
this.moveBy = function(row, column) {
|
||||
this.start.row += row;
|
||||
this.start.column += column;
|
||||
this.end.row += row;
|
||||
this.end.column += column;
|
||||
};
|
||||
|
||||
}).call(Range.prototype);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue