909 lines
27 KiB
JavaScript
909 lines
27 KiB
JavaScript
/* vim:ts=4:sts=4:sw=4:
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
*
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
* http://www.mozilla.org/MPL/
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
* for the specific language governing rights and limitations under the
|
|
* License.
|
|
*
|
|
* The Original Code is Ajax.org Code Editor (ACE).
|
|
*
|
|
* The Initial Developer of the Original Code is
|
|
* Ajax.org B.V.
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
* the Initial Developer. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
|
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
|
|
* Julian Viereck <julian.viereck@gmail.com>
|
|
*
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
* the provisions above, a recipient may use your version of this file under
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
*
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
define(function(require, exports, module) {
|
|
|
|
require("ace/lib/fixoldbrowsers");
|
|
|
|
var oop = require("ace/lib/oop");
|
|
var event = require("ace/lib/event");
|
|
var lang = require("ace/lib/lang");
|
|
var useragent = require("ace/lib/useragent");
|
|
var TextInput = require("ace/keyboard/textinput").TextInput;
|
|
var MouseHandler = require("ace/mouse_handler").MouseHandler;
|
|
//var TouchHandler = require("ace/touch_handler").TouchHandler;
|
|
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
|
|
var Buffer = require("ace/model/buffer").Buffer;
|
|
var Window = require("ace/model/window").Window;
|
|
var WindowController = require("ace/window_controller").WindowController;
|
|
var Search = require("ace/search").Search;
|
|
var Range = require("ace/range").Range;
|
|
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
|
|
var CommandManager = require("ace/commands/command_manager").CommandManager;
|
|
var defaultCommands = require("ace/commands/default_commands").commands;
|
|
|
|
var Editor = function(windowView, buffer) {
|
|
var container = windowView.getContainerElement();
|
|
this.container = container;
|
|
this.renderer = windowView;
|
|
|
|
this.textInput = new TextInput(windowView.getTextAreaContainer(), this);
|
|
this.keyBinding = new KeyBinding(this);
|
|
|
|
// TODO detect touch event support
|
|
if (useragent.isIPad) {
|
|
//this.$mouseHandler = new TouchHandler(this);
|
|
} else {
|
|
this.$mouseHandler = new MouseHandler(this);
|
|
}
|
|
|
|
this.windowModel = this.renderer.model;
|
|
this.windowModel.search = new Search().set({
|
|
wrap: true
|
|
});
|
|
this.windowController = new WindowController(this.windowModel, this.renderer);
|
|
|
|
this.commands = new CommandManager(defaultCommands);
|
|
this.setSession(buffer || new Buffer(""));
|
|
};
|
|
|
|
(function(){
|
|
|
|
oop.implement(this, EventEmitter);
|
|
|
|
this.$forwardEvents = {
|
|
gutterclick: 1,
|
|
gutterdblclick: 1
|
|
};
|
|
|
|
this.$originalAddEventListener = this.addEventListener;
|
|
this.$originalRemoveEventListener = this.removeEventListener;
|
|
|
|
this.addEventListener = function(eventName, callback) {
|
|
if (this.$forwardEvents[eventName]) {
|
|
return this.renderer.addEventListener(eventName, callback);
|
|
} else {
|
|
return this.$originalAddEventListener(eventName, callback);
|
|
}
|
|
};
|
|
|
|
this.removeEventListener = function(eventName, callback) {
|
|
if (this.$forwardEvents[eventName]) {
|
|
return this.renderer.removeEventListener(eventName, callback);
|
|
} else {
|
|
return this.$originalRemoveEventListener(eventName, callback);
|
|
}
|
|
};
|
|
|
|
this.setKeyboardHandler = function(keyboardHandler) {
|
|
this.keyBinding.setKeyboardHandler(keyboardHandler);
|
|
};
|
|
|
|
this.getKeyboardHandler = function() {
|
|
return this.keyBinding.getKeyboardHandler();
|
|
};
|
|
|
|
// TODO refactor
|
|
// remove
|
|
this.setSession = function(session) {
|
|
if (this.session == session)
|
|
return;
|
|
|
|
this.windowModel.setBuffer(session);
|
|
this.session = session;
|
|
this.selection = session.getSelection();
|
|
};
|
|
|
|
this.getSession = function() {
|
|
return this.session;
|
|
};
|
|
|
|
this.getSelection = function() {
|
|
return this.selection;
|
|
};
|
|
|
|
this.resize = function() {
|
|
//this.renderer.onResize();
|
|
this.windowController.resize();
|
|
};
|
|
|
|
this.setTheme = function(theme) {
|
|
this.windowModel.setTheme(theme);
|
|
};
|
|
|
|
this.getTheme = function() {
|
|
return this.windowModel.getTheme();
|
|
};
|
|
|
|
this.setStyle = function(style) {
|
|
this.renderer.setStyle(style);
|
|
};
|
|
|
|
this.unsetStyle = function(style) {
|
|
this.renderer.unsetStyle(style);
|
|
};
|
|
|
|
this.setFontSize = function(size) {
|
|
this.container.style.fontSize = size;
|
|
};
|
|
|
|
this.focus = function() {
|
|
// Safari needs the timeout
|
|
// iOS and Firefox need it called immediately
|
|
// to be on the save side we do both
|
|
var _self = this;
|
|
setTimeout(function() {
|
|
_self.textInput.focus();
|
|
});
|
|
this.textInput.focus();
|
|
};
|
|
|
|
this.isFocused = function() {
|
|
return this.textInput.isFocused();
|
|
};
|
|
|
|
this.blur = function() {
|
|
this.textInput.blur();
|
|
};
|
|
|
|
this.onFocus = function() {
|
|
this.renderer.showCursor();
|
|
this.renderer.visualizeFocus();
|
|
this._dispatchEvent("focus");
|
|
};
|
|
|
|
this.onBlur = function() {
|
|
this.renderer.hideCursor();
|
|
this.renderer.visualizeBlur();
|
|
this._dispatchEvent("blur");
|
|
};
|
|
|
|
this.getCopyText = function() {
|
|
var text = "";
|
|
if (!this.selection.isEmpty())
|
|
text = this.session.getTextRange(this.getSelectionRange());
|
|
|
|
this._emit("copy", text);
|
|
return text;
|
|
};
|
|
|
|
this.onCut = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var range = this.getSelectionRange();
|
|
this._emit("cut", range);
|
|
|
|
if (!this.selection.isEmpty()) {
|
|
this.session.remove(range)
|
|
this.clearSelection();
|
|
}
|
|
};
|
|
|
|
this.insert = function(text) {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var session = this.session;
|
|
var mode = session.getMode();
|
|
|
|
var cursor = this.getCursorPosition();
|
|
|
|
if (this.getBehavioursEnabled()) {
|
|
// Get a transform if the current mode wants one.
|
|
var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
|
|
if (transform)
|
|
text = transform.text;
|
|
}
|
|
|
|
text = text.replace("\t", this.session.getTabString());
|
|
|
|
// remove selected text
|
|
if (!this.selection.isEmpty()) {
|
|
var cursor = this.session.remove(this.getSelectionRange());
|
|
this.clearSelection();
|
|
}
|
|
else if (this.session.getOverwrite()) {
|
|
var range = new Range.fromPoints(cursor, cursor);
|
|
range.end.column += text.length;
|
|
this.session.remove(range);
|
|
}
|
|
|
|
this.clearSelection();
|
|
|
|
var start = cursor.column;
|
|
var lineState = session.getState(cursor.row);
|
|
var shouldOutdent = mode.checkOutdent(lineState, session.getLine(cursor.row), text);
|
|
var line = session.getLine(cursor.row);
|
|
var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
|
|
var end = session.insert(cursor, text);
|
|
|
|
if (transform && transform.selection) {
|
|
if (transform.selection.length == 2) { // Transform relative to the current column
|
|
this.selection.setSelectionRange(
|
|
new Range(cursor.row, start + transform.selection[0],
|
|
cursor.row, start + transform.selection[1]));
|
|
} else { // Transform relative to the current row.
|
|
this.selection.setSelectionRange(
|
|
new Range(cursor.row + transform.selection[0],
|
|
transform.selection[1],
|
|
cursor.row + transform.selection[2],
|
|
transform.selection[3]));
|
|
}
|
|
}
|
|
|
|
var lineState = session.getState(cursor.row);
|
|
|
|
// TODO disabled multiline auto indent
|
|
// possibly doing the indent before inserting the text
|
|
// if (cursor.row !== end.row) {
|
|
if (session.getDocument().isNewLine(text)) {
|
|
this.moveCursorTo(cursor.row+1, 0);
|
|
|
|
var size = session.getTabSize();
|
|
var minIndent = Number.MAX_VALUE;
|
|
|
|
for (var row = cursor.row + 1; row <= end.row; ++row) {
|
|
var indent = 0;
|
|
|
|
line = session.getLine(row);
|
|
for (var i = 0; i < line.length; ++i)
|
|
if (line.charAt(i) == '\t')
|
|
indent += size;
|
|
else if (line.charAt(i) == ' ')
|
|
indent += 1;
|
|
else
|
|
break;
|
|
if (/[^\s]/.test(line))
|
|
minIndent = Math.min(indent, minIndent);
|
|
}
|
|
|
|
for (var row = cursor.row + 1; row <= end.row; ++row) {
|
|
var outdent = minIndent;
|
|
|
|
line = session.getLine(row);
|
|
for (var i = 0; i < line.length && outdent > 0; ++i)
|
|
if (line.charAt(i) == '\t')
|
|
outdent -= size;
|
|
else if (line.charAt(i) == ' ')
|
|
outdent -= 1;
|
|
session.remove(new Range(row, 0, row, i));
|
|
}
|
|
session.indentRows(cursor.row + 1, end.row, lineIndent);
|
|
} else {
|
|
if (shouldOutdent) {
|
|
mode.autoOutdent(lineState, session, cursor.row);
|
|
}
|
|
}
|
|
};
|
|
|
|
this.onTextInput = function(text) {
|
|
// In case we got only one character, then
|
|
// handel it as a command key stroke.
|
|
if (text.length == 1) {
|
|
// Note: The `null` as `keyCode` is important here, as there are
|
|
// some checks in the code for `keyCode == 0` meaning the text comes
|
|
// from the keyBinding.onTextInput code path.
|
|
var handled = this.keyBinding.onCommandKey({}, 0, null, text);
|
|
|
|
// Check if the text was handled. If not, then handled it as "normal"
|
|
// text and insert it to the editor directly. This shouldn't be done
|
|
// using the this.keyBinding.onTextInput(text) function, as it would
|
|
// make the `text` get sent to the keyboardHandler twice, which might
|
|
// turn out to be a bad thing in case there is a custome keyboard
|
|
// handler like the StateHandler.
|
|
if (!handled) {
|
|
this.insert(text);
|
|
}
|
|
} else {
|
|
this.keyBinding.onTextInput(text);
|
|
}
|
|
};
|
|
|
|
this.onPaste = function(text) {
|
|
this._emit("paste", text);
|
|
this.keyBinding.onTextInput(text);
|
|
};
|
|
|
|
this.onCommandKey = function(e, hashId, keyCode) {
|
|
this.keyBinding.onCommandKey(e, hashId, keyCode);
|
|
};
|
|
|
|
this.setOverwrite = function(overwrite) {
|
|
this.session.setOverwrite(overwrite);
|
|
};
|
|
|
|
this.getOverwrite = function() {
|
|
return this.session.getOverwrite();
|
|
};
|
|
|
|
this.toggleOverwrite = function() {
|
|
this.session.toggleOverwrite();
|
|
};
|
|
|
|
this.setScrollSpeed = function(speed) {
|
|
this.$mouseHandler.setScrollSpeed(speed);
|
|
};
|
|
|
|
this.getScrollSpeed = function() {
|
|
return this.$mouseHandler.getScrollSpeed()
|
|
};
|
|
|
|
this.setSelectionStyle = function(style) {
|
|
this.windowModel.setSelectionStyle(style);
|
|
};
|
|
|
|
this.getSelectionStyle = function() {
|
|
return this.windowModel.getSelectionStyle();
|
|
};
|
|
|
|
this.setHighlightActiveLine = function(shouldHighlight) {
|
|
this.windowModel.setHighlightActiveLine(shouldHighlight);
|
|
};
|
|
|
|
this.getHighlightActiveLine = function() {
|
|
return this.windowModel.getHighlightActiveLine();
|
|
};
|
|
|
|
this.setHighlightSelectedWord = function(shouldHighlight) {
|
|
this.windowModel.setHighlightSelectedWord(shouldHighlight);
|
|
};
|
|
|
|
this.getHighlightSelectedWord = function() {
|
|
return this.windowModel.getHighlightSelectedWord();
|
|
};
|
|
|
|
this.setShowInvisibles = function(showInvisibles) {
|
|
this.windowModel.setShowInvisibles(showInvisibles);
|
|
};
|
|
|
|
this.getShowInvisibles = function() {
|
|
return this.windowModel.getShowInvisibles();
|
|
};
|
|
|
|
this.setShowPrintMargin = function(showPrintMargin) {
|
|
this.windowModel.setShowPrintMargin(showPrintMargin);
|
|
};
|
|
|
|
this.getShowPrintMargin = function() {
|
|
return this.windowModel.getShowPrintMargin();
|
|
};
|
|
|
|
this.setPrintMarginColumn = function(showPrintMargin) {
|
|
this.windowModel.setPrintMarginColumn(showPrintMargin);
|
|
};
|
|
|
|
this.getPrintMarginColumn = function() {
|
|
return this.windowModel.getPrintMarginColumn();
|
|
};
|
|
|
|
this.setShowGutter = function(showGutter) {
|
|
this.windowModel.setShowGutter(showGutter);
|
|
};
|
|
|
|
this.getShowGutter = function() {
|
|
return this.windowModel.getShowGutter();
|
|
};
|
|
|
|
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
|
|
this.windowModel.setHScrollBarAlwaysVisible(alwaysVisible);
|
|
};
|
|
|
|
this.getHScrollBarAlwaysVisible = function() {
|
|
return this.windowModel.getHScrollBarAlwaysVisible();
|
|
};
|
|
|
|
this.$readOnly = false;
|
|
this.setReadOnly = function(readOnly) {
|
|
this.$readOnly = readOnly;
|
|
};
|
|
|
|
this.getReadOnly = function() {
|
|
return this.$readOnly;
|
|
};
|
|
|
|
this.$modeBehaviours = true;
|
|
this.setBehavioursEnabled = function (enabled) {
|
|
this.$modeBehaviours = enabled;
|
|
}
|
|
|
|
this.getBehavioursEnabled = function () {
|
|
return this.$modeBehaviours;
|
|
}
|
|
|
|
this.removeRight = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty()) {
|
|
this.selection.selectRight();
|
|
}
|
|
this.session.remove(this.getSelectionRange())
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.removeLeft = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty())
|
|
this.selection.selectLeft();
|
|
|
|
var range = this.getSelectionRange();
|
|
if (this.getBehavioursEnabled()) {
|
|
var session = this.session;
|
|
var state = session.getState(range.start.row);
|
|
var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
|
|
if (new_range !== false) {
|
|
range = new_range;
|
|
}
|
|
}
|
|
|
|
this.session.remove(range);
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.removeWordRight = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty())
|
|
this.selection.selectWordRight();
|
|
|
|
this.session.remove(this.getSelectionRange());
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.removeWordLeft = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty())
|
|
this.selection.selectWordLeft();
|
|
|
|
this.session.remove(this.getSelectionRange());
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.removeToLineStart = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty())
|
|
this.selection.selectLineStart();
|
|
|
|
this.session.remove(this.getSelectionRange());
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.removeToLineEnd = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (this.selection.isEmpty())
|
|
this.selection.selectLineEnd();
|
|
|
|
var range = this.getSelectionRange();
|
|
if (range.start.column == range.end.column && range.start.row == range.end.row) {
|
|
range.end.column = 0;
|
|
range.end.row++;
|
|
}
|
|
|
|
this.session.remove(range);
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.splitLine = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (!this.selection.isEmpty()) {
|
|
this.session.remove(this.getSelectionRange());
|
|
this.clearSelection();
|
|
}
|
|
|
|
var cursor = this.getCursorPosition();
|
|
this.insert("\n");
|
|
this.moveCursorToPosition(cursor);
|
|
};
|
|
|
|
this.transposeLetters = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
if (!this.selection.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
var cursor = this.getCursorPosition();
|
|
var column = cursor.column;
|
|
if (column == 0)
|
|
return;
|
|
|
|
var line = this.session.getLine(cursor.row);
|
|
if (column < line.length) {
|
|
var swap = line.charAt(column) + line.charAt(column-1);
|
|
var range = new Range(cursor.row, column-1, cursor.row, column+1)
|
|
}
|
|
else {
|
|
var swap = line.charAt(column-1) + line.charAt(column-2);
|
|
var range = new Range(cursor.row, column-2, cursor.row, column)
|
|
}
|
|
this.session.replace(range, swap);
|
|
};
|
|
|
|
this.indent = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var session = this.session;
|
|
var range = this.getSelectionRange();
|
|
|
|
if (range.start.row < range.end.row || range.start.column < range.end.column) {
|
|
var rows = this.$getSelectedRows();
|
|
session.indentRows(rows.first, rows.last, "\t");
|
|
} else {
|
|
var indentString;
|
|
|
|
if (this.session.getUseSoftTabs()) {
|
|
var size = session.getTabSize(),
|
|
position = this.getCursorPosition(),
|
|
column = session.documentToScreenColumn(position.row, position.column),
|
|
count = (size - column % size);
|
|
|
|
indentString = lang.stringRepeat(" ", count);
|
|
} else
|
|
indentString = "\t";
|
|
return this.onTextInput(indentString);
|
|
}
|
|
};
|
|
|
|
this.blockOutdent = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var selection = this.session.getSelection();
|
|
this.session.outdentRows(selection.getRange());
|
|
};
|
|
|
|
this.toggleCommentLines = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var state = this.session.getState(this.getCursorPosition().row);
|
|
var rows = this.$getSelectedRows()
|
|
this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
|
|
};
|
|
|
|
this.removeLines = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
var rows = this.$getSelectedRows();
|
|
if (rows.last == 0 || rows.last+1 < this.session.getLength())
|
|
var range = new Range(rows.first, 0, rows.last+1, 0)
|
|
else
|
|
var range = new Range(
|
|
rows.first-1, this.session.getLine(rows.first-1).length,
|
|
rows.last, this.session.getLine(rows.last).length
|
|
);
|
|
this.session.remove(range);
|
|
this.clearSelection();
|
|
};
|
|
|
|
this.moveLinesDown = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
this.$moveLines(function(firstRow, lastRow) {
|
|
return this.session.moveLinesDown(firstRow, lastRow);
|
|
});
|
|
};
|
|
|
|
this.moveLinesUp = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
this.$moveLines(function(firstRow, lastRow) {
|
|
return this.session.moveLinesUp(firstRow, lastRow);
|
|
});
|
|
};
|
|
|
|
this.moveText = function(range, toPosition) {
|
|
if (this.$readOnly)
|
|
return null;
|
|
|
|
return this.session.moveText(range, toPosition);
|
|
};
|
|
|
|
this.copyLinesUp = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
this.$moveLines(function(firstRow, lastRow) {
|
|
this.session.duplicateLines(firstRow, lastRow);
|
|
return 0;
|
|
});
|
|
};
|
|
|
|
this.copyLinesDown = function() {
|
|
if (this.$readOnly)
|
|
return;
|
|
|
|
this.$moveLines(function(firstRow, lastRow) {
|
|
return this.session.duplicateLines(firstRow, lastRow);
|
|
});
|
|
};
|
|
|
|
|
|
this.$moveLines = function(mover) {
|
|
var rows = this.$getSelectedRows();
|
|
|
|
var linesMoved = mover.call(this, rows.first, rows.last);
|
|
|
|
var selection = this.selection;
|
|
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
|
|
selection.$moveSelection(function() {
|
|
selection.moveCursorTo(rows.first+linesMoved, 0);
|
|
});
|
|
};
|
|
|
|
this.$getSelectedRows = function() {
|
|
var range = this.getSelectionRange().collapseRows();
|
|
|
|
return {
|
|
first: range.start.row,
|
|
last: range.end.row
|
|
};
|
|
};
|
|
|
|
this.onCompositionStart = function(text) {
|
|
this.renderer.showComposition(this.getCursorPosition());
|
|
};
|
|
|
|
this.onCompositionUpdate = function(text) {
|
|
this.renderer.setCompositionText(text);
|
|
};
|
|
|
|
this.onCompositionEnd = function() {
|
|
this.renderer.hideComposition();
|
|
};
|
|
|
|
this.getFirstVisibleRow = function() {
|
|
return this.windowModel.getFirstVisibleRow();
|
|
};
|
|
|
|
this.getLastVisibleRow = function() {
|
|
return this.windowModel.getLastVisibleRow();
|
|
};
|
|
|
|
this.isRowVisible = function(row) {
|
|
return this.windowModel.isRowVisible(row);
|
|
};
|
|
|
|
this.$getVisibleRowCount = function() {
|
|
return this.windowModel.getVisibleRowCount();
|
|
};
|
|
|
|
this.$getPageDownRow = function() {
|
|
return this.windowModel.getPageDownRow();
|
|
};
|
|
|
|
this.$getPageUpRow = function() {
|
|
return this.windowModel.getPageUpRow();
|
|
};
|
|
|
|
this.selectPageDown = function() {
|
|
var row = this.$getPageDownRow() + Math.floor(this.$getVisibleRowCount() / 2);
|
|
|
|
this.scrollPageDown();
|
|
|
|
var selection = this.getSelection();
|
|
var leadScreenPos = this.session.documentToScreenPosition(selection.getSelectionLead());
|
|
var dest = this.session.screenToDocumentPosition(row, leadScreenPos.column);
|
|
selection.selectTo(dest.row, dest.column);
|
|
};
|
|
|
|
this.selectPageUp = function() {
|
|
var visibleRows = this.windowModel.getScrollTopRow() - this.windowModel.getScrollBottomRow();
|
|
var row = this.$getPageUpRow() + Math.round(visibleRows / 2);
|
|
|
|
this.scrollPageUp();
|
|
|
|
var selection = this.getSelection();
|
|
var leadScreenPos = this.session.documentToScreenPosition(selection.getSelectionLead());
|
|
var dest = this.session.screenToDocumentPosition(row, leadScreenPos.column);
|
|
selection.selectTo(dest.row, dest.column);
|
|
};
|
|
|
|
this.gotoPageDown = function() {
|
|
var row = this.$getPageDownRow();
|
|
var column = this.getCursorPositionScreen().column;
|
|
|
|
this.scrollToRow(row);
|
|
this.getSelection().moveCursorToScreen(row, column);
|
|
};
|
|
|
|
this.gotoPageUp = function() {
|
|
var row = this.$getPageUpRow();
|
|
var column = this.getCursorPositionScreen().column;
|
|
|
|
this.scrollToRow(row);
|
|
this.getSelection().moveCursorToScreen(row, column);
|
|
};
|
|
|
|
this.scrollPageDown = function() {
|
|
this.scrollToRow(this.$getPageDownRow());
|
|
};
|
|
|
|
this.scrollPageUp = function() {
|
|
this.windowModel.scrollToRow(this.$getPageUpRow());
|
|
};
|
|
|
|
this.scrollToRow = function(row) {
|
|
this.windowModel.scrollToRow(row);
|
|
};
|
|
|
|
this.scrollToLine = function(line, center) {
|
|
this.windowModel.scrollToLine(line, center);
|
|
};
|
|
|
|
this.centerSelection = function() {
|
|
this.windowModel.centerSelection();
|
|
};
|
|
|
|
this.getCursorPosition = function() {
|
|
return this.windowModel.getCursorPosition();
|
|
};
|
|
|
|
this.getCursorPositionScreen = function() {
|
|
return this.windowModel.getCursorPositionScreen();
|
|
};
|
|
|
|
this.getSelectionRange = function() {
|
|
return this.windowModel.getSelectionRange();
|
|
};
|
|
|
|
this.selectAll = function() {
|
|
this.windowModel.selectAll();
|
|
};
|
|
|
|
this.clearSelection = function() {
|
|
this.windowModel.clearSelection();
|
|
};
|
|
|
|
this.moveCursorTo = function(row, column) {
|
|
this.windowModel.moveCursorTo(row, column);
|
|
};
|
|
|
|
this.moveCursorToPosition = function(pos) {
|
|
this.windowModel.moveCursorToPosition(pos);
|
|
};
|
|
|
|
|
|
this.gotoLine = function(lineNumber, column) {
|
|
this.windowModel.gotoLine(lineNumber, column);
|
|
};
|
|
|
|
this.navigateTo = function(row, column) {
|
|
this.windowModel.navigateTo(row, column);
|
|
};
|
|
|
|
this.navigateUp = function(times) {
|
|
this.windowModel.navigateUp(times);
|
|
};
|
|
|
|
this.navigateDown = function(times) {
|
|
this.windowModel.navigateDown(times);
|
|
};
|
|
|
|
this.navigateLeft = function(times) {
|
|
this.windowModel.navigateLeft(times);
|
|
};
|
|
|
|
this.navigateRight = function(times) {
|
|
this.windowModel.navigateRight(times);
|
|
};
|
|
|
|
this.navigateLineStart = function() {
|
|
this.windowModel.navigateLineStart()
|
|
};
|
|
|
|
this.navigateLineEnd = function() {
|
|
this.windowModel.navigateLineEnd();
|
|
};
|
|
|
|
this.navigateFileEnd = function() {
|
|
this.windowModel.navigateFileEnd();
|
|
};
|
|
|
|
this.navigateFileStart = function() {
|
|
this.windowModel.navigateFileStart();
|
|
};
|
|
|
|
this.navigateWordRight = function() {
|
|
this.windowModel.navigateWordRight();
|
|
};
|
|
|
|
this.navigateWordLeft = function() {
|
|
this.windowModel.navigateWordLeft();
|
|
};
|
|
|
|
this.replace = function(replacement, options) {
|
|
this.windowModel.replace(replace, options);
|
|
};
|
|
|
|
this.replaceAll = function(replacement, options) {
|
|
this.windowModel.replaceAll(replaceAll, options);
|
|
};
|
|
|
|
this.getLastSearchOptions = function() {
|
|
return this.windowModel.getLastSearchOptions();
|
|
};
|
|
|
|
this.find = function(needle, options) {
|
|
this.windowModel.find(needle, options);
|
|
};
|
|
|
|
this.findNext = function(options) {
|
|
this.windowModel.findNext(options);
|
|
};
|
|
|
|
this.findPrevious = function(options) {
|
|
this.windowModel.findPrevious(options);
|
|
};
|
|
|
|
this.undo = function() {
|
|
this.session.getUndoManager().undo();
|
|
};
|
|
|
|
this.redo = function() {
|
|
this.session.getUndoManager().redo();
|
|
};
|
|
|
|
this.destroy = function() {
|
|
this.renderer.destroy();
|
|
}
|
|
|
|
}).call(Editor.prototype);
|
|
|
|
|
|
exports.Editor = Editor;
|
|
});
|