revert changes to worker

This commit is contained in:
nightwing 2013-04-12 12:09:15 +04:00
commit dc198344d5
7 changed files with 186 additions and 196 deletions

View file

@ -8,7 +8,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter;
/** /**
* @class CommandManager * @class CommandManager
* *
* *
**/ **/
/** /**
@ -24,7 +24,7 @@ var CommandManager = function(platform, commands) {
this.commmandKeyBinding = {}; this.commmandKeyBinding = {};
this.addCommands(commands); this.addCommands(commands);
this.setDefaultHandler("exec", function(e) { this.setDefaultHandler("exec", function(e) {
return e.command.exec(e.editor, e.args || {}); return e.command.exec(e.editor, e.args || {});
}); });

View file

@ -3,7 +3,7 @@
* *
* Copyright (c) 2010, Ajax.org B.V. * Copyright (c) 2010, Ajax.org B.V.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -46,16 +46,15 @@ var Search = require("./search").Search;
var Range = require("./range").Range; var Range = require("./range").Range;
var EventEmitter = require("./lib/event_emitter").EventEmitter; var EventEmitter = require("./lib/event_emitter").EventEmitter;
var CommandManager = require("./commands/command_manager").CommandManager; var CommandManager = require("./commands/command_manager").CommandManager;
var Autocomplete = require("./autocomplete").Autocomplete;
var defaultCommands = require("./commands/default_commands").commands; var defaultCommands = require("./commands/default_commands").commands;
var config = require("./config"); 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. * 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 * @class Editor
@ -90,7 +89,6 @@ var Editor = function(renderer, session) {
}); });
this.setSession(session || new EditSession("")); this.setSession(session || new EditSession(""));
Autocomplete.addTo(this);
config.resetOptions(this); config.resetOptions(this);
config._emit("editor", this); config._emit("editor", this);
}; };
@ -103,7 +101,7 @@ var Editor = function(renderer, session) {
* Sets a new key handler, such as "vim" or "windows". * Sets a new key handler, such as "vim" or "windows".
* @param {String} keyboardHandler The new key handler * @param {String} keyboardHandler The new key handler
* *
* *
**/ **/
this.setKeyboardHandler = function(keyboardHandler) { this.setKeyboardHandler = function(keyboardHandler) {
if (!keyboardHandler) { if (!keyboardHandler) {
@ -121,11 +119,11 @@ var Editor = function(renderer, session) {
} }
}; };
/** /**
* Returns the keyboard handler, such as "vim" or "windows". * Returns the keyboard handler, such as "vim" or "windows".
* *
* @returns {String} * @returns {String}
* *
**/ **/
this.getKeyboardHandler = function() { this.getKeyboardHandler = function() {
return this.keyBinding.getKeyboardHandler(); return this.keyBinding.getKeyboardHandler();
@ -252,7 +250,7 @@ var Editor = function(renderer, session) {
return this.session; return this.session;
}; };
/** /**
* Sets the current document to `val`. * Sets the current document to `val`.
* @param {String} val The new value to set for the document * @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 * @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
@ -273,7 +271,7 @@ var Editor = function(renderer, session) {
return val; return val;
}; };
/** /**
* Returns the current session's content. * Returns the current session's content.
* *
* @returns {String} * @returns {String}
@ -284,7 +282,7 @@ var Editor = function(renderer, session) {
}; };
/** /**
* *
* Returns the currently highlighted selection. * Returns the currently highlighted selection.
* @returns {String} The highlighted selection * @returns {String} The highlighted selection
**/ **/
@ -292,11 +290,11 @@ var Editor = function(renderer, session) {
return this.selection; return this.selection;
}; };
/** /**
* {:VirtualRenderer.onResize} * {:VirtualRenderer.onResize}
* @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed
* *
* *
* @related VirtualRenderer.onResize * @related VirtualRenderer.onResize
**/ **/
this.resize = function(force) { this.resize = function(force) {
@ -313,9 +311,9 @@ var Editor = function(renderer, session) {
this.renderer.setTheme(theme); this.renderer.setTheme(theme);
}; };
/** /**
* {:VirtualRenderer.getTheme} * {:VirtualRenderer.getTheme}
* *
* @returns {String} The set theme * @returns {String} The set theme
* @related VirtualRenderer.getTheme * @related VirtualRenderer.getTheme
**/ **/
@ -327,14 +325,14 @@ var Editor = function(renderer, session) {
* {:VirtualRenderer.setStyle} * {:VirtualRenderer.setStyle}
* @param {String} style A class name * @param {String} style A class name
* *
* *
* @related VirtualRenderer.setStyle * @related VirtualRenderer.setStyle
**/ **/
this.setStyle = function(style) { this.setStyle = function(style) {
this.renderer.setStyle(style); this.renderer.setStyle(style);
}; };
/** /**
* {:VirtualRenderer.unsetStyle} * {:VirtualRenderer.unsetStyle}
* @related VirtualRenderer.unsetStyle * @related VirtualRenderer.unsetStyle
**/ **/
@ -353,8 +351,8 @@ var Editor = function(renderer, session) {
/** /**
* Set a new font size (in pixels) for the editor text. * Set a new font size (in pixels) for the editor text.
* @param {String} size A font size ( _e.g._ "12px") * @param {String} size A font size ( _e.g._ "12px")
* *
* *
**/ **/
this.setFontSize = function(size) { this.setFontSize = function(size) {
this.setOption("fontSize", size); this.setOption("fontSize", size);
@ -388,7 +386,7 @@ var Editor = function(renderer, session) {
}; };
/** /**
* *
* Brings the current `textInput` into focus. * Brings the current `textInput` into focus.
**/ **/
this.focus = function() { this.focus = function() {
@ -411,7 +409,7 @@ var Editor = function(renderer, session) {
}; };
/** /**
* *
* Blurs the current `textInput`. * Blurs the current `textInput`.
**/ **/
this.blur = function() { this.blur = function() {
@ -420,9 +418,9 @@ var Editor = function(renderer, session) {
/** /**
* Emitted once the editor comes into focus. * Emitted once the editor comes into focus.
* @event focus * @event focus
* *
* *
**/ **/
this.onFocus = function() { this.onFocus = function() {
if (this.$isFocused) if (this.$isFocused)
@ -436,8 +434,8 @@ var Editor = function(renderer, session) {
/** /**
* Emitted once the editor has been blurred. * Emitted once the editor has been blurred.
* @event blur * @event blur
* *
* *
**/ **/
this.onBlur = function() { this.onBlur = function() {
if (!this.$isFocused) if (!this.$isFocused)
@ -453,12 +451,12 @@ var Editor = function(renderer, session) {
}; };
/** /**
* Emitted whenever the document is changed. * Emitted whenever the document is changed.
* @event change * @event change
* @param {Object} e Contains a single property, `data`, which has the delta of changes * @param {Object} e Contains a single property, `data`, which has the delta of changes
* *
* *
* *
**/ **/
this.onDocumentChange = function(e) { this.onDocumentChange = function(e) {
var delta = e.data; var delta = e.data;
@ -486,14 +484,14 @@ var Editor = function(renderer, session) {
this.onScrollTopChange = function() { this.onScrollTopChange = function() {
this.renderer.scrollToY(this.session.getScrollTop()); this.renderer.scrollToY(this.session.getScrollTop());
}; };
this.onScrollLeftChange = function() { this.onScrollLeftChange = function() {
this.renderer.scrollToX(this.session.getScrollLeft()); this.renderer.scrollToX(this.session.getScrollLeft());
}; };
/** /**
* Emitted when the selection changes. * Emitted when the selection changes.
* *
**/ **/
this.onCursorChange = function() { this.onCursorChange = function() {
this.$cursorChange(); this.$cursorChange();
@ -549,7 +547,7 @@ var Editor = function(renderer, session) {
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp() var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
this.session.highlight(re); this.session.highlight(re);
this._emit("changeSelection"); this._emit("changeSelection");
}; };
@ -629,10 +627,10 @@ var Editor = function(renderer, session) {
/** /**
* Emitted when text is copied. * Emitted when text is copied.
* @event copy * @event copy
* @param {String} text The copied text * @param {String} text The copied text
* *
* *
**/ **/
/** /**
* *
@ -678,7 +676,7 @@ var Editor = function(renderer, session) {
**/ **/
this.onPaste = function(text) { this.onPaste = function(text) {
// 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;
this._emit("paste", text); this._emit("paste", text);
this.insert(text); this.insert(text);
@ -692,8 +690,8 @@ var Editor = function(renderer, session) {
/** /**
* Inserts `text` into wherever the cursor is pointing. * Inserts `text` into wherever the cursor is pointing.
* @param {String} text The new text to add * @param {String} text The new text to add
* *
* *
**/ **/
this.insert = function(text) { this.insert = function(text) {
var session = this.session; var session = this.session;
@ -793,10 +791,10 @@ var Editor = function(renderer, session) {
this.keyBinding.onCommandKey(e, hashId, keyCode); 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. * 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 * @param {Boolean} overwrite Defines wheter or not to set overwrites
* *
* *
* @related EditSession.setOverwrite * @related EditSession.setOverwrite
**/ **/
@ -804,7 +802,7 @@ var Editor = function(renderer, session) {
this.session.setOverwrite(overwrite); this.session.setOverwrite(overwrite);
}; };
/** /**
* Returns `true` if overwrites are enabled; `false` otherwise. * Returns `true` if overwrites are enabled; `false` otherwise.
* @returns {Boolean} * @returns {Boolean}
* @related EditSession.getOverwrite * @related EditSession.getOverwrite
@ -813,7 +811,7 @@ var Editor = function(renderer, session) {
return this.session.getOverwrite(); return this.session.getOverwrite();
}; };
/** /**
* Sets the value of overwrite to the opposite of whatever it currently is. * Sets the value of overwrite to the opposite of whatever it currently is.
* @related EditSession.toggleOverwrite * @related EditSession.toggleOverwrite
**/ **/
@ -861,7 +859,7 @@ var Editor = function(renderer, session) {
/** /**
* Draw selection markers spanning whole line, or only over selected text. Default value is "line" * Draw selection markers spanning whole line, or only over selected text. Default value is "line"
* @param {String} style The new selection style "line"|"text" * @param {String} style The new selection style "line"|"text"
* *
**/ **/
this.setSelectionStyle = function(val) { this.setSelectionStyle = function(val) {
this.setOption("selectionStyle", val); this.setOption("selectionStyle", val);
@ -924,7 +922,7 @@ var Editor = function(renderer, session) {
/** /**
* If `showInvisibles` is set to `true`, invisible characters—like spaces or new lines—are show in the editor. * If `showInvisibles` 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 * @param {Boolean} showInvisibles Specifies whether or not to show invisible characters
* *
**/ **/
this.setShowInvisibles = function(showInvisibles) { this.setShowInvisibles = function(showInvisibles) {
this.renderer.setShowInvisibles(showInvisibles); this.renderer.setShowInvisibles(showInvisibles);
@ -949,7 +947,7 @@ var Editor = function(renderer, session) {
/** /**
* If `showPrintMargin` is set to `true`, the print margin is shown in the editor. * 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 * @param {Boolean} showPrintMargin Specifies whether or not to show the print margin
* *
**/ **/
this.setShowPrintMargin = function(showPrintMargin) { this.setShowPrintMargin = function(showPrintMargin) {
this.renderer.setShowPrintMargin(showPrintMargin); this.renderer.setShowPrintMargin(showPrintMargin);
@ -983,7 +981,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. * 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 * @param {Boolean} readOnly Specifies whether the editor can be modified or not
* *
**/ **/
this.setReadOnly = function(readOnly) { this.setReadOnly = function(readOnly) {
this.setOption("readOnly", readOnly); this.setOption("readOnly", readOnly);
@ -1000,7 +998,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} * 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 * @param {Boolean} enabled Enables or disables behaviors
* *
**/ **/
this.setBehavioursEnabled = function (enabled) { this.setBehavioursEnabled = function (enabled) {
this.setOption("behavioursEnabled", enabled); this.setOption("behavioursEnabled", enabled);
@ -1008,7 +1006,7 @@ var Editor = function(renderer, session) {
/** /**
* Returns `true` if the behaviors are currently enabled. {:BehaviorsDef} * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef}
* *
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.getBehavioursEnabled = function () { this.getBehavioursEnabled = function () {
@ -1019,7 +1017,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 * 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. * when such a character is typed in.
* @param {Boolean} enabled Enables or disables wrapping behaviors * @param {Boolean} enabled Enables or disables wrapping behaviors
* *
**/ **/
this.setWrapBehavioursEnabled = function (enabled) { this.setWrapBehavioursEnabled = function (enabled) {
this.setOption("wrapBehavioursEnabled", enabled); this.setOption("wrapBehavioursEnabled", enabled);
@ -1059,7 +1057,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. * 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" * @param {String} dir The direction of the deletion to occur, either "left" or "right"
* *
**/ **/
this.remove = function(dir) { this.remove = function(dir) {
if (this.selection.isEmpty()){ if (this.selection.isEmpty()){
@ -1204,7 +1202,7 @@ var Editor = function(renderer, session) {
/** /**
* Inserts an indentation into the current cursor position or indents the selected lines. * Inserts an indentation into the current cursor position or indents the selected lines.
* *
* @related EditSession.indentRows * @related EditSession.indentRows
**/ **/
this.indent = function() { this.indent = function() {
@ -1311,7 +1309,7 @@ var Editor = function(renderer, session) {
} }
return null; return null;
}; };
/** /**
* If the character before the cursor is a number, this functions changes its value by `amount`. * 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) * @param {Number} amount The value to change the numeral by (can be negative to decrease value)
@ -1336,14 +1334,14 @@ var Editor = function(renderer, session) {
var t = parseFloat(nr.value); var t = parseFloat(nr.value);
t *= Math.pow(10, decimals); t *= Math.pow(10, decimals);
if(fp !== nr.end && column < fp){ if(fp !== nr.end && column < fp){
amount *= Math.pow(10, nr.end - column - 1); amount *= Math.pow(10, nr.end - column - 1);
} else { } else {
amount *= Math.pow(10, nr.end - column); amount *= Math.pow(10, nr.end - column);
} }
t += amount; t += amount;
t /= Math.pow(10, decimals); t /= Math.pow(10, decimals);
var nnr = t.toFixed(decimals); var nnr = t.toFixed(decimals);
@ -1358,8 +1356,8 @@ var Editor = function(renderer, session) {
} }
} }
}; };
/** /**
* Removes all the lines in the current selection * Removes all the lines in the current selection
* @related EditSession.remove * @related EditSession.remove
**/ **/
@ -1390,12 +1388,12 @@ var Editor = function(renderer, session) {
var endPoint = doc.insert(point, doc.getTextRange(range), false); var endPoint = doc.insert(point, doc.getTextRange(range), false);
range.start = point; range.start = point;
range.end = endPoint; range.end = endPoint;
sel.setSelectionRange(range, reverse) sel.setSelectionRange(range, reverse)
} }
}; };
/** /**
* Shifts all the selected lines down one row. * Shifts all the selected lines down one row.
* *
* @returns {Number} On success, it returns -1. * @returns {Number} On success, it returns -1.
@ -1407,7 +1405,7 @@ var Editor = function(renderer, session) {
}); });
}; };
/** /**
* Shifts all the selected lines up one row. * Shifts all the selected lines up one row.
* @returns {Number} On success, it returns -1. * @returns {Number} On success, it returns -1.
* @related EditSession.moveLinesDown * @related EditSession.moveLinesDown
@ -1418,14 +1416,14 @@ 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: * Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this:
* ```json * ```json
* { row: newRowLocation, column: newColumnLocation } * { row: newRowLocation, column: newColumnLocation }
* ``` * ```
* @param {Range} fromRange The range of text you want moved within the document * @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 * @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. * @returns {Range} The new range where the text was moved to.
* @related EditSession.moveText * @related EditSession.moveText
**/ **/
@ -1433,10 +1431,10 @@ var Editor = function(renderer, session) {
return this.session.moveText(range, toPosition); return this.session.moveText(range, toPosition);
}; };
/** /**
* Copies all the selected lines up one row. * Copies all the selected lines up one row.
* @returns {Number} On success, returns 0. * @returns {Number} On success, returns 0.
* *
**/ **/
this.copyLinesUp = function() { this.copyLinesUp = function() {
this.$moveLines(function(firstRow, lastRow) { this.$moveLines(function(firstRow, lastRow) {
@ -1445,7 +1443,7 @@ var Editor = function(renderer, session) {
}); });
}; };
/** /**
* Copies all the selected lines down one row. * 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`. * @returns {Number} On success, returns the number of new rows added; in other words, `lastRow - firstRow + 1`.
* @related EditSession.duplicateLines * @related EditSession.duplicateLines
@ -1460,7 +1458,7 @@ 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. * 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 * @param {Function} mover A method to call on each selected row
* *
* *
**/ **/
this.$moveLines = function(mover) { this.$moveLines = function(mover) {
@ -1468,7 +1466,7 @@ var Editor = function(renderer, session) {
if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) { if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
var range = selection.toOrientedRange(); var range = selection.toOrientedRange();
var rows = this.$getSelectedRows(range); var rows = this.$getSelectedRows(range);
var linesMoved = mover.call(this, rows.first, rows.last); var linesMoved = mover.call(this, rows.first, rows.last);
range.moveBy(linesMoved, 0); range.moveBy(linesMoved, 0);
selection.fromOrientedRange(range); selection.fromOrientedRange(range);
} else { } else {
@ -1486,14 +1484,14 @@ var Editor = function(renderer, session) {
first = rows.end.row; first = rows.end.row;
else else
break; break;
} }
i++; i++;
var linesMoved = mover.call(this, first, last); var linesMoved = mover.call(this, first, last);
while (rangeIndex >= i) { while (rangeIndex >= i) {
ranges[rangeIndex].moveBy(linesMoved, 0); ranges[rangeIndex].moveBy(linesMoved, 0);
rangeIndex--; rangeIndex--;
} }
} }
selection.fromOrientedRange(selection.ranges[0]); selection.fromOrientedRange(selection.ranges[0]);
selection.rangeList.attach(this.session); selection.rangeList.attach(this.session);
@ -1530,7 +1528,7 @@ var Editor = function(renderer, session) {
this.renderer.hideComposition(); this.renderer.hideComposition();
}; };
/** /**
* {:VirtualRenderer.getFirstVisibleRow} * {:VirtualRenderer.getFirstVisibleRow}
* *
* @returns {Number} * @returns {Number}
@ -1540,7 +1538,7 @@ var Editor = function(renderer, session) {
return this.renderer.getFirstVisibleRow(); return this.renderer.getFirstVisibleRow();
}; };
/** /**
* {:VirtualRenderer.getLastVisibleRow} * {:VirtualRenderer.getLastVisibleRow}
* *
* @returns {Number} * @returns {Number}
@ -1553,7 +1551,7 @@ var Editor = function(renderer, session) {
/** /**
* Indicates if the row is currently visible on the screen. * Indicates if the row is currently visible on the screen.
* @param {Number} row The row to check * @param {Number} row The row to check
* *
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.isRowVisible = function(row) { this.isRowVisible = function(row) {
@ -1563,8 +1561,8 @@ var Editor = function(renderer, session) {
/** /**
* Indicates if the entire row is currently visible on the screen. * Indicates if the entire row is currently visible on the screen.
* @param {Number} row The row to check * @param {Number} row The row to check
* *
* *
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.isRowFullyVisible = function(row) { this.isRowFullyVisible = function(row) {
@ -1646,7 +1644,7 @@ var Editor = function(renderer, session) {
this.$moveByPage(-1); this.$moveByPage(-1);
}; };
/** /**
* Moves the editor to the specified row. * Moves the editor to the specified row.
* @related VirtualRenderer.scrollToRow * @related VirtualRenderer.scrollToRow
**/ **/
@ -1654,14 +1652,14 @@ var Editor = function(renderer, session) {
this.renderer.scrollToRow(row); this.renderer.scrollToRow(row);
}; };
/** /**
* Scrolls to a line. If `center` is `true`, it puts the line in middle of screen (or attempts to). * 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 {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 {Boolean} animate If `true` animates scrolling
* @param {Function} callback Function to be called when the animation has finished * @param {Function} callback Function to be called when the animation has finished
* *
* *
* @related VirtualRenderer.scrollToLine * @related VirtualRenderer.scrollToLine
**/ **/
this.scrollToLine = function(line, center, animate, callback) { this.scrollToLine = function(line, center, animate, callback) {
@ -1680,9 +1678,9 @@ var Editor = function(renderer, session) {
this.renderer.alignCursor(pos, 0.5); this.renderer.alignCursor(pos, 0.5);
}; };
/** /**
* Gets the current position of the cursor. * 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 * ```json
* { row: currRow, column: currCol } * { row: currRow, column: currCol }
@ -1694,7 +1692,7 @@ var Editor = function(renderer, session) {
return this.selection.getCursor(); return this.selection.getCursor();
}; };
/** /**
* Returns the screen position of the cursor. * Returns the screen position of the cursor.
* @returns {Number} * @returns {Number}
* @related EditSession.documentToScreenPosition * @related EditSession.documentToScreenPosition
@ -1703,7 +1701,7 @@ var Editor = function(renderer, session) {
return this.session.documentToScreenPosition(this.getCursorPosition()); return this.session.documentToScreenPosition(this.getCursorPosition());
}; };
/** /**
* {:Selection.getRange} * {:Selection.getRange}
* @returns {Range} * @returns {Range}
* @related Selection.getRange * @related Selection.getRange
@ -1713,7 +1711,7 @@ var Editor = function(renderer, session) {
}; };
/** /**
* Selects all the text in editor. * Selects all the text in editor.
* @related Selection.selectAll * @related Selection.selectAll
**/ **/
@ -1723,7 +1721,7 @@ var Editor = function(renderer, session) {
this.$blockScrolling -= 1; this.$blockScrolling -= 1;
}; };
/** /**
* {:Selection.clearSelection} * {:Selection.clearSelection}
* @related Selection.clearSelection * @related Selection.clearSelection
**/ **/
@ -1731,7 +1729,7 @@ var Editor = function(renderer, session) {
this.selection.clearSelection(); this.selection.clearSelection();
}; };
/** /**
* Moves the cursor to the specified row and column. Note that this does not de-select the current selection. * 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} row The new row number
* @param {Number} column The new column number * @param {Number} column The new column number
@ -1743,10 +1741,10 @@ var Editor = function(renderer, session) {
this.selection.moveCursorTo(row, column); this.selection.moveCursorTo(row, column);
}; };
/** /**
* Moves the cursor to the position indicated by `pos.row` and `pos.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 * @param {Object} pos An object with two properties, row and column
* *
* *
* @related Selection.moveCursorToPosition * @related Selection.moveCursorToPosition
**/ **/
@ -1754,7 +1752,7 @@ var Editor = function(renderer, session) {
this.selection.moveCursorToPosition(pos); this.selection.moveCursorToPosition(pos);
}; };
/** /**
* Moves the cursor's row and column to the next matching bracket. * Moves the cursor's row and column to the next matching bracket.
* *
**/ **/
@ -1774,7 +1772,7 @@ var Editor = function(renderer, session) {
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2) if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
range = this.session.getBracketRange(pos); range = this.session.getBracketRange(pos);
} }
pos = range && range.cursor || pos; pos = range && range.cursor || pos;
if (pos) { if (pos) {
if (select) { if (select) {
@ -1794,7 +1792,7 @@ var Editor = function(renderer, session) {
* @param {Number} lineNumber The line number to go to * @param {Number} lineNumber The line number to go to
* @param {Number} column A column number to go to * @param {Number} column A column number to go to
* @param {Boolean} animate If `true` animates scolling * @param {Boolean} animate If `true` animates scolling
* *
**/ **/
this.gotoLine = function(lineNumber, column, animate) { this.gotoLine = function(lineNumber, column, animate) {
this.selection.clearSelection(); this.selection.clearSelection();
@ -1810,7 +1808,7 @@ var Editor = function(renderer, session) {
this.scrollToLine(lineNumber - 1, true, animate); this.scrollToLine(lineNumber - 1, true, animate);
}; };
/** /**
* Moves the cursor to the specified row and column. Note that this does de-select the current selection. * 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} row The new row number
* @param {Number} column The new column number * @param {Number} column The new column number
@ -1826,8 +1824,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. * 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 * @param {Number} times The number of times to change navigation
* *
* *
**/ **/
this.navigateUp = function(times) { this.navigateUp = function(times) {
if (this.selection.isMultiLine() && !this.selection.isBackwards()) { if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
@ -1842,8 +1840,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. * 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 * @param {Number} times The number of times to change navigation
* *
* *
**/ **/
this.navigateDown = function(times) { this.navigateDown = function(times) {
if (this.selection.isMultiLine() && this.selection.isBackwards()) { if (this.selection.isMultiLine() && this.selection.isBackwards()) {
@ -1858,8 +1856,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. * 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 * @param {Number} times The number of times to change navigation
* *
* *
**/ **/
this.navigateLeft = function(times) { this.navigateLeft = function(times) {
if (!this.selection.isEmpty()) { if (!this.selection.isEmpty()) {
@ -1878,8 +1876,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. * 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 * @param {Number} times The number of times to change navigation
* *
* *
**/ **/
this.navigateRight = function(times) { this.navigateRight = function(times) {
if (!this.selection.isEmpty()) { if (!this.selection.isEmpty()) {
@ -1896,7 +1894,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. * Moves the cursor to the start of the current line. Note that this does de-select the current selection.
**/ **/
this.navigateLineStart = function() { this.navigateLineStart = function() {
@ -1905,7 +1903,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. * Moves the cursor to the end of the current line. Note that this does de-select the current selection.
**/ **/
this.navigateLineEnd = function() { this.navigateLineEnd = function() {
@ -1914,7 +1912,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. * Moves the cursor to the end of the current file. Note that this does de-select the current selection.
**/ **/
this.navigateFileEnd = function() { this.navigateFileEnd = function() {
@ -1925,7 +1923,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. * Moves the cursor to the start of the current file. Note that this does de-select the current selection.
**/ **/
this.navigateFileStart = function() { this.navigateFileStart = function() {
@ -1936,7 +1934,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. * 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() { this.navigateWordRight = function() {
@ -1945,7 +1943,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. * 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() { this.navigateWordLeft = function() {
@ -2026,7 +2024,7 @@ var Editor = function(renderer, session) {
} }
}; };
/** /**
* {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * {:Search.getOptions} For more information on `options`, see [[Search `Search`]].
* @related Search.getOptions * @related Search.getOptions
* @returns {Object} * @returns {Object}
@ -2035,7 +2033,7 @@ var Editor = function(renderer, session) {
return this.$search.getOptions(); return this.$search.getOptions();
}; };
/** /**
* Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * 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 {String} needle The text to search for (optional)
* @param {Object} options An object defining various search properties * @param {Object} options An object defining various search properties
@ -2083,7 +2081,7 @@ var Editor = function(renderer, session) {
this.selection.setRange(range); this.selection.setRange(range);
}; };
/** /**
* Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
* @param {Object} options search options * @param {Object} options search options
* @param {Boolean} animate If `true` animate scrolling * @param {Boolean} animate If `true` animate scrolling
@ -2095,7 +2093,7 @@ var Editor = function(renderer, session) {
this.find({skipCurrent: true, backwards: false}, options, animate); this.find({skipCurrent: true, backwards: false}, options, animate);
}; };
/** /**
* Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
* @param {Object} options search options * @param {Object} options search options
* @param {Boolean} animate If `true` animate scrolling * @param {Boolean} animate If `true` animate scrolling
@ -2119,7 +2117,7 @@ var Editor = function(renderer, session) {
this.renderer.animateScrolling(scrollTop); this.renderer.animateScrolling(scrollTop);
}; };
/** /**
* {:UndoManager.undo} * {:UndoManager.undo}
* @related UndoManager.undo * @related UndoManager.undo
**/ **/
@ -2130,7 +2128,7 @@ var Editor = function(renderer, session) {
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
}; };
/** /**
* {:UndoManager.redo} * {:UndoManager.redo}
* @related UndoManager.redo * @related UndoManager.redo
**/ **/
@ -2141,8 +2139,8 @@ var Editor = function(renderer, session) {
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
}; };
/** /**
* *
* Cleans up the entire editor. * Cleans up the entire editor.
**/ **/
this.destroy = function() { this.destroy = function() {

View file

@ -1,58 +1,58 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var TextMode = require("./text").Mode; var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer; var Tokenizer = require("../tokenizer").Tokenizer;
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules; var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode; var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
var highlighter = new GolangHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$keywordList = highlighter.$keywordList;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);
(function() {
var Mode = function() {
var highlighter = new GolangHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$keywordList = highlighter.$keywordList;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//"; this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"}; this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line); var indent = this.$getIndent(line);
var tokenizedLine = this.$tokenizer.getLineTokens(line, state); var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
var tokens = tokenizedLine.tokens; var tokens = tokenizedLine.tokens;
var endState = tokenizedLine.state; var endState = tokenizedLine.state;
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent; return indent;
};//end getNextLineIndent }
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}
this.checkOutdent = function(state, line, input) { return indent;
return this.$outdent.checkOutdent(line, input); };//end getNextLineIndent
};
this.autoOutdent = function(state, doc, row) { this.checkOutdent = function(state, line, input) {
this.$outdent.autoOutdent(doc, row); return this.$outdent.checkOutdent(line, input);
}; };
}).call(Mode.prototype); this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
exports.Mode = Mode; }).call(Mode.prototype);
exports.Mode = Mode;
}); });

View file

@ -30,33 +30,33 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var TextMode = require("../mode/text").Mode; var TextMode = require("../mode/text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer; var Tokenizer = require("../tokenizer").Tokenizer;
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules; var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
var Range = require("../range").Range; var Range = require("../range").Range;
var Mode = function() { var Mode = function() {
var highlighter = new PgsqlHighlightRules(); var highlighter = new PgsqlHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$keywordList = highlighter.$keywordList;
};
oop.inherits(Mode, TextMode);
(function() { this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$keywordList = highlighter.$keywordList;
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "--"; this.lineCommentStart = "--";
this.blockComment = {start: "/*", end: "*/"}; this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
if (state == "start" || state == "keyword.statementEnd") { if (state == "start" || state == "keyword.statementEnd") {
return ""; return "";
} else { } else {
return this.$getIndent(line); // Keep whatever indent the previous line has return this.$getIndent(line); // Keep whatever indent the previous line has
}
} }
}
}).call(Mode.prototype); }).call(Mode.prototype);
exports.Mode = Mode; exports.Mode = Mode;
}); });

View file

@ -347,7 +347,7 @@ var Mode = function() {
} }
} }
} }
} }
} }
this.completionKeywords = completionKeywords; this.completionKeywords = completionKeywords;
} }

View file

@ -7,34 +7,26 @@ var lang = require("../lib/lang");
var Mirror = exports.Mirror = function(sender) { var Mirror = exports.Mirror = function(sender) {
this.sender = sender; this.sender = sender;
var doc = this.doc = new Document(""); var doc = this.doc = new Document("");
this.data = {};
var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
var _self = this; var _self = this;
sender.on("change", function(e) { sender.on("change", function(e) {
doc.applyDeltas(e.data); doc.applyDeltas(e.data);
if (_self.$defer) deferredUpdate.schedule(_self.$timeout);
deferredUpdate.schedule(_self.$timeout);
}); });
}; };
(function() { (function() {
this.$timeout = 500; this.$timeout = 500;
this.$defer = true;
this.setTimeout = function(timeout) { this.setTimeout = function(timeout) {
this.$timeout = timeout; this.$timeout = timeout;
}; };
this.setDeferredUpdate = function(defer) { this.setValue = function(value) {
this.$defer = defer;
};
this.setValue = function(value, data) {
this.doc.setValue(value); this.doc.setValue(value);
this.data = data;
this.deferredUpdate.schedule(this.$timeout); this.deferredUpdate.schedule(this.$timeout);
}; };

View file

@ -144,12 +144,12 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
catch(ex) {} catch(ex) {}
}; };
this.attachToDocument = function(doc, data, ignore) { this.attachToDocument = function(doc) {
if (this.$doc && !ignore) if(this.$doc)
this.terminate(); this.terminate();
this.$doc = doc; this.$doc = doc;
this.call("setValue", [doc.getValue(), data]); this.call("setValue", [doc.getValue()]);
doc.on("change", this.changeListener); doc.on("change", this.changeListener);
}; };