Merge branch 'doc/api'

Conflicts:
	lib/ace/editor.js
This commit is contained in:
Fabian Jakobs 2012-04-28 15:52:53 +02:00
commit cd9da075b1
349 changed files with 12166 additions and 15607 deletions

View file

@ -35,6 +35,14 @@
*
* ***** END LICENSE BLOCK ***** */
/**
* class Ace
*
* The main class required to set up an Ace instance in the browser.
*
*
**/
define(function(require, exports, module) {
"use strict";
@ -56,6 +64,13 @@ require("./keyboard/state_handler");
require("./placeholder");
require("./config").init();
/**
* Ace.edit(el) -> Editor
* - el (String | DOMElement): Either the id of an element, or the element itself
*
* This method embeds the Ace editor into the DOM, at the element provided by `el`.
*
**/
exports.edit = function(el) {
if (typeof(el) == "string") {
el = document.getElementById(el);

View file

@ -42,9 +42,22 @@ var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
/**
* An Anchor is a floating pointer in the document. Whenever text is inserted or
* deleted before the cursor, the position of the cursor is updated
*/
* class Anchor
*
* Defines the floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the cursor is updated
*
**/
/**
* new Anchor(doc, row, column)
* - doc (Document): The document to associate with the anchor
* - row (Number): The starting row position
* - column (Number): The starting column position
*
* Creates a new `Anchor` and associates it with a document.
*
**/
var Anchor = exports.Anchor = function(doc, row, column) {
this.document = doc;
@ -61,14 +74,36 @@ var Anchor = exports.Anchor = function(doc, row, column) {
oop.implement(this, EventEmitter);
/**
* Anchor.getPosition() -> Object
*
* Returns an object identifying the `row` and `column` position of the current anchor.
*
**/
this.getPosition = function() {
return this.$clipPositionToDocument(this.row, this.column);
};
/**
* Anchor.getDocument() -> Document
*
* Returns the current document.
*
**/
this.getDocument = function() {
return this.document;
};
/**
* Anchor@onChange(e)
* - e (Event): Contains data about the event
*
* Fires whenever the anchor position changes. Events that can trigger this function include `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
*
**/
this.onChange = function(e) {
var delta = e.data;
var range = delta.range;
@ -134,6 +169,16 @@ var Anchor = exports.Anchor = function(doc, row, column) {
this.setPosition(row, column, true);
};
/**
* Anchor.setPosition(row, column, noClip)
* - row (Number): The row index to move the anchor to
* - column (Number): The column index to move the anchor to
* - noClip (Boolean): Identifies if you want the position to be clipped
*
* Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped.
*
**/
this.setPosition = function(row, column, noClip) {
var pos;
if (noClip) {
@ -162,10 +207,26 @@ var Anchor = exports.Anchor = function(doc, row, column) {
});
};
/**
* Anchor.detach()
*
* When called, the `'change'` event listener is removed.
*
**/
this.detach = function() {
this.document.removeEventListener("change", this.$onChange);
};
/** internal, hide
* Anchor.clipPositionToDocument(row, column)
* - row (Number): The row index to clip the anchor to
* - column (Number): The column index to clip the anchor to
*
* Clips the anchor position to the specified row and column.
*
**/
this.$clipPositionToDocument = function(row, column) {
var pos = {};

View file

@ -41,6 +41,23 @@ define(function(require, exports, module) {
var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
/**
* class BackgroundTokenizer
*
* Tokenizes the current [[Document `Document`]] in the background, and caches the tokenized rows for future use. If a certain row is changed, everything below that row is re-tokenized.
*
**/
/**
* new BackgroundTokenizer(tokenizer, editor)
* - tokenizer (Tokenizer): The tokenizer to use
* - editor (Editor): The editor to associate with
*
* Creates a new `BackgroundTokenizer` object.
*
*
**/
var BackgroundTokenizer = function(tokenizer, editor) {
this.running = false;
this.lines = [];
@ -82,6 +99,14 @@ var BackgroundTokenizer = function(tokenizer, editor) {
oop.implement(this, EventEmitter);
/**
* BackgroundTokenizer.setTokenizer(tokenizer)
* - tokenizer (Tokenizer): The new tokenizer to use
*
* Sets a new tokenizer for this object.
*
**/
this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer;
this.lines = [];
@ -89,6 +114,14 @@ var BackgroundTokenizer = function(tokenizer, editor) {
this.start(0);
};
/**
* BackgroundTokenizer.setDocument(doc)
* - doc (Document): The new document to associate with
*
* Sets a new document to associate with this object.
*
**/
this.setDocument = function(doc) {
this.doc = doc;
this.lines = [];
@ -96,6 +129,15 @@ var BackgroundTokenizer = function(tokenizer, editor) {
this.stop();
};
/**
* BackgroundTokenizer.fireUpdateEvent(firstRow, lastRow)
* - firstRow (Number): The starting row region
* - lastRow (Number): The final row region
*
* Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated.
*
**/
this.fireUpdateEvent = function(firstRow, lastRow) {
var data = {
first: firstRow,
@ -104,6 +146,14 @@ var BackgroundTokenizer = function(tokenizer, editor) {
this._emit("update", {data: data});
};
/**
* BackgroundTokenizer.start(startRow)
* - startRow (Number): The row to start at
*
* Starts tokenizing at the row indicated.
*
**/
this.start = function(startRow) {
this.currentLine = Math.min(startRow || 0, this.currentLine,
this.doc.getLength());
@ -116,20 +166,54 @@ var BackgroundTokenizer = function(tokenizer, editor) {
this.running = setTimeout(this.$worker, 700);
};
/**
* BackgroundTokenizer.stop()
*
* Stops tokenizing.
*
**/
this.stop = function() {
if (this.running)
clearTimeout(this.running);
this.running = false;
};
/** related to: BackgroundTokenizer.$tokenizeRows
* BackgroundTokenizer.getTokens(firstRow, lastRow) -> [Object]
* - firstRow (Number): The row to start at
* - lastRow (Number): The row to finish at
*
* Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.
*
**/
this.getTokens = function(firstRow, lastRow) {
return this.$tokenizeRows(firstRow, lastRow);
};
/**
* BackgroundTokenizer.getState(row) -> String
* - row (Number): The row to start at
*
* [Returns the state of tokenization for a row.]{: #BackgroundTokenizer.getState}
*
**/
this.getState = function(row) {
return this.$tokenizeRows(row, row)[0].state;
};
/**
* BackgroundTokenizer.$tokenizeRows(firstRow, lastRow) -> [Object]
* - startRow (Number): The row to start at
* - lastRow (Number): The row to finish at
* + ([Object]): A list of the tokenized rows. Each item in the list is an object with two properties, `state` and `start`.
*
* Tokenizes all the rows within the specified region.
*
*
**/
this.$tokenizeRows = function(firstRow, lastRow) {
if (!this.doc || isNaN(firstRow) || isNaN(lastRow))
return [{'state':'start','tokens':[]}];

View file

@ -5,6 +5,24 @@ var oop = require("../lib/oop");
var HashHandler = require("../keyboard/hash_handler").HashHandler;
var EventEmitter = require("../lib/event_emitter").EventEmitter;
/**
* class CommandManager
*
*
*
*
**/
/**
* new CommandManager(platform, commands)
* - platform (String): Identifier for the platform; must be either `'mac'` or `'win'`
* - commands (Array): A list of commands
*
* TODO
*
*
**/
var CommandManager = function(platform, commands) {
this.platform = platform;
this.commands = {};

View file

@ -43,6 +43,21 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range;
var Anchor = require("./anchor").Anchor;
/**
* class Document
*
* Contains the text of the document. Documents are controlled by a single [[EditSession `EditSession`]]. At its core, `Document`s are just an array of strings, with each row in the document matching up to the array index.
*
*
**/
/**
* new Document([text])
* - text (String | Array): The starting text
*
* Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
*
**/
var Document = function(text) {
this.$lines = [];
@ -62,20 +77,48 @@ var Document = function(text) {
oop.implement(this, EventEmitter);
/**
* Document.setValue(text) -> Void
* - text (String): The text to use
*
* Replaces all the lines in the current `Document` with the value of `text`.
**/
this.setValue = function(text) {
var len = this.getLength();
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
this.insert({row: 0, column:0}, text);
};
/**
* Document.getValue() -> String
*
* Returns all the lines in the document as a single string, split by the new line character.
**/
this.getValue = function() {
return this.getAllLines().join(this.getNewLineCharacter());
};
/**
* Document.createAnchor(row, column) -> Anchor
* - row (Number): The row number to use
* - column (Number): The column number to use
*
* Creates a new `Anchor` to define a floating point in the document.
**/
this.createAnchor = function(row, column) {
return new Anchor(this, row, column);
};
/** internal, hide
* Document.$split(text) -> [String]
* - text (String): The text to work with
* + ([String]): A String array, with each index containing a piece of the original `text` string.
*
* Splits a string of text on any newline (`\n`) or carriage-return ('\r') characters.
*
*
**/
// check for IE split bug
if ("aaa".split(/a/).length == 0)
this.$split = function(text) {
@ -87,6 +130,11 @@ var Document = function(text) {
};
/** internal, hide
* Document.$detectNewLine(text) -> Void
*
*
**/
this.$detectNewLine = function(text) {
var match = text.match(/^.*?(\r\n|\r|\n)/m);
if (match) {
@ -96,6 +144,17 @@ var Document = function(text) {
}
};
/**
* Document.getNewLineCharacter() -> String
* + (String): If `newLineMode == windows`, `\r\n` is returned.<br/>
* If `newLineMode == unix`, `\n` is returned.<br/>
* If `newLineMode == auto`, the value of `autoNewLine` is returned.
*
* Returns the newline character that's being used, depending on the value of `newLineMode`.
*
*
*
**/
this.getNewLineCharacter = function() {
switch (this.$newLineMode) {
case "windows":
@ -111,6 +170,12 @@ var Document = function(text) {
this.$autoNewLine = "\n";
this.$newLineMode = "auto";
/**
* Document.setNewLineMode(newLineMode) -> Void
* - newLineMode(String): [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param}
*
* [Sets the new line mode.]{: #Document.setNewLineMode.desc}
**/
this.setNewLineMode = function(newLineMode) {
if (this.$newLineMode === newLineMode)
return;
@ -118,37 +183,74 @@ var Document = function(text) {
this.$newLineMode = newLineMode;
};
/**
* Document.getNewLineMode() -> String
*
* [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode}
*
**/
this.getNewLineMode = function() {
return this.$newLineMode;
};
/**
* Document.isNewLine(text) -> Boolean
* - text (String): The text to check
*
* Returns `true` if `text` is a newline character (either `\r\n`, `\r`, or `\n`).
*
**/
this.isNewLine = function(text) {
return (text == "\r\n" || text == "\r" || text == "\n");
};
/**
* Get a verbatim copy of the given line as it is in the document
*/
* Document.getLine(row) -> String
* - row (Number): The row index to retrieve
*
* Returns a verbatim copy of the given line as it is in the document
*
**/
this.getLine = function(row) {
return this.$lines[row] || "";
};
/**
* Document.getLines(firstRow, lastRow) -> [String]
* - firstRow (Number): The first row index to retrieve
* - lastRow (Number): The final row index to retrieve
*
* Returns an array of strings of the rows between `firstRow` and `lastRow`. This function is inclusive of `lastRow`.
*
**/
this.getLines = function(firstRow, lastRow) {
return this.$lines.slice(firstRow, lastRow + 1);
};
/**
* Returns all lines in the document as string array. Warning: The caller
* should not modify this array!
*/
* Document.getAllLines() -> [String]
*
* Returns all lines in the document as string array. Warning: The caller should not modify this array!
**/
this.getAllLines = function() {
return this.getLines(0, this.getLength());
};
/**
* Document.getLength() -> Number
*
* Returns the number of rows in the document.
**/
this.getLength = function() {
return this.$lines.length;
};
/**
* Document.getTextRange(range) -> String
* - range (Range): The range to work with
*
* [Given a range within the document, this function returns all the text within that range as a single string.]{: #Document.getTextRange.desc}
**/
this.getTextRange = function(range) {
if (range.start.row == range.end.row) {
return this.$lines[range.start.row].substring(range.start.column,
@ -163,6 +265,11 @@ var Document = function(text) {
}
};
/** internal, hide
* Document.$clipPosition(position) -> Number
*
*
**/
this.$clipPosition = function(position) {
var length = this.getLength();
if (position.row >= length) {
@ -172,6 +279,15 @@ var Document = function(text) {
return position;
};
/**
* Document.insert(position, text) -> Number
* - position (Number): The position to start inserting at
* - text (String): A chunk of text to insert
* + (Number): The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`.
* Inserts a block of `text` and the indicated `position`.
*
*
**/
this.insert = function(position, text) {
if (!text || text.length === 0)
return position;
@ -195,6 +311,19 @@ var Document = function(text) {
return position;
};
/**
* Document.insertLines(row, lines) -> Object
* - row (Number): The index of the row to insert at
* - lines (Array): An array of strings
* + (Object): Returns an object containing the final row and column, like this:<br/>
* ```{row: endRow, column: 0}```<br/>
* If `lines` is empty, this function returns an object containing the current row, and column, like this:<br/>
* ```{row: row, column: 0}```
*
* Inserts the elements in `lines` into the document, starting at the row index given by `row`. This method also triggers the `'change'` event.
*
*
**/
this.insertLines = function(row, lines) {
if (lines.length == 0)
return {row: row, column: 0};
@ -213,6 +342,17 @@ var Document = function(text) {
return range.end;
};
/**
* Document.insertNewLine(position) -> Object
* - position (String): The position to insert at
* + (Object): Returns an object containing the final row and column, like this:<br/>
* ```{row: endRow, column: 0}```
*
* Inserts a new line into the document at the current row's `position`. This method also triggers the `'change'` event.
*
*
*
**/
this.insertNewLine = function(position) {
position = this.$clipPosition(position);
var line = this.$lines[position.row] || "";
@ -235,6 +375,19 @@ var Document = function(text) {
return end;
};
/**
* Document.insertInLine(position, text) -> Object | Number
* - position (Number): The position to insert at
* - text (String): A chunk of text
* + (Object): Returns an object containing the final row and column, like this:<br/>
* ```{row: endRow, column: 0}```
* + (Number): If `text` is empty, this function returns the value of `position`
*
* Inserts `text` into the `position` at the current row. This method also triggers the `'change'` event.
*
*
*
**/
this.insertInLine = function(position, text) {
if (text.length == 0)
return position;
@ -259,6 +412,15 @@ var Document = function(text) {
return end;
};
/**
* Document.remove(range) -> Object
* - range (Range): A specified Range to remove
* + (Object): Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`.
*
* Removes the `range` from the document.
*
*
**/
this.remove = function(range) {
// clip to document
range.start = this.$clipPosition(range.start);
@ -291,6 +453,17 @@ var Document = function(text) {
return range.start;
};
/**
* Document.removeInLine(row, startColumn, endColumn) -> Object
* - row (Number): The row to remove from
* - startColumn (Number): The column to start removing at
* - endColumn (Number): The column to stop removing at
* + (Object): Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.<br/>If `startColumn` is equal to `endColumn`, this function returns nothing.
*
* Removes the specified columns from the `row`. This method also triggers the `'change'` event.
*
*
**/
this.removeInLine = function(row, startColumn, endColumn) {
if (startColumn == endColumn)
return;
@ -311,12 +484,15 @@ var Document = function(text) {
};
/**
* Removes a range of full lines
*
* @param firstRow {Integer} The first row to be removed
* @param lastRow {Integer} The last row to be removed
* @return {String[]} The removed lines
*/
* Document.removeLines(firstRow, lastRow) -> [String]
* - firstRow (Number): The first row to be removed
* - lastRow (Number): The last row to be removed
* + ([String]): Returns all the removed lines.
*
* Removes a range of full lines. This method also triggers the `'change'` event.
*
*
**/
this.removeLines = function(firstRow, lastRow) {
var range = new Range(firstRow, 0, lastRow + 1, 0);
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
@ -331,6 +507,13 @@ var Document = function(text) {
return removed;
};
/**
* Document.removeNewLine(row) -> Void
* - row (Number): The row to check
*
* Removes the new line between `row` and the row immediately following it. This method also triggers the `'change'` event.
*
**/
this.removeNewLine = function(row) {
var firstLine = this.getLine(row);
var secondLine = this.getLine(row+1);
@ -348,6 +531,18 @@ var Document = function(text) {
this._emit("change", { data: delta });
};
/**
* Document.replace(range, text) -> Object
* - range (Range): A specified Range to replace
* - text (String): The new text to use as a replacement
* + (Object): Returns an object containing the final row and column, like this:
* {row: endRow, column: 0}
* If the text and range are empty, this function returns an object containing the current `range.start` value.
* If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value.
*
* Replaces a range in the document with the new `text`.
*
**/
this.replace = function(range, text) {
if (text.length == 0 && range.isEmpty())
return range.start;
@ -368,6 +563,11 @@ var Document = function(text) {
return end;
};
/**
* Document.applyDeltas(deltas) -> Void
*
* Applies all the changes previously accumulated. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
**/
this.applyDeltas = function(deltas) {
for (var i=0; i<deltas.length; i++) {
var delta = deltas[i];
@ -384,6 +584,11 @@ var Document = function(text) {
}
};
/**
* Document.revertDeltas(deltas) -> Void
*
* Reverts any changes previously applied. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
**/
this.revertDeltas = function(deltas) {
for (var i=deltas.length-1; i>=0; i--) {
var delta = deltas[i];

File diff suppressed because it is too large Load diff

View file

@ -41,8 +41,34 @@ define(function(require, exports, module) {
var TokenIterator = require("../token_iterator").TokenIterator;
/**
* class BracketMatch
*
*
*
*
**/
/**
* new BracketMatch(position)
* - platform (String): Identifier for the platform; must be either `'mac'` or `'win'`
* - commands (Array): A list of commands
*
* TODO
*
*
**/
function BracketMatch() {
/**
* new findMatchingBracket(position)
* - position (Number): Identifier for the platform; must be either `'mac'` or `'win'`
* - commands (Array): A list of commands
*
* TODO
*
*
**/
this.findMatchingBracket = function(position) {
if (position.column == 0) return null;

View file

@ -39,7 +39,7 @@
define(function(require, exports, module) {
"use strict";
/**
/*
* Simple fold-data struct.
**/
var Fold = exports.Fold = function(range, placeholder) {

View file

@ -41,7 +41,7 @@ define(function(require, exports, module) {
var Range = require("../range").Range;
/**
/*
* If an array is passed in, the folds are expected to be sorted already.
*/
function FoldLine(foldData, folds) {
@ -64,7 +64,7 @@ function FoldLine(foldData, folds) {
}
(function() {
/**
/*
* Note: This doesn't update wrapData!
*/
this.shiftRow = function(shift) {

View file

@ -45,7 +45,7 @@ var Fold = require("./fold").Fold;
var TokenIterator = require("../token_iterator").TokenIterator;
function Folding() {
/**
/*
* Looks up a fold at a given row/column. Possible values for side:
* -1: ignore a fold if fold.start = row/column
* +1: ignore a fold if fold.end = row/column
@ -69,7 +69,7 @@ function Folding() {
}
};
/**
/*
* Returns all folds in the given range. Note, that this will return folds
*
*/
@ -115,7 +115,7 @@ function Folding() {
return foundFolds;
};
/**
/*
* Returns all folds in the document
*/
this.getAllFolds = function() {
@ -138,7 +138,7 @@ function Folding() {
return folds;
};
/**
/*
* Returns the string between folds at the given position.
* E.g.
* foo<fold>b|ar<fold>wolrd -> "bar"
@ -257,7 +257,7 @@ function Folding() {
return foldLine;
};
/**
/*
* Adds a new fold.
*
* @returns
@ -457,7 +457,7 @@ function Folding() {
}
};
/**
/*
* Checks if a given documentRow is folded. This is true if there are some
* folded parts such that some parts of the line is still visible.
**/

File diff suppressed because it is too large Load diff

View file

@ -44,7 +44,7 @@ var EditSession = require("../edit_session").EditSession;
var TextLayer = require("../layer/text").Text;
var baseStyles = require("../requirejs/text!./static.css");
/** Transforms a given input code snippet into HTML using the given mode
/* Transforms a given input code snippet into HTML using the given mode
*
* @param {string} input Code snippet
* @param {mode} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode')

View file

@ -46,7 +46,7 @@ var ace = require("../ace");
require("ace/theme/textmate");
/**
/*
* Returns the CSS property of element.
* 1) If the CSS property is on the style object of the element, use it, OR
* 2) Compute the CSS property

View file

@ -164,4 +164,4 @@ function HashHandler(config, platform) {
}).call(HashHandler.prototype)
exports.HashHandler = HashHandler;
});
});

View file

@ -47,7 +47,7 @@ function StateHandler(keymapping) {
}
StateHandler.prototype = {
/**
/*
* Build the RegExp from the keymapping as RegExp can't stored directly
* in the metadata JSON and as the RegExp used to match the keys/buffer
* need to be adapted.
@ -198,7 +198,7 @@ StateHandler.prototype = {
}
},
/**
/*
* This function is called by keyBinding.
*/
handleKeyboard: function(data, hashId, key, keyCode, e) {
@ -224,7 +224,7 @@ StateHandler.prototype = {
}
}
/**
/*
* This is a useful matching function and therefore is defined here so that
* users of KeyboardStateMapper can use it.
*

View file

@ -111,9 +111,7 @@ var Marker = function(parentEl) {
return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
};
/**
* Draws a marker, which spans a range of text on multiple lines
*/
// Draws a marker, which spans a range of text on multiple lines
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
// selection start
var row = range.start.row;
@ -137,9 +135,7 @@ var Marker = function(parentEl) {
}
};
/**
* Draws a multi line marker, where lines span the full width
*/
// Draws a multi line marker, where lines span the full width
this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig, type) {
var padding = type === "background" ? 0 : this.$padding;
var layerWidth = layerConfig.width + 2 * this.$padding - padding;
@ -186,9 +182,7 @@ var Marker = function(parentEl) {
);
};
/**
* Draws a marker which covers part or whole width of a single screen line
*/
// Draws a marker which covers part or whole width of a single screen line
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength, type) {
var padding = type === "background" ? 0 : this.$padding;
var height = layerConfig.lineHeight;
@ -216,4 +210,4 @@ var Marker = function(parentEl) {
exports.Marker = Marker;
});
});

View file

@ -45,7 +45,7 @@ var oop = require("./oop");
var event = require("./event");
var EventEmitter = require("./event_emitter").EventEmitter;
/**
/*
* This class keeps track of the focus state of the given window.
* Focus changes for example when the user switches a browser tab,
* goes to the location bar or switches to another application.

View file

@ -63,7 +63,7 @@ exports.hasCssClass = function(el, name) {
return classes.indexOf(name) !== -1;
};
/**
/*
* Add a CSS class to the list of classes on the given node
*/
exports.addCssClass = function(el, name) {
@ -72,7 +72,7 @@ exports.addCssClass = function(el, name) {
}
};
/**
/*
* Remove a CSS class from the list of classes on the given node
*/
exports.removeCssClass = function(el, name) {
@ -104,7 +104,7 @@ exports.toggleCssClass = function(el, name) {
return add;
};
/**
/*
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
@ -255,7 +255,7 @@ exports.scrollbarWidth = function(document) {
return noScrollbar-withScrollbar;
};
/**
/*
* Optimized set innerHTML. This is faster than plain innerHTML if the element
* already contains a lot of child elements.
*
@ -289,4 +289,4 @@ exports.getParentWindow = function(document) {
return document.defaultView || document.parentWindow;
};
});
});

View file

@ -26,7 +26,7 @@
define(function(require, exports, module) {
/**
/*
* Brings an environment as close to ECMAScript 5 compliance
* as is possible with the facilities of erstwhile engines.
*

View file

@ -64,7 +64,7 @@ exports.removeListener = function(elem, type, callback) {
}
};
/**
/*
* Prevents propagation and clobbers the default action of the passed event
*/
exports.stopEvent = function(e) {
@ -103,7 +103,7 @@ exports.getDocumentY = function(e) {
}
};
/**
/*
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
*/
exports.getButton = function(e) {

View file

@ -36,7 +36,7 @@ define(function(require, exports, module) {
var oop = require("./oop");
/**
/*
* Helper functions and hashes for key handling.
*/
var Keys = (function() {

View file

@ -101,7 +101,7 @@ exports.arrayToMap = function(arr) {
};
/**
/*
* splice out of 'array' anything that === 'value'
*/
exports.arrayRemove = function(array, value) {

View file

@ -1,4 +1,4 @@
/**
/*
* based on code from:
*
* @license RequireJS text 0.25.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.

View file

@ -1,4 +1,4 @@
/**
/*
* Based on code from:
*
* XRegExp 1.5.0

View file

@ -41,13 +41,13 @@ define(function(require, exports, module) {
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
var ua = navigator.userAgent;
/** Is the user using a browser that identifies itself as Windows */
// Is the user using a browser that identifies itself as Windows
exports.isWin = (os == "win");
/** Is the user using a browser that identifies itself as Mac OS */
// Is the user using a browser that identifies itself as Mac OS
exports.isMac = (os == "mac");
/** Is the user using a browser that identifies itself as Linux */
// Is the user using a browser that identifies itself as Linux
exports.isLinux = (os == "linux");
exports.isIE =
@ -56,16 +56,16 @@ exports.isIE =
exports.isOldIE = exports.isIE && exports.isIE < 9;
/** Is this Firefox or related? */
// Is this Firefox or related?
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
/** oldGecko == rev < 2.0 **/
// oldGecko == rev < 2.0
exports.isOldGecko = exports.isGecko && parseInt((navigator.userAgent.match(/rv\:(\d+)/)||[])[1], 10) < 4;
/** Is this Opera */
// Is this Opera
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
/** Is the user using a browser that identifies itself as WebKit */
// Is the user using a browser that identifies itself as WebKit
exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
@ -76,7 +76,7 @@ exports.isIPad = ua.indexOf("iPad") >= 0;
exports.isTouchPad = ua.indexOf("TouchPad") >= 0;
/**
/*
* I hate doing this, but we need some way to determine if the user is on a Mac
* The reason is that users have different expectations of their key combinations.
*
@ -89,7 +89,7 @@ exports.OS = {
WINDOWS: "WINDOWS"
};
/**
/*
* Return an exports.OS constant
*/
exports.getOS = function() {

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
@ -97,4 +97,4 @@ define(function(require, exports, module) {
};
});
});

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
@ -736,4 +736,4 @@ define(function(require, exports, module) {
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
});
});

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
@ -2753,4 +2753,4 @@ define(function(require, exports, module) {
};
});
});

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
@ -339,4 +339,4 @@ define(function(require, exports, module) {
LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT'];
});
});

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2011 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
@ -151,4 +151,4 @@ define(function(require, exports, module) {
})();
});
});

View file

@ -101,7 +101,7 @@ oop.inherits(FoldMode, BaseFoldMode);
};
};
/**
/*
* reads a full tag and places the iterator after the tag
*/
this._readTagForward = function(iterator) {

View file

@ -41,7 +41,7 @@ define(function(require, exports, module) {
var event = require("../lib/event");
/**
/*
* Custom Ace mouse event
*/
var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
@ -78,7 +78,7 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
this.preventDefault();
};
/**
/*
* Get the document position below the mouse cursor
*
* @return {Object} 'row' and 'column' of the document position
@ -93,7 +93,7 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
return this.$pos;
};
/**
/*
* Check if the mouse cursor is inside of the text selection
*
* @return {Boolean} whether the mouse cursor is inside of the selection
@ -119,7 +119,7 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
return this.$inSelection;
};
/**
/*
* Get the clicked mouse button
*
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
@ -128,7 +128,7 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
return event.getButton(this.domEvent);
};
/**
/*
* @return {Boolean} whether the shift key was pressed when the event was emitted
*/
this.getShiftKey = function() {

View file

@ -71,10 +71,12 @@ var EditSession = require("./edit_session").EditSession;
// automatically sorted list of ranges
this.rangeList = null;
/**
* Selection.addRange(Range) -> Void
/** extension
* Selection.addRange(range, $blockChangeEvents)
* - range (Range): The new range to add
* - $blockChangeEvents (Boolean): Whether or not to block changing events
*
* adds a range to selection entering multiselect mode if necessary
* Adds a range to a selection by entering multiselect mode, if necessary.
**/
this.addRange = function(range, $blockChangeEvents) {
if (!range)
@ -118,11 +120,11 @@ var EditSession = require("./edit_session").EditSession;
range && this.fromOrientedRange(range);
};
/**
* Selection.addRange(pos) -> Range
* pos: {row, column}
/** extension
* Selection.substractPoint(pos) -> Range
* - pos (Range): The position to remove, as a `{row, column}` object
*
* removes range containing pos (if exists)
* Removes a Range containing pos (if it exists).
**/
this.substractPoint = function(pos) {
var removed = this.rangeList.substractPoint(pos);
@ -132,10 +134,10 @@ var EditSession = require("./edit_session").EditSession;
}
};
/**
* Selection.mergeOverlappingRanges() -> Void
/** extension
* Selection.mergeOverlappingRanges()
*
* merges overlapping ranges ensuring consistency after changes
* Merges overlapping ranges ensuring consistency after changes
**/
this.mergeOverlappingRanges = function() {
var removed = this.rangeList.merge();
@ -209,11 +211,14 @@ var EditSession = require("./edit_session").EditSession;
}
};
/**
* Selection.rectangularRangeBlock(screenCursor, screenAnchor, includeEmptyLines) -> [Range]
* gets list of ranges composing rectangular block on the screen
* @includeEmptyLines if true includes ranges inside the block which
* are empty becuase of the clipping
/** extension
* Selection.rectangularRangeBlock(screenCursor, screenAnchor, includeEmptyLines) -> Range
* - screenCursor (Cursor): The cursor to use
* - screenAnchor (Anchor): The anchor to use
* - includeEmptyLins (Boolean): If true, this includes ranges inside the block which are empty due to clipping
*
* Gets list of ranges composing rectangular block on the screen
*
*/
this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
var rectSel = [];
@ -283,21 +288,22 @@ var EditSession = require("./edit_session").EditSession;
// extend Editor
var Editor = require("./editor").Editor;
(function() {
/**
* Editor.updateSelectionMarkers() -> Void
/** extension
* Editor.updateSelectionMarkers()
*
* updates cursor and marker layers
* Updates the cursor and marker layers.
**/
this.updateSelectionMarkers = function() {
this.renderer.updateCursor();
this.renderer.updateBackMarkers();
};
/**
/** extension
* Editor.addSelectionMarker(orientedRange) -> Range
* - orientedRange: range with cursor
* - orientedRange (Range): A range containing a cursor
*
* adds selection and cursor
* Adds the selection and cursor.
**/
this.addSelectionMarker = function(orientedRange) {
if (!orientedRange.cursor)
@ -311,11 +317,11 @@ var Editor = require("./editor").Editor;
return orientedRange;
};
/**
* Editor.removeSelectionMarker(range) -> Void
* - range: selection range added with addSelectionMarker
/** extension
* Editor.removeSelectionMarker(range)
* - range (Range): The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]].
*
* removes selection marker
* Removes the selection marker.
**/
this.removeSelectionMarker = function(range) {
if (!range.marker)
@ -397,12 +403,12 @@ var Editor = require("./editor").Editor;
e.preventDefault();
};
/**
* Editor.forEachSelection(cmd, args) -> Void
* - cmd: command to execute
* - args: arguments to the command
/** extension
* Editor.forEachSelection(cmd, args)
* - cmd (String): The command to execute
* - args (String): Any arguments for the command
*
* executes command for each selection range
* Executes a command for each selection range.
**/
this.forEachSelection = function(cmd, args) {
if (this.inVirtualSelectionMode)
@ -434,10 +440,10 @@ var Editor = require("./editor").Editor;
this.onSelectionChange();
};
/**
* Editor.exitMultiSelectMode() -> Void
/** extension
* Editor.exitMultiSelectMode()
*
* removes all selections except the last added one.
* Removes all the selections except the last added one.
**/
this.exitMultiSelectMode = function() {
if (this.inVirtualSelectionMode)
@ -461,14 +467,15 @@ var Editor = require("./editor").Editor;
return text;
};
/**
* Editor.findAll(dir, options) -> Number
* - needle: text to find
* - options: search options
* - additive: keeps
/** extension
* Editor.findAll(needle, dir, additive) -> Number
* - needle (String): The text to find
* - options (Object): Any of the additional [[Search search options]]
* - additive (Boolean): TODO
* + (Number): The number of found ranges.
*
* finds and selects all the occurencies of needle
* returns number of found ranges
* Finds and selects all the occurences of `needle`.
*
**/
this.findAll = function(needle, options, additive) {
options = options || {};
@ -494,12 +501,12 @@ var Editor = require("./editor").Editor;
};
// commands
/**
* Editor.selectMoreLines(dir, skip) -> Void
* - dir: -1 up, 1 down
* - skip: remove active selection range if true
/** extension
* Editor.selectMoreLines(dir, skip)
* - dir (Number): The direction of lines to select: -1 for up, 1 for down
* - skip (Boolean): If `true`, removes the active selection range
*
* adds cursor above or bellow active cursor
* Adds a cursor above or below the active cursor.
**/
this.selectMoreLines = function(dir, skip) {
var range = this.selection.toOrientedRange();
@ -539,12 +546,12 @@ var Editor = require("./editor").Editor;
this.selection.substractPoint(toRemove);
};
/**
* Editor.transposeSelections(dir) -> Void
* - dir: direction to rotate selections
/** extension
* Editor.transposeSelections(dir)
* - dir (Number): The direction to rotate selections
*
* contents
* empty ranges are expanded to word
* Transposes the selected ranges.
*
**/
this.transposeSelections = function(dir) {
var session = this.session;
@ -583,13 +590,12 @@ var Editor = require("./editor").Editor;
}
}
/**
* Editor.selectMore(dir, skip) -> Void
* - dir: 1 next, -1 previous
* - skip: remove active selection range if true
/** extension
* Editor.selectMore(dir, skip)
* - dir (Number): The direction of lines to select: -1 for up, 1 for down
* - skip (Boolean): If `true`, removes the active selection range
*
* finds next occurence of text in active selection
* and adds it to the selections
* Finds the next occurence of text in an active selection and adds it to the selections.
**/
this.selectMore = function (dir, skip) {
var session = this.session;
@ -656,12 +662,9 @@ exports.onSessionChange = function(e) {
}
};
/**
* MultiSelect(editor) -> Void
*
* adds multiple selection support to the editor
* (note: should be called only once for each editor instance)
**/
// MultiSelect(editor)
// adds multiple selection support to the editor
// (note: should be called only once for each editor instance)
function MultiSelect(editor) {
editor.$onAddRange = editor.$onAddRange.bind(editor);
editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);

View file

@ -41,6 +41,26 @@ var Range = require('./range').Range;
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var oop = require("./lib/oop");
/**
* class PlaceHolder
*
* TODO
*
**/
/**
* new PlaceHolder(session, length, pos, others, mainClass, othersClass)
* - session (Document): The document to associate with the anchor
* - length (Number): The starting row position
* - pos (Number): The starting column position
* - others (String):
* - mainClass (String):
* - othersClass (String):
*
* TODO
*
**/
var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
var _self = this;
this.length = length;
@ -71,6 +91,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
oop.implement(this, EventEmitter);
/**
* PlaceHolder.setup()
*
* TODO
*
**/
this.setup = function() {
var _self = this;
var doc = this.doc;
@ -91,6 +117,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
session.setUndoSelect(false);
};
/**
* PlaceHolder.showOtherMarkers()
*
* TODO
*
**/
this.showOtherMarkers = function() {
if(this.othersActive) return;
var session = this.session;
@ -105,6 +137,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
});
};
/**
* PlaceHolder.hideOtherMarkers()
*
* Hides all over markers in the [[EditSession `EditSession`]] that are not the currently selected one.
*
**/
this.hideOtherMarkers = function() {
if(!this.othersActive) return;
this.othersActive = false;
@ -113,6 +151,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
}
};
/**
* PlaceHolder@onUpdate(e)
*
* Emitted when the place holder updates.
*
**/
this.onUpdate = function(event) {
var delta = event.data;
var range = delta.range;
@ -175,6 +219,13 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
this.$updating = false;
};
/**
* PlaceHolder@onCursorChange(e)
*
* Emitted when the cursor changes.
*
**/
this.onCursorChange = function(event) {
if (this.$updating) return;
var pos = this.session.selection.getCursor();
@ -187,6 +238,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
}
};
/**
* PlaceHolder.detach()
*
* TODO
*
**/
this.detach = function() {
this.session.removeMarker(this.markerId);
this.hideOtherMarkers();
@ -199,6 +256,12 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
this.session.setUndoSelect(true);
};
/**
* PlaceHolder.cancel()
*
* TODO
*
**/
this.cancel = function() {
if(this.$undoStackDepth === -1)
throw Error("Canceling placeholders only supported with undo manager attached to session.");

View file

@ -38,6 +38,23 @@
define(function(require, exports, module) {
"use strict";
/**
* class Range
*
* This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogus to a range, as ranges contain a starting row and starting column, and an ending row, and ending column.
*
**/
/**
* new Range(startRow, startColumn, endRow, endColumn)
* - startRow (Number): The starting row
* - startColumn (Number): The starting column
* - endRow (Number): The ending row
* - endColumn (Number): The ending column
*
* Creates a new `Range` object with the given starting and ending row and column points.
*
**/
var Range = function(startRow, startColumn, endRow, endColumn) {
this.start = {
row: startRow,
@ -51,6 +68,13 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
};
(function() {
/**
* Range.isEqual(range) -> Boolean
* - range (Range): A range to check against
*
* Returns `true` if and only if the starting row and column, and ending tow and column, are equivalent to those given by `range`.
*
**/
this.isEqual = function(range) {
return this.start.row == range.start.row &&
this.end.row == range.end.row &&
@ -58,28 +82,51 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
this.end.column == range.end.column
};
/**
* Range.toString() -> String
*
* Returns a string containing the range's row and column information, given like this:
*
* [start.row/start.column] -> [end.row/end.column]
*
**/
this.toString = function() {
return ("Range: [" + this.start.row + "/" + this.start.column +
"] -> [" + this.end.row + "/" + this.end.column + "]");
};
/** related to: Range.compare
* Range.contains(row, column) -> Boolean
* - row (Number): A row to check for
* - column (Number): A column to check for
*
* Returns `true` if the `row` and `column` provided are within the given range. This can better be expressed as returning `true` if:
*
* this.start.row <= row <= this.end.row &&
* this.start.column <= column <= this.end.column
*
**/
this.contains = function(row, column) {
return this.compare(row, column) == 0;
};
/**
* Compares this range (A) with another range (B), where B is the passed in
* range.
/** related to: Range.compare
* Range.compareRange(range) -> Number
* - range (Range): A range to compare with
* + (Number): This method returns one of the following numbers:<br/>
* <br/>
* * `-2`: (B) is in front of (A), and doesn't intersect with (A)<br/>
* * `-1`: (B) begins before (A) but ends inside of (A)<br/>
* * `0`: (B) is completely inside of (A) OR (A) is completely inside of (B)<br/>
* * `+1`: (B) begins inside of (A) but ends outside of (A)<br/>
* * `+2`: (B) is after (A) and doesn't intersect with (A)<br/>
* * `42`: FTW state: (B) ends in (A) but starts outside of (A)
*
* Compares `this` range (A) with another range (B).
*
* Return values:
* -2: (B) is infront of (A) and doesn't intersect with (A)
* -1: (B) begins before (A) but ends inside of (A)
* 0: (B) is completly inside of (A) OR (A) is complety inside of (B)
* +1: (B) begins inside of (A) but ends outside of (A)
* +2: (B) is after (A) and doesn't intersect with (A)
*
* 42: FTW state: (B) ends in (A) but starts outside of (A)
*/
**/
this.compareRange = function(range) {
var cmp,
end = range.end,
@ -109,27 +156,86 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
/** related to: Range.compare
* Range.comparePoint(p) -> Number
* - p (Range): A point to compare with
* + (Number): This method returns one of the following numbers:<br/>
* * `0` if the two points are exactly equal<br/>
* * `-1` if `p.row` is less then the calling range<br/>
* * `1` if `p.row` is greater than the calling range<br/>
* <br/>
* If the starting row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
* * Otherwise, it returns -1<br/>
*<br/>
* If the ending row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
* * Otherwise, it returns 1<br/>
*
* Checks the row and column points of `p` with the row and column points of the calling range.
*
*
*
**/
this.comparePoint = function(p) {
return this.compare(p.row, p.column);
}
/** related to: Range.comparePoint
* Range.containsRange(range) -> Boolean
* - range (Range): A range to compare with
*
* Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
*
**/
this.containsRange = function(range) {
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
}
/**
* Range.intersects(range) -> Boolean
* - range (Range): A range to compare with
*
* Returns `true` if passed in `range` intersects with the one calling this method.
*
**/
this.intersects = function(range) {
var cmp = this.compareRange(range);
return (cmp == -1 || cmp == 0 || cmp == 1);
}
/**
* Range.isEnd(row, column) -> Boolean
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
*
* Returns `true` if the caller's ending row point is the same as `row`, and if the caller's ending column is the same as `column`.
*
**/
this.isEnd = function(row, column) {
return this.end.row == row && this.end.column == column;
}
/**
* Range.isStart(row, column) -> Boolean
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
*
* Returns `true` if the caller's starting row point is the same as `row`, and if the caller's starting column is the same as `column`.
*
**/
this.isStart = function(row, column) {
return this.start.row == row && this.start.column == column;
}
/**
* Range.setStart(row, column)
* - row (Number): A row point to set
* - column (Number): A column point to set
*
* Sets the starting row and column for the range.
*
**/
this.setStart = function(row, column) {
if (typeof row == "object") {
this.start.column = row.column;
@ -140,6 +246,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
/**
* Range.setEnd(row, column)
* - row (Number): A row point to set
* - column (Number): A column point to set
*
* Sets the starting row and column for the range.
*
**/
this.setEnd = function(row, column) {
if (typeof row == "object") {
this.end.column = row.column;
@ -150,6 +264,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
/** related to: Range.compare
* Range.inside(row, column) -> Boolean
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
*
* Returns `true` if the `row` and `column` are within the given range.
*
**/
this.inside = function(row, column) {
if (this.compare(row, column) == 0) {
if (this.isEnd(row, column) || this.isStart(row, column)) {
@ -161,6 +283,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return false;
}
/** related to: Range.compare
* Range.insideStart(row, column) -> Boolean
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
*
* Returns `true` if the `row` and `column` are within the given range's starting points.
*
**/
this.insideStart = function(row, column) {
if (this.compare(row, column) == 0) {
if (this.isEnd(row, column)) {
@ -172,6 +302,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return false;
}
/** related to: Range.compare
* Range.insideEnd(row, column) -> Boolean
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
*
* Returns `true` if the `row` and `column` are within the given range's ending points.
*
**/
this.insideEnd = function(row, column) {
if (this.compare(row, column) == 0) {
if (this.isStart(row, column)) {
@ -183,6 +321,27 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return false;
}
/**
* Range.compare(row, column) -> Number
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
* + (Number): This method returns one of the following numbers:<br/>
* * `0` if the two points are exactly equal <br/>
* * `-1` if `p.row` is less then the calling range <br/>
* * `1` if `p.row` is greater than the calling range <br/>
* <br/>
* If the starting row of the calling range is equal to `p.row`, and: <br/>
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
* * Otherwise, it returns -1<br/>
* <br/>
* If the ending row of the calling range is equal to `p.row`, and: <br/>
* * `p.column` is less than or equal to the calling range's ending column, this returns `0` <br/>
* * Otherwise, it returns 1
*
* Checks the row and column points with the row and column points of the calling range.
*
*
**/
this.compare = function(row, column) {
if (!this.isMultiLine()) {
if (row === this.start.row) {
@ -206,8 +365,28 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
};
/**
* Like .compare(), but if isStart is true, return -1;
*/
* Range.compareStart(row, column) -> Number
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
* + (Number): This method returns one of the following numbers:<br/>
* <br/>
* * `0` if the two points are exactly equal<br/>
* * `-1` if `p.row` is less then the calling range<br/>
* * `1` if `p.row` is greater than the calling range, or if `isStart` is `true`.<br/>
* <br/>
* If the starting row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
* * Otherwise, it returns -1<br/>
* <br/>
* If the ending row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
* * Otherwise, it returns 1
*
* Checks the row and column points with the row and column points of the calling range.
*
*
*
**/
this.compareStart = function(row, column) {
if (this.start.row == row && this.start.column == column) {
return -1;
@ -217,8 +396,26 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
/**
* Like .compare(), but if isEnd is true, return 1;
*/
* Range.compareEnd(row, column) -> Number
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
* + (Number): This method returns one of the following numbers:<br/>
* * `0` if the two points are exactly equal<br/>
* * `-1` if `p.row` is less then the calling range<br/>
* * `1` if `p.row` is greater than the calling range, or if `isEnd` is `true.<br/>
* <br/>
* If the starting row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
* * Otherwise, it returns -1<br/>
*<br/>
* If the ending row of the calling range is equal to `p.row`, and:<br/>
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
* * Otherwise, it returns 1
*
* Checks the row and column points with the row and column points of the calling range.
*
*
**/
this.compareEnd = function(row, column) {
if (this.end.row == row && this.end.column == column) {
return 1;
@ -227,6 +424,21 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
/**
* Range.compareInside(row, column) -> Number
* - row (Number): A row point to compare with
* - column (Number): A column point to compare with
* + (Number): This method returns one of the following numbers:<br/>
* * `1` if the ending row of the calling range is equal to `row`, and the ending column of the calling range is equal to `column`<br/>
* * `-1` if the starting row of the calling range is equal to `row`, and the starting column of the calling range is equal to `column`<br/>
* <br/>
* Otherwise, it returns the value after calling [[Range.compare `compare()`]].
*
* Checks the row and column points with the row and column points of the calling range.
*
*
*
**/
this.compareInside = function(row, column) {
if (this.end.row == row && this.end.column == column) {
return 1;
@ -237,6 +449,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
/**
* Range.clipRows(firstRow, lastRow) -> Range
* - firstRow (Number): The starting row
* - lastRow (Number): The ending row
*
* Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
*
**/
this.clipRows = function(firstRow, lastRow) {
if (this.end.row > lastRow) {
var end = {
@ -268,6 +488,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return Range.fromPoints(start || this.start, end || this.end);
};
/**
* Range.extend(row, column) -> Range
* - row (Number): A new row to extend to
* - column (Number): A new column to extend to
*
* Changes the row and column points for the calling range for both the starting and ending points. This method returns that range with a new row.
*
**/
this.extend = function(row, column) {
var cmp = this.compare(row, column);
@ -281,33 +509,36 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return Range.fromPoints(start || this.start, end || this.end);
};
this.fixOrientation = function() {
if (
this.start.row < this.end.row
|| (this.start.row == this.end.row && this.start.column < this.end.column)
) {
return false;
}
var temp = this.start;
this.end = this.start;
this.start = temp;
return true;
};
this.isEmpty = function() {
return (this.start.row == this.end.row && this.start.column == this.end.column);
};
/**
* Range.isMultiLine() -> Boolean
*
* Returns true if the range spans across multiple lines.
*
**/
this.isMultiLine = function() {
return (this.start.row !== this.end.row);
};
/**
* Range.clone() -> Range
*
* Returns a duplicate of the calling range.
*
**/
this.clone = function() {
return Range.fromPoints(this.start, this.end);
};
/**
* Range.collapseRows() -> Range
*
* Returns a range containing the starting and ending rows of the original range, but with a column value of `0`.
*
**/
this.collapseRows = function() {
if (this.end.column == 0)
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
@ -315,6 +546,12 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
return new Range(this.start.row, 0, this.end.row, 0)
};
/**
* Range.toScreenRange(session) -> Range
* - session (EditSession): The `EditSession` to retrieve coordinates from
*
* Given the current `Range`, this function converts those starting and ending points into screen positions, and then returns a new `Range` object.
**/
this.toScreenRange = function(session) {
var screenPosStart =
session.documentToScreenPosition(this.start);
@ -329,7 +566,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}).call(Range.prototype);
/**
* Range.fromPoints(start, end) -> Range
* - start (Range): A starting point to use
* - end (Range): An ending point to use
*
* Creates and returns a new `Range` based on the row and column of the given parameters.
*
**/
Range.fromPoints = function(start, end) {
return new Range(start.row, start.column, end.row, end.column);
};

View file

@ -41,6 +41,19 @@ define(function(require, exports, module) {
var event = require("./lib/event");
/** internal, hide
* class RenderLoop
*
* Batches changes (that force something to be redrawn) in the background.
*
**/
/** internal, hide
* new RenderLoop(onRender, win)
*
*
*
**/
var RenderLoop = function(onRender, win) {
this.onRender = onRender;
this.pending = false;
@ -50,6 +63,12 @@ var RenderLoop = function(onRender, win) {
(function() {
/** internal, hide
* RenderLoop.schedule(change)
* - change (Array):
*
*
**/
this.schedule = function(change) {
//this.onRender(change);
//return;

View file

@ -35,7 +35,7 @@
*
* ***** END LICENSE BLOCK ***** */
/**
/*
* Extremely simplified version of the requireJS text plugin
*/

View file

@ -44,6 +44,20 @@ var dom = require("./lib/dom");
var event = require("./lib/event");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
/**
* class ScrollBar
*
* A set of methods for setting and retrieving the editor's scrollbar.
*
**/
/**
* new ScrollBar(parent)
* - parent (DOMElement): A DOM element
*
* Creates a new `ScrollBar`. `parent` is the owner of the scroll bar.
*
**/
var ScrollBar = function(parent) {
this.element = dom.createElement("div");
this.element.className = "ace_sb";
@ -67,22 +81,55 @@ var ScrollBar = function(parent) {
(function() {
oop.implement(this, EventEmitter);
/**
* ScrollBar@onScroll
*
* Emitted when the scroll bar, well, scrolls.
*
**/
this.onScroll = function() {
this._emit("scroll", {data: this.element.scrollTop});
};
/**
* ScrollBar.getWidth() -> Number
*
* Returns the width of the scroll bar.
*
**/
this.getWidth = function() {
return this.width;
};
/**
* ScrollBar.setHeight(height)
* - height (Number): The new height
*
* Sets the height of the scroll bar, in pixels.
*
**/
this.setHeight = function(height) {
this.element.style.height = height + "px";
};
/**
* ScrollBar.setInnerHeight(height)
* - height (Number): The new inner height
*
* Sets the inner height of the scroll bar, in pixels.
*
**/
this.setInnerHeight = function(height) {
this.inner.style.height = height + "px";
};
/**
* ScrollBar.setScrollTop(scrollTop)
* - scrollTop (Number): The new scroll top
*
* Sets the scroll top of the scroll bar.
*
**/
// TODO: on chrome 17+ after for small zoom levels after this function
// this.element.scrollTop != scrollTop which makes page to scroll up.
this.setScrollTop = function(scrollTop) {

View file

@ -44,6 +44,28 @@ var lang = require("./lib/lang");
var oop = require("./lib/oop");
var Range = require("./range").Range;
/**
* class Search
*
* A class designed to handle all sorts of text searches within a [[Document `Document`]].
*
**/
/**
* new Search()
*
* Creates a new `Search` object. The search options contain the following defaults:
*
* * `needle`: `""`
* * `backwards`: `false`
* * `wrap`: `false`
* * `caseSensitive`: `false`
* * `wholeWord`: `false`
* * `scope`: `ALL`
* * `regExp`: `false`
*
**/
var Search = function() {
this.$options = {
needle: "",
@ -61,15 +83,35 @@ Search.SELECTION = 2;
(function() {
/**
* Search.set(options) -> Search
* - options (Object): An object containing all the new search properties
*
* Sets the search options via the `options` parameter.
*
**/
this.set = function(options) {
oop.mixin(this.$options, options);
return this;
};
/**
* Search.getOptions() -> Object
*
* [Returns an object containing all the search options.]{: #Search.getOptions}
*
**/
this.getOptions = function() {
return lang.copyObject(this.$options);
};
/**
* Search.find(session) -> Range
* - session (EditSession): The session to search with
*
* Searches for `options.needle`. If found, this method returns the [[Range `Range`]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.
*
**/
this.find = function(session) {
if (!this.$options.needle)
return null;
@ -89,6 +131,13 @@ Search.SELECTION = 2;
return firstRange;
};
/**
* Search.findAll(session) -> [Range]
* - session (EditSession): The session to search with
*
* Searches for all occurances `options.needle`. If found, this method returns an array of [[Range `Range`s]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.
*
**/
this.findAll = function(session) {
var options = this.$options;
if (!options.needle)
@ -115,6 +164,18 @@ Search.SELECTION = 2;
return ranges;
};
/**
* Search.replace(input, replacement) -> String
* - input (String): The text to search in
* - replacement (String): The replacing text
* + (String): If `options.regExp` is `true`, this function returns `input` with the replacement already made. Otherwise, this function just returns `replacement`.<br/>
* If `options.needle` was not found, this function returns `null`.
*
* Searches for `options.needle` in `input`, and, if found, replaces it with `replacement`.
*
*
*
**/
this.replace = function(input, replacement) {
var re = this.$assembleRegExp();
var match = re.exec(input);
@ -129,6 +190,13 @@ Search.SELECTION = 2;
}
};
/** internal, hide
* Search.$forwardMatchIterator(session) -> String | Boolean
* - session (EditSession): The session to search with
*
*
*
**/
this.$forwardMatchIterator = function(session) {
var re = this.$assembleRegExp();
var self = this;
@ -163,6 +231,13 @@ Search.SELECTION = 2;
};
};
/** internal, hide
* Search.$backwardMatchIterator(session) -> String
* - session (EditSession): The session to search with
*
*
*
**/
this.$backwardMatchIterator = function(session) {
var re = this.$assembleRegExp();
var self = this;

View file

@ -45,12 +45,20 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range;
/**
* Keeps cursor position and the text selection of an edit session.
* class Selection
*
* The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document
* before applying soft wrap and folding.
*/
* Contains the cursor position and the text selection of an edit session.
*
* The row/columns used in the selection are in document coordinates representing ths coordinates as thez appear in the document before applying soft wrap and folding.
**/
/**
* new Selection(session)
* - session (EditSession): The session to use
*
* Creates a new `Selection` object.
*
**/
var Selection = function(session) {
this.session = session;
this.doc = session.getDocument();
@ -78,6 +86,11 @@ var Selection = function(session) {
oop.implement(this, EventEmitter);
/**
* Selection.isEmpty() -> Boolean
*
* Returns `true` if the selection is empty.
**/
this.isEmpty = function() {
return (this.$isEmpty || (
this.selectionAnchor.row == this.selectionLead.row &&
@ -85,6 +98,11 @@ var Selection = function(session) {
));
};
/**
* Selection.isMultiLine() -> Boolean
*
* Returns `true` if the selection is a multi-line.
**/
this.isMultiLine = function() {
if (this.isEmpty()) {
return false;
@ -93,10 +111,22 @@ var Selection = function(session) {
return this.getRange().isMultiLine();
};
/**
* Selection.getCursor() -> Number
*
* Gets the current position of the cursor.
**/
this.getCursor = function() {
return this.selectionLead.getPosition();
};
/**
* Selection.setSelectionAnchor(row, column)
* - row (Number): The new row
* - column (Number): The new column
*
* Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.
**/
this.setSelectionAnchor = function(row, column) {
this.selectionAnchor.setPosition(row, column);
@ -106,6 +136,12 @@ var Selection = function(session) {
}
};
/** related to: Anchor.getPosition
* Selection.getSelectionAnchor() -> Object
*
* Returns an object containing the `row` and `column` of the calling selection anchor.
*
**/
this.getSelectionAnchor = function() {
if (this.$isEmpty)
return this.getSelectionLead()
@ -113,10 +149,22 @@ var Selection = function(session) {
return this.selectionAnchor.getPosition();
};
/**
* Selection.getSelectionLead() -> Object
*
* Returns an object containing the `row` and `column` of the calling selection lead.
**/
this.getSelectionLead = function() {
return this.selectionLead.getPosition();
};
/**
* Selection.shiftSelection(columns)
* - columns (Number): The number of columns to shift by
*
* Shifts the selection up (or down, if [[Selection.isBackwards `isBackwards()`]] is true) the given number of columns.
*
**/
this.shiftSelection = function(columns) {
if (this.$isEmpty) {
this.moveCursorTo(this.selectionLead.row, this.selectionLead.column + columns);
@ -138,12 +186,22 @@ var Selection = function(session) {
}
};
/**
* Selection.isBackwards() -> Boolean
*
* Returns `true` if the selection is going backwards in the document.
**/
this.isBackwards = function() {
var anchor = this.selectionAnchor;
var lead = this.selectionLead;
return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
};
/**
* Selection.getRange() -> Range
*
* [Returns the [[Range `Range`]] for the selected text.]{: #Selection.getRange}
**/
this.getRange = function() {
var anchor = this.selectionAnchor;
var lead = this.selectionLead;
@ -159,6 +217,11 @@ var Selection = function(session) {
}
};
/**
* Selection.clearSelection()
*
* [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection}
**/
this.clearSelection = function() {
if (!this.$isEmpty) {
this.$isEmpty = true;
@ -166,12 +229,25 @@ var Selection = function(session) {
}
};
/**
* Selection.selectAll()
*
* Selects all the text in the document.
**/
this.selectAll = function() {
var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
this.moveCursorTo(0, 0);
};
/**
* Selection.setSelectionRange(range, reverse)
* - range (Range): The range of text to select
* - reverse (Boolean): Indicates if the range should go backwards (`true`) or not
*
* Sets the selection to the provided range.
*
**/
this.setSelectionRange = function(range, reverse) {
if (reverse) {
this.setSelectionAnchor(range.end.row, range.end.column);
@ -191,71 +267,150 @@ var Selection = function(session) {
mover.call(this);
};
/**
* Selection.selectTo(row, column)
* - row (Number): The row to select to
* - column (Number): The column to select to
*
* Moves the selection cursor to the indicated row and column.
*
**/
this.selectTo = function(row, column) {
this.$moveSelection(function() {
this.moveCursorTo(row, column);
});
};
/**
* Selection.selectToPosition(pos)
* - pos (Object): An object containing the row and column
*
* Moves the selection cursor to the row and column indicated by `pos`.
*
**/
this.selectToPosition = function(pos) {
this.$moveSelection(function() {
this.moveCursorToPosition(pos);
});
};
/**
* Selection.selectUp()
*
* Moves the selection up one row.
**/
this.selectUp = function() {
this.$moveSelection(this.moveCursorUp);
};
/**
* Selection.selectDown()
*
* Moves the selection down one row.
**/
this.selectDown = function() {
this.$moveSelection(this.moveCursorDown);
};
/**
* Selection.selectRight()
*
* Moves the selection right one column.
**/
this.selectRight = function() {
this.$moveSelection(this.moveCursorRight);
};
/**
* Selection.selectLeft()
*
* Moves the selection left one column.
**/
this.selectLeft = function() {
this.$moveSelection(this.moveCursorLeft);
};
/**
* Selection.selectLineStart()
*
* Moves the selection to the beginning of the current line.
**/
this.selectLineStart = function() {
this.$moveSelection(this.moveCursorLineStart);
};
/**
* Selection.selectLineEnd()
*
* Moves the selection to the end of the current line.
**/
this.selectLineEnd = function() {
this.$moveSelection(this.moveCursorLineEnd);
};
/**
* Selection.selectFileEnd()
*
* Moves the selection to the end of the file.
**/
this.selectFileEnd = function() {
this.$moveSelection(this.moveCursorFileEnd);
};
/**
* Selection.selectFileStart()
*
* Moves the selection to the start of the file.
**/
this.selectFileStart = function() {
this.$moveSelection(this.moveCursorFileStart);
};
/**
* Selection.selectWordRight()
*
* Moves the selection to the first word on the right.
**/
this.selectWordRight = function() {
this.$moveSelection(this.moveCursorWordRight);
};
/**
* Selection.selectWordLeft()
*
* Moves the selection to the first word on the left.
**/
this.selectWordLeft = function() {
this.$moveSelection(this.moveCursorWordLeft);
};
/** related to: EditSession.getWordRange
* Selection.selectWord()
*
* Moves the selection to highlight the entire word.
**/
this.selectWord = function() {
var cursor = this.getCursor();
var range = this.session.getWordRange(cursor.row, cursor.column);
this.setSelectionRange(range);
};
// Selects a word including its right whitespace
/** related to: EditSession.getAWordRange
* Selection.selectAWord()
*
* Selects a word, including its right whitespace.
**/
this.selectAWord = function() {
var cursor = this.getCursor();
var range = this.session.getAWordRange(cursor.row, cursor.column);
this.setSelectionRange(range);
};
/**
* Selection.selectLine()
*
* Selects the entire line.
**/
this.selectLine = function() {
var rowStart = this.selectionLead.row;
var rowEnd;
@ -273,14 +428,29 @@ var Selection = function(session) {
});
};
/**
* Selection.moveCursorUp()
*
* Moves the cursor up one row.
**/
this.moveCursorUp = function() {
this.moveCursorBy(-1, 0);
};
/**
* Selection.moveCursorDown()
*
* Moves the cursor down one row.
**/
this.moveCursorDown = function() {
this.moveCursorBy(1, 0);
};
/**
* Selection.moveCursorLeft()
*
* Moves the cursor left one column.
**/
this.moveCursorLeft = function() {
var cursor = this.selectionLead.getPosition(),
fold;
@ -302,6 +472,11 @@ var Selection = function(session) {
}
};
/**
* Selection.moveCursorRight()
*
* Moves the cursor right one column.
**/
this.moveCursorRight = function() {
var cursor = this.selectionLead.getPosition(),
fold;
@ -323,6 +498,11 @@ var Selection = function(session) {
}
};
/**
* Selection.moveCursorLineStart()
*
* Moves the cursor to the start of the line.
**/
this.moveCursorLineStart = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
@ -351,6 +531,11 @@ var Selection = function(session) {
}
};
/**
* Selection.moveCursorLineEnd()
*
* Moves the cursor to the end of the line.
**/
this.moveCursorLineEnd = function() {
var lead = this.selectionLead;
var lastRowColumnPosition =
@ -361,16 +546,31 @@ var Selection = function(session) {
);
};
/**
* Selection.moveCursorFileEnd()
*
* Moves the cursor to the end of the file.
**/
this.moveCursorFileEnd = function() {
var row = this.doc.getLength() - 1;
var column = this.doc.getLine(row).length;
this.moveCursorTo(row, column);
};
/**
* Selection.moveCursorFileStart()
*
* Moves the cursor to the start of the file.
**/
this.moveCursorFileStart = function() {
this.moveCursorTo(0, 0);
};
/**
* Selection.moveCursorWordRight()
*
* Moves the cursor to the word on the right.
**/
this.moveCursorWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
@ -387,14 +587,14 @@ var Selection = function(session) {
this.moveCursorTo(fold.end.row, fold.end.column);
return;
}
// first skip space
if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
column += this.session.nonTokenRe.lastIndex;
this.session.nonTokenRe.lastIndex = 0;
rightOfCursor = line.substring(column);
}
// if at line end proceed with next line
if (column >= line.length) {
this.moveCursorTo(row, line.length);
@ -403,7 +603,7 @@ var Selection = function(session) {
this.moveCursorWordRight();
return;
}
// advance to the end of the next token
if (match = this.session.tokenRe.exec(rightOfCursor)) {
column += this.session.tokenRe.lastIndex;
@ -413,6 +613,11 @@ var Selection = function(session) {
this.moveCursorTo(row, column);
};
/**
* Selection.moveCursorWordLeft()
*
* Moves the cursor to the word on the left.
**/
this.moveCursorWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
@ -428,19 +633,19 @@ var Selection = function(session) {
if (str == null) {
str = this.doc.getLine(row).substring(0, column)
}
var leftOfCursor = lang.stringReverse(str);
var match;
this.session.nonTokenRe.lastIndex = 0;
this.session.tokenRe.lastIndex = 0;
// skip whitespace
if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
column -= this.session.nonTokenRe.lastIndex;
leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
this.session.nonTokenRe.lastIndex = 0;
}
// if at begin of the line proceed in line above
if (column <= 0) {
this.moveCursorTo(row, 0);
@ -459,6 +664,13 @@ var Selection = function(session) {
this.moveCursorTo(row, column);
};
/** related to: EditSession.documentToScreenPosition
* Selection.moveCursorBy(rows, chars)
* - rows (Number): The number of rows to move by
* - chars (Number): The number of characters to move by
*
* Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document.
**/
this.moveCursorBy = function(rows, chars) {
var screenPos = this.session.documentToScreenPosition(
this.selectionLead.row,
@ -478,10 +690,24 @@ var Selection = function(session) {
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
};
/**
* Selection.moveCursorToPosition(position)
* - position (Object): The position to move to
*
* Moves the selection to the position indicated by its `row` and `column`.
**/
this.moveCursorToPosition = function(position) {
this.moveCursorTo(position.row, position.column);
};
/**
* Selection.moveCursorTo(row, column, keepDesiredColumn)
* - row (Number): The row to move to
* - column (Number): The column to move to
* - keepDesiredColumn (Boolean): [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool}
*
* Moves the cursor to the row and column provided. [If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.]{: #preventUpdateBoolDesc}
**/
this.moveCursorTo = function(row, column, keepDesiredColumn) {
// Ensure the row/column is not inside of a fold.
var fold = this.session.getFoldAt(row, column, 1);
@ -498,6 +724,14 @@ var Selection = function(session) {
this.$desiredColumn = null;
};
/**
* Selection.moveCursorToScreen(row, column, keepDesiredColumn)
* - row (Number): The row to move to
* - column (Number): The column to move to
* - keepDesiredColumn (Boolean): {:preventUpdateBool}
*
* Moves the cursor to the screen position indicated by row and column. {:preventUpdateBoolDesc}
**/
this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
var pos = this.session.screenToDocumentPosition(row, column);
this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);

View file

@ -47,6 +47,23 @@ var Editor = require("./editor").Editor;
var Renderer = require("./virtual_renderer").VirtualRenderer;
var EditSession = require("./edit_session").EditSession;
/** internal, hide
* class Split
*
*
*
**/
/** internal, hide
* new Split(container, theme, splits)
* - container (Document): The document to associate with the split
* - theme (String): The name of the initial theme
* - splits (Number): The number of initial splits
*
*
*
**/
var Split = function(container, theme, splits) {
this.BELOW = 1;
this.BESIDE = 0;
@ -87,6 +104,13 @@ var Split = function(container, theme, splits) {
return editor;
};
/** internal, hide
* Split.setSplits(splits) -> Void
* - splits (Number): The new number of splits
*
*
*
**/
this.setSplits = function(splits) {
var editor;
if (splits < 1) {
@ -116,42 +140,100 @@ var Split = function(container, theme, splits) {
this.resize();
};
/**
* Split.getSplits() -> Number
*
* Returns the number of splits.
*
**/
this.getSplits = function() {
return this.$splits;
};
/**
* Split.getEditor(idx) -> Editor
* -idx (Number): The index of the editor you want
*
* Returns the editor identified by the index `idx`.
*
**/
this.getEditor = function(idx) {
return this.$editors[idx];
};
/**
* Split.getCurrentEditor() -> Editor
*
* Returns the current editor.
*
**/
this.getCurrentEditor = function() {
return this.$cEditor;
};
/** related to: Editor.focus
* Split.focus() -> Void
*
* Focuses the current editor.
*
**/
this.focus = function() {
this.$cEditor.focus();
};
/** related to: Editor.blur
* Split.blur() -> Void
*
* Blurs the current editor.
*
**/
this.blur = function() {
this.$cEditor.blur();
};
/** related to: Editor.setTheme
* Split.setTheme(theme) -> Void
* - theme (String): The name of the theme to set
*
* Sets a theme for each of the available editors.
**/
this.setTheme = function(theme) {
this.$editors.forEach(function(editor) {
editor.setTheme(theme);
});
};
/** internal, hide
* Split.setKeyboardHandler(keybinding) -> Void
* - keybinding (String):
*
*
**/
this.setKeyboardHandler = function(keybinding) {
this.$editors.forEach(function(editor) {
editor.setKeyboardHandler(keybinding);
});
};
/** internal, hide
* Split.forEach(callback, scope) -> Void
* - callback (Function): A callback function to execute
* - scope (String):
*
* Executes `callback` on all of the available editors.
*
**/
this.forEach = function(callback, scope) {
this.$editors.forEach(callback, scope);
};
/** related to: Editor.setFontSize
* Split.setFontSize(size) -> Void
* - size (Number): The new font size
*
* Sets the font size, in pixels, for all the available editors.
*
**/
this.$fontSize = "";
this.setFontSize = function(size) {
this.$fontSize = size;
@ -187,6 +269,14 @@ var Split = function(container, theme, splits) {
return s;
};
/** related to: Editor.setSession
* Split.setSession(session, idx) -> Void
* - session (EditSession): The new edit session
* - idx (Number): The editor's index you're interested in
*
* Sets a new [[EditSession `EditSession`]] for the indicated editor.
*
**/
this.setSession = function(session, idx) {
var editor;
if (idx == null) {
@ -213,10 +303,23 @@ var Split = function(container, theme, splits) {
return session;
};
/** internal, hide
* Split.getOrientation() -> Number
*
* Returns the orientation.
*
**/
this.getOrientation = function() {
return this.$orientation;
};
/** internal, hide
* Split.setOrientation(oriantation) -> Void
* - oriantation (Number):
*
* Sets the orientation.
*
**/
this.setOrientation = function(orientation) {
if (this.$orientation == orientation) {
return;
@ -225,6 +328,12 @@ var Split = function(container, theme, splits) {
this.resize();
};
/** internal
* Split.resize() -> Void
*
*
*
**/
this.resize = function() {
var width = this.$container.clientWidth;
var height = this.$container.clientHeight;
@ -255,6 +364,12 @@ var Split = function(container, theme, splits) {
}).call(Split.prototype);
/** internal
* Split.UndoManagerProxy() -> Void
*
*
*
**/
function UndoManagerProxy(undoManager, session) {
this.$u = undoManager;
this.$doc = session;

View file

@ -467,7 +467,7 @@ exports.keys = function(map, construct) {
return exports.list(keys, construct)
}
/**
/*
* range([start,] stop[, step]) -> generator of integers
*
* Return a generator containing an arithmetic progression of integers.

View file

@ -39,6 +39,22 @@
define(function(require, exports, module) {
"use strict";
/**
* class TokenIterator
*
* This class provides an essay way to treat the document as a stream of tokens, and provides methods to iterate over these tokens.
*
**/
/**
* new TokenIterator(session, initialRow, initialColumn)
* - session (EditSession): The session to associate with
* - initialRow (Number): The row to start the tokenizing at
* - initialColumn (Number): The column to start the tokenizing at
*
* Creates a new token iterator object. The inital token index is set to the provided row and column coordinates.
*
**/
var TokenIterator = function(session, initialRow, initialColumn) {
this.$session = session;
this.$row = initialRow;
@ -49,7 +65,13 @@ var TokenIterator = function(session, initialRow, initialColumn) {
};
(function() {
/**
* TokenIterator.stepBackward() -> [String]
* + (String): If the current point is not at the top of the file, this function returns `null`. Otherwise, it returns an array of the tokenized strings.
*
* Tokenizes all the items from the current point to the row prior in the document.
**/
this.stepBackward = function() {
this.$tokenIndex -= 1;
@ -66,7 +88,12 @@ var TokenIterator = function(session, initialRow, initialColumn) {
return this.$rowTokens[this.$tokenIndex];
};
/**
* TokenIterator.stepForward() -> String
*
* Tokenizes all the items from the current point until the next row in the document. If the current point is at the end of the file, this function returns `null`. Otherwise, it returns the tokenized string.
**/
this.stepForward = function() {
var rowCount = this.$session.getLength();
this.$tokenIndex += 1;
@ -84,15 +111,33 @@ var TokenIterator = function(session, initialRow, initialColumn) {
return this.$rowTokens[this.$tokenIndex];
};
/**
* TokenIterator.getCurrentToken() -> String
*
* Returns the current tokenized string.
*
**/
this.getCurrentToken = function () {
return this.$rowTokens[this.$tokenIndex];
};
/**
* TokenIterator.getCurrentTokenRow() -> Number
*
* Returns the current row.
*
**/
this.getCurrentTokenRow = function () {
return this.$row;
};
/**
* TokenIterator.getCurrentTokenColumn() -> Number
*
* Returns the current column.
*
**/
this.getCurrentTokenColumn = function() {
var rowTokens = this.$rowTokens;
var tokenIndex = this.$tokenIndex;

View file

@ -38,6 +38,21 @@
define(function(require, exports, module) {
"use strict";
/**
* class Tokenizer
*
* This class takes a set of highlighting rules, and creates a tokenizer out of them. For more information, see [the wiki on extending highlighters](https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#wiki-extendingTheHighlighter).
*
**/
/**
* new Tokenizer(rules, flag)
* - rules (Object): The highlighting rules
* - flag (String): Any additional regular expression flags to pass (like "i" for case insensitive)
*
* Constructs a new tokenizer based on the given rules and flags.
*
**/
var Tokenizer = function(rules, flag) {
flag = flag ? "g" + flag : "g";
this.rules = rules;
@ -83,6 +98,11 @@ var Tokenizer = function(rules, flag) {
(function() {
/**
* Tokenizer.getLineTokens() -> Object
*
* Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
**/
this.getLineTokens = function(line, startState) {
var currentState = startState;
var state = this.rules[currentState];

View file

@ -40,12 +40,33 @@
define(function(require, exports, module) {
"use strict";
/**
* class UndoManager
*
* This object maintains the undo stack for an [[EditSession `EditSession`]].
*
**/
/**
* new UndoManager()
*
* Resets the current undo state and creates a new `UndoManager`.
**/
var UndoManager = function() {
this.reset();
};
(function() {
/**
* UndoManager.execute(options) -> Void
* - options (Object): Contains additional properties
*
* Provides a means for implementing your own undo manager. `options` has one property, `args`, an [[Array `Array`]], with two elements:
* * `args[0]` is an array of deltas
* * `args[1]` is the document to associate with
*
**/
this.execute = function(options) {
var deltas = options.args[0];
this.$doc = options.args[1];
@ -53,6 +74,12 @@ var UndoManager = function() {
this.$redoStack = [];
};
/**
* UndoManager.undo(dontSelect) -> Range
* - dontSelect (Boolean): {:dontSelect}
*
* [Perform an undo operation on the document, reverting the last change. Returns the range of the undo.]{: #UndoManager.undo}
**/
this.undo = function(dontSelect) {
var deltas = this.$undoStack.pop();
var undoSelectionRange = null;
@ -64,6 +91,12 @@ var UndoManager = function() {
return undoSelectionRange;
};
/**
* UndoManager.redo(dontSelect) -> Void
* - dontSelect (Boolean): {:dontSelect}
*
* [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo}
**/
this.redo = function(dontSelect) {
var deltas = this.$redoStack.pop();
var redoSelectionRange = null;
@ -75,15 +108,30 @@ var UndoManager = function() {
return redoSelectionRange;
};
/**
* UndoManager.reset() -> Void
*
* Destroys the stack of undo and redo redo operations.
**/
this.reset = function() {
this.$undoStack = [];
this.$redoStack = [];
};
/**
* UndoManager.hasUndo() -> Boolean
*
* Returns `true` if there are undo operations left to perform.
**/
this.hasUndo = function() {
return this.$undoStack.length > 0;
};
/**
* UndoManager.hasRedo() -> Boolean
*
* Returns `true` if there are redo operations left to perform.
**/
this.hasRedo = function() {
return this.$redoStack.length > 0;
};

View file

@ -58,6 +58,22 @@ var editorCss = require("ace/requirejs/text!./css/editor.css");
dom.importCssString(editorCss, "ace_editor");
/**
* class VirtualRenderer
*
* The class that is responsible for drawing everything you see on the screen!
*
**/
/**
* new VirtualRenderer(container, theme)
* - container (DOMElement): The root element of the editor
* - theme (String): The starting theme
*
* Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`.
*
**/
var VirtualRenderer = function(container, theme) {
var _self = this;
@ -188,6 +204,11 @@ var VirtualRenderer = function(container, theme) {
oop.implement(this, EventEmitter);
/**
* VirtualRenderer.setSession(session) -> Void
*
* Associates an [[EditSession `EditSession`]].
**/
this.setSession = function(session) {
this.session = session;
this.$cursorLayer.setSession(session);
@ -199,8 +220,12 @@ var VirtualRenderer = function(container, theme) {
};
/**
* Triggers partial update of the text layer
*/
* VirtualRenderer.updateLines(firstRow, lastRow) -> Void
* - firstRow (Number): The first row to update
* - lastRow (Number): The last row to update
*
* Triggers a partial update of the text, from the range given by the two parameters.
**/
this.updateLines = function(firstRow, lastRow) {
if (lastRow === undefined)
lastRow = Infinity;
@ -223,26 +248,38 @@ var VirtualRenderer = function(container, theme) {
};
/**
* Triggers full update of the text layer
*/
* VirtualRenderer.updateText() -> Void
*
* Triggers a full update of the text, for all the rows.
**/
this.updateText = function() {
this.$loop.schedule(this.CHANGE_TEXT);
};
/**
* Triggers a full update of all layers
*/
* VirtualRenderer.updateFull() -> Void
*
* Triggers a full update of all the layers, for all the rows.
**/
this.updateFull = function() {
this.$loop.schedule(this.CHANGE_FULL);
};
/**
* VirtualRenderer.updateFontSize() -> Void
*
* Updates the font size.
**/
this.updateFontSize = function() {
this.$textLayer.checkForSizeChanges();
};
/**
* Triggers resize of the editor
*/
* VirtualRenderer.onResize(force) -> Void
* - force (Boolean): If `true`, recomputes the size, even if the height and width haven't changed
*
* [Triggers a resize of the editor.]{: #VirtualRenderer.onResize}
**/
this.onResize = function(force) {
var changes = this.CHANGE_SIZE;
var size = this.$size;
@ -277,53 +314,119 @@ var VirtualRenderer = function(container, theme) {
this.$loop.schedule(changes);
};
/**
* VirtualRenderer.adjustWrapLimit() -> Void
*
* Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen.
**/
this.adjustWrapLimit = function() {
var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
var limit = Math.floor(availableWidth / this.characterWidth);
return this.session.adjustWrapLimit(limit);
};
/**
* VirtualRenderer.setAnimatedScroll(shouldAnimate) -> Void
* - shouldAnimate (Boolean): Set to `true` to show animated scrolls
*
* Identifies whether you want to have an animated scroll or not.
*
**/
this.setAnimatedScroll = function(shouldAnimate){
this.$animatedScroll = shouldAnimate;
};
/**
* VirtualRenderer.getAnimatedScroll() -> Boolean
*
* Returns whether an animated scroll happens or not.
**/
this.getAnimatedScroll = function() {
return this.$animatedScroll;
};
/**
* VirtualRenderer.setShowInvisibles(showInvisibles) -> Void
* - showInvisibles (Boolean): Set to `true` to show invisibles
*
* Identifies whether you want to show invisible characters or not.
*
**/
this.setShowInvisibles = function(showInvisibles) {
if (this.$textLayer.setShowInvisibles(showInvisibles))
this.$loop.schedule(this.CHANGE_TEXT);
};
/**
* VirtualRenderer.getShowInvisibles() -> Boolean
*
* Returns whether invisible characters are being shown or not.
**/
this.getShowInvisibles = function() {
return this.$textLayer.showInvisibles;
};
this.$showPrintMargin = true;
/**
* VirtualRenderer.setShowPrintMargin(showPrintMargin)
* - showPrintMargin (Boolean): Set to `true` to show the print margin
*
* Identifies whether you want to show the print margin or not.
*
**/
this.setShowPrintMargin = function(showPrintMargin) {
this.$showPrintMargin = showPrintMargin;
this.$updatePrintMargin();
};
/**
* VirtualRenderer.getShowPrintMargin() -> Boolean
*
* Returns whetherthe print margin is being shown or not.
**/
this.getShowPrintMargin = function() {
return this.$showPrintMargin;
};
this.$printMarginColumn = 80;
/**
* VirtualRenderer.setPrintMarginColumn(showPrintMargin)
* - showPrintMargin (Boolean): Set to `true` to show the print margin column
*
* Identifies whether you want to show the print margin column or not.
*
**/
this.setPrintMarginColumn = function(showPrintMargin) {
this.$printMarginColumn = showPrintMargin;
this.$updatePrintMargin();
};
/**
* VirtualRenderer.getPrintMarginColumn() -> Boolean
*
* Returns whether the print margin column is being shown or not.
**/
this.getPrintMarginColumn = function() {
return this.$printMarginColumn;
};
/**
* VirtualRenderer.getShowGutter() -> Boolean
*
* Returns `true` if the gutter is being shown.
**/
this.getShowGutter = function(){
return this.showGutter;
};
/**
* VirtualRenderer.setShowGutter(show) -> Void
* - show (Boolean): Set to `true` to show the gutter
*
* Identifies whether you want to show the gutter or not.
**/
this.setShowGutter = function(show){
if(this.showGutter === show)
return;
@ -352,18 +455,39 @@ var VirtualRenderer = function(container, theme) {
style.visibility = this.$showPrintMargin ? "visible" : "hidden";
};
/**
* VirtualRenderer.getContainerElement() -> DOMElement
*
* Returns the root element containing this renderer.
**/
this.getContainerElement = function() {
return this.container;
};
/**
* VirtualRenderer.getMouseEventTarget() -> DOMElement
*
* Returns the element that the mouse events are attached to
**/
this.getMouseEventTarget = function() {
return this.content;
};
/**
* VirtualRenderer.getTextAreaContainer() -> DOMElement
*
* Returns the element to which the hidden text area is added.
**/
this.getTextAreaContainer = function() {
return this.container;
};
/**
* VirtualRenderer.moveTextAreaToCursor(textarea) -> Void
* - textarea (DOMElement): A text area to work with
*
* Changes the position of `textarea` to where the cursor is pointing.
**/
this.moveTextAreaToCursor = function(textarea) {
// in IE the native cursor always shines through
// this persists in IE9
@ -384,24 +508,52 @@ var VirtualRenderer = function(container, theme) {
textarea.style.top = (bounds.top + pos.top - this.scrollTop + offset) + "px";
};
/**
* VirtualRenderer.getFirstVisibleRow() -> Number
*
* [Returns the index of the first visible row.]{: #VirtualRenderer.getFirstVisibleRow}
**/
this.getFirstVisibleRow = function() {
return this.layerConfig.firstRow;
};
/**
* VirtualRenderer.getFirstFullyVisibleRow() -> Number
*
* Returns the index of the first fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen.
**/
this.getFirstFullyVisibleRow = function() {
return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
};
/**
* VirtualRenderer.getLastFullyVisibleRow() -> Number
*
* Returns the index of the last fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen.
**/
this.getLastFullyVisibleRow = function() {
var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight);
return this.layerConfig.firstRow - 1 + flint;
};
/**
* VirtualRenderer.getLastVisibleRow() -> Number
*
* [Returns the index of the last visible row.]{: #VirtualRenderer.getLastVisibleRow}
**/
this.getLastVisibleRow = function() {
return this.layerConfig.lastRow;
};
this.$padding = null;
/**
* VirtualRenderer.setPadding(padding) -> Void
* - padding (Number): A new padding value (in pixels)
*
* Sets the padding for all the layers.
*
**/
this.setPadding = function(padding) {
this.$padding = padding;
this.$textLayer.setPadding(padding);
@ -412,10 +564,21 @@ var VirtualRenderer = function(container, theme) {
this.$updatePrintMargin();
};
/**
* VirtualRenderer.getHScrollBarAlwaysVisible() -> Boolean
*
* Returns whether the horizontal scrollbar is set to be always visible.
**/
this.getHScrollBarAlwaysVisible = function() {
return this.$horizScrollAlwaysVisible;
};
/**
* VirtualRenderer.setHScrollBarAlwaysVisible(alwaysVisible) -> Void
* - alwaysVisible (Boolean): Set to `true` to make the horizontal scroll bar visible
*
* Identifies whether you want to show the horizontal scrollbar or not.
**/
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) {
this.$horizScrollAlwaysVisible = alwaysVisible;
@ -622,44 +785,95 @@ var VirtualRenderer = function(container, theme) {
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
};
/**
* VirtualRenderer.updateFrontMarkers() -> Void
*
* Schedules an update to all the front markers in the document.
**/
this.updateFrontMarkers = function() {
this.$markerFront.setMarkers(this.session.getMarkers(true));
this.$loop.schedule(this.CHANGE_MARKER_FRONT);
};
/**
* VirtualRenderer.updateBackMarkers() -> Void
*
* Schedules an update to all the back markers in the document.
**/
this.updateBackMarkers = function() {
this.$markerBack.setMarkers(this.session.getMarkers());
this.$loop.schedule(this.CHANGE_MARKER_BACK);
};
/**
* VirtualRenderer.addGutterDecoration(row, className) -> Void
* - row (Number): The row number
* - className (String): The class to add
*
* Adds `className` to the `row`, to be used for CSS stylings and whatnot.
**/
this.addGutterDecoration = function(row, className){
this.$gutterLayer.addGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**
* VirtualRenderer.removeGutterDecoration(row, className)-> Void
* - row (Number): The row number
* - className (String): The class to add
*
* Removes `className` from the `row`.
**/
this.removeGutterDecoration = function(row, className){
this.$gutterLayer.removeGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**
* VirtualRenderer.setBreakpoints(rows) -> Void
* - rows (Array): An array containg row numbers
*
* Sets a breakpoint for every row number indicated on `rows`.
**/
this.setBreakpoints = function(rows) {
this.$gutterLayer.setBreakpoints(rows);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**
* VirtualRenderer.setAnnotations(annotations) -> Void
* - annotations (Array): An array containing annotations
*
* Sets annotations for the gutter.
**/
this.setAnnotations = function(annotations) {
this.$gutterLayer.setAnnotations(annotations);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**
* VirtualRenderer.updateCursor() -> Void
*
* Updates the cursor icon.
**/
this.updateCursor = function() {
this.$loop.schedule(this.CHANGE_CURSOR);
};
/**
* VirtualRenderer.hideCursor() -> Void
*
* Hides the cursor icon.
**/
this.hideCursor = function() {
this.$cursorLayer.hideCursor();
};
/**
* VirtualRenderer.showCursor() -> Void
*
* Shows the cursor icon.
**/
this.showCursor = function() {
this.$cursorLayer.showCursor();
};
@ -670,6 +884,11 @@ var VirtualRenderer = function(container, theme) {
this.scrollCursorIntoView(lead);
};
/**
* VirtualRenderer.scrollCursorIntoView() -> Void
*
* Scrolls the cursor into the first visibile area of the editor
**/
this.scrollCursorIntoView = function(cursor) {
// the editor is not visible
if (this.$size.scrollerHeight === 0)
@ -701,45 +920,59 @@ var VirtualRenderer = function(container, theme) {
}
};
/** related to: EditSession.getScrollTop
* VirtualRenderer.getScrollTop() -> Number
*
* {:EditSession.getScrollTop}
**/
this.getScrollTop = function() {
return this.session.getScrollTop();
};
/** related to: EditSession.getScrollLeft
* VirtualRenderer.getScrollLeft() -> Number
*
* {:EditSession.getScrollLeft}
**/
this.getScrollLeft = function() {
return this.session.getScrollLeft();
};
/**
* VirtualRenderer.getScrollTopRow() -> Number
*
* Returns the first visible row, regardless of whether it's fully visible or not.
**/
this.getScrollTopRow = function() {
return this.scrollTop / this.lineHeight;
};
/**
* VirtualRenderer.getScrollBottomRow() -> Number
*
* Returns the last visible row, regardless of whether it's fully visible or not.
**/
this.getScrollBottomRow = function() {
return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
};
/** related to: EditSession.setScrollTop
* VirtualRenderer.scrollToRow(row) -> Void
* - row (Number): A row id
*
* Gracefully scrolls the top of the editor to the row indicated.
**/
this.scrollToRow = function(row) {
this.session.setScrollTop(row * this.lineHeight);
};
this.STEPS = 10;
this.$calcSteps = function(fromValue, toValue){
var i = 0;
var l = this.STEPS;
var steps = [];
var func = function(t, x_min, dx) {
if ((t /= .5) < 1)
return dx / 2 * Math.pow(t, 3) + x_min;
return dx / 2 * (Math.pow(t - 2, 3) + 2) + x_min;
};
for (i = 0; i < l; ++i)
steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
steps.push(toValue);
return steps;
};
/**
* VirtualRenderer.scrollToLine(line, center) -> Void
* - line (Number): A line number
* - center (Boolean): If `true`, centers the editor the to indicated line
*
* Gracefully scrolls the editor to the row indicated.
**/
this.scrollToLine = function(line, center) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = pos.top;
@ -759,10 +992,17 @@ var VirtualRenderer = function(container, theme) {
}, 10);
}
else {
this.session.setScrollTop(offset);
this.session.setScrollTop(offset);
}
};
/**
* VirtualRenderer.scrollToY(scrollTop) -> Number
* - scrollTop (Number): The position to scroll to
*
* Scrolls the editor to the y pixel indicated.
*
**/
this.scrollToY = function(scrollTop) {
// after calling scrollBar.setScrollTop
// scrollbar sends us event with same scrollTop. ignore it
@ -772,6 +1012,13 @@ var VirtualRenderer = function(container, theme) {
}
};
/**
* VirtualRenderer.scrollToX(scrollLeft) -> Number
* - scrollLeft (Number): The position to scroll to
*
* Scrolls the editor to the x pixel indicated.
*
**/
this.scrollToX = function(scrollLeft) {
if (scrollLeft <= this.$padding)
scrollLeft = 0;
@ -781,11 +1028,25 @@ var VirtualRenderer = function(container, theme) {
this.$loop.schedule(this.CHANGE_H_SCROLL);
};
/**
* VirtualRenderer.scrollBy(deltaX, deltaY) -> Void
* - deltaX (Number): The x value to scroll by
* - deltaY (Number): The y value to scroll by
*
* Scrolls the editor across both x- and y-axes.
**/
this.scrollBy = function(deltaX, deltaY) {
deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
};
/**
* VirtualRenderer.isScrollableBy(deltaX, deltaY) -> Boolean
* - deltaX (Number): The x value to scroll by
* - deltaY (Number): The y value to scroll by
*
* Returns `true` if you can still scroll by either parameter; in other words, you haven't reached the end of the file or line.
**/
this.isScrollableBy = function(deltaX, deltaY) {
if (deltaY < 0 && this.session.getScrollTop() > 0)
return true;
@ -794,19 +1055,6 @@ var VirtualRenderer = function(container, theme) {
// todo: handle horizontal scrolling
};
this.pixelToScreenCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round(
(pageX + this.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft()) / this.characterWidth
);
var row = Math.floor(
(pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop()) / this.lineHeight
);
return {row: row, column: col};
};
this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
@ -820,6 +1068,15 @@ var VirtualRenderer = function(container, theme) {
return this.session.screenToDocumentPosition(row, Math.max(col, 0));
};
/**
* VirtualRenderer.textToScreenCoordinates(row, column) -> Object
* - row (Number): The document row position
* - column (Number): The document column position
*
* Returns an object containing the `pageX` and `pageY` coordinates of the document position.
*
*
**/
this.textToScreenCoordinates = function(row, column) {
var canvasPos = this.scroller.getBoundingClientRect();
var pos = this.session.documentToScreenPosition(row, column);
@ -833,14 +1090,29 @@ var VirtualRenderer = function(container, theme) {
};
};
/**
* VirtualRenderer.visualizeFocus() -> Void
*
* Focuses the current container.
**/
this.visualizeFocus = function() {
dom.addCssClass(this.container, "ace_focus");
};
/**
* VirtualRenderer.visualizeBlur() -> Void
*
* Blurs the current container.
**/
this.visualizeBlur = function() {
dom.removeCssClass(this.container, "ace_focus");
};
/** internal, hide
* VirtualRenderer.showComposition(position) -> Void
* - position (Number):
*
**/
this.showComposition = function(position) {
if (!this.$composition) {
this.$composition = dom.createElement("div");
@ -859,10 +1131,21 @@ var VirtualRenderer = function(container, theme) {
this.hideCursor();
};
/**
* VirtualRenderer.setCompositionText(text) -> Void
* - text (String): A string of text to use
*
* Sets the inner text of the current composition to `text`.
**/
this.setCompositionText = function(text) {
dom.setInnerText(this.$composition, text);
};
/**
* VirtualRenderer.hideComposition() -> Void
*
* Hides the current composition.
**/
this.hideComposition = function() {
this.showCursor();
@ -883,6 +1166,12 @@ var VirtualRenderer = function(container, theme) {
net.loadScript(filename, callback);
};
/**
* VirtualRenderer.setTheme(theme) -> Void
* - theme (String): The path to a theme
*
* [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme}
**/
this.setTheme = function(theme) {
var _self = this;
@ -937,6 +1226,11 @@ var VirtualRenderer = function(container, theme) {
}
};
/**
* VirtualRenderer.getTheme() -> String
*
* [Returns the path of the current theme.]{: #VirtualRenderer.getTheme}
**/
this.getTheme = function() {
return this.$themeValue;
};
@ -945,14 +1239,31 @@ var VirtualRenderer = function(container, theme) {
// This feature can be used by plug-ins to provide a visual indication of
// a certain mode that editor is in.
/**
* VirtualRenderer.setStyle(style) -> Void
* - style (String): A class name
*
* [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle}
**/
this.setStyle = function setStyle(style) {
dom.addCssClass(this.container, style);
};
/**
* VirtualRenderer.unsetStyle(style) -> Void
* - style (String): A class name
*
* [Removes the class `style` from the editor.]{: #VirtualRenderer.unsetStyle}
**/
this.unsetStyle = function unsetStyle(style) {
dom.removeCssClass(this.container, style);
};
/**
* VirtualRenderer.destroy()
*
* Destroys the text and cursor layers for this renderer.
**/
this.destroy = function() {
this.$textLayer.destroy();
this.$cursorLayer.destroy();