Merge branch 'ui/navbar'

Conflicts:
	build/demo/kitchen-sink/kitchen-sink-uncompressed.js
	build/src/ace-uncompressed-noconflict.js
	build/src/ace-uncompressed.js
	build/textarea/src/ace-bookmarklet.js
	lib/ace/edit_session.js
	lib/ace/editor.js
	lib/ace/multi_select.js
	lib/ace/selection.js
	lib/ace/virtual_renderer.js
This commit is contained in:
Fabian Jakobs 2012-05-01 11:30:17 +02:00
commit 43c4a8fc35
29 changed files with 630 additions and 287 deletions

View file

@ -78,6 +78,7 @@ var Editor = function(renderer, session) {
this.container = container;
this.renderer = renderer;
this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
this.keyBinding = new KeyBinding(this);
@ -94,7 +95,6 @@ var Editor = function(renderer, session) {
wrap: true
});
this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
this.setSession(session || new EditSession(""));
};
@ -458,6 +458,7 @@ var Editor = function(renderer, session) {
this.$highlightBrackets();
this.$updateHighlightActiveLine();
this.$updateHighlightGutterLine();
};
/** internal, hide
@ -470,13 +471,10 @@ var Editor = function(renderer, session) {
if (session.$highlightLineMarker)
session.removeMarker(session.$highlightLineMarker);
if (typeof this.$lastrow == "number")
this.renderer.removeGutterDecoration(this.$lastrow, "ace_gutter_active_line");
session.$highlightLineMarker = null;
this.$lastrow = null;
if (this.getHighlightActiveLine()) {
if (this.$highlightActiveLine) {
var cursor = this.getCursorPosition(),
foldLine = this.session.getFoldLine(cursor.row);
@ -489,11 +487,24 @@ var Editor = function(renderer, session) {
}
session.$highlightLineMarker = session.addMarker(range, "ace_active_line", "background");
}
this.renderer.addGutterDecoration(this.$lastrow = cursor.row, "ace_gutter_active_line");
}
};
/** internal, hide
* Editor.$updateHighlightGutterLine()
*
*
**/
this.$updateHighlightGutterLine = function(){
if (typeof this.$lastrow == "number")
this.renderer.removeGutterDecoration(this.$lastrow, "ace_gutter_active_line");
this.$lastrow = null;
if (this.$highlightGutterLine)
this.renderer.addGutterDecoration(
this.$lastrow = this.getCursorPosition().row, "ace_gutter_active_line");
}
/**
* Editor@onSelectionChange(e)
* - e (Object): Contains a single property, `data`, which has the delta of changes
@ -514,6 +525,7 @@ var Editor = function(renderer, session) {
session.$selectionMarker = session.addMarker(range, "ace_selection", style);
} else {
this.$updateHighlightActiveLine();
this.$updateHighlightGutterLine();
}
if (this.$highlightSelectedWord)
@ -592,6 +604,7 @@ var Editor = function(renderer, session) {
// Update the active line marker as due to folding changes the current
// line range on the screen might have changed.
this.$updateHighlightActiveLine();
this.$updateHighlightGutterLine();
// TODO: This might be too much updating. Okay for now.
this.renderer.updateFull();
};
@ -610,15 +623,34 @@ var Editor = function(renderer, session) {
return text;
};
/**
* Editor.onCopy()
*
* Called whenever a text "copy" happens.
**/
this.onCopy = function() {
this.commands.exec("copy", this);
};
/**
* Editor.onCut()
*
* Emitted whenever a text "cut" happens.
* called whenever a text "cut" happens.
**/
this.onCut = function() {
this.commands.exec("cut", this);
};
/**
* Editor.onPaste()
*
* called whenever a text "paste" happens.
**/
this.onPaste = function(text) {
this._emit("paste", text);
this.insert(text);
};
/**
* Editor.insert(text)
* - text (String): The new text to add
@ -724,11 +756,8 @@ var Editor = function(renderer, session) {
*
* Emitted when text is entered.
**/
this.onTextInput = function(text, pasted) {
if (pasted)
this._emit("paste", text);
this.keyBinding.onTextInput(text, pasted);
this.onTextInput = function(text) {
this.keyBinding.onTextInput(text);
};
/**
@ -844,7 +873,8 @@ var Editor = function(renderer, session) {
*
**/
this.setHighlightActiveLine = function(shouldHighlight) {
if (this.$highlightActiveLine == shouldHighlight) return;
if (this.$highlightActiveLine == shouldHighlight)
return;
this.$highlightActiveLine = shouldHighlight;
this.$updateHighlightActiveLine();
@ -859,6 +889,19 @@ var Editor = function(renderer, session) {
return this.$highlightActiveLine;
};
this.$highlightGutterLine = true;
this.setHighlightGutterLine = function(shouldHighlightGutterLine) {
if (this.$highlightGutterLine == shouldHighlightGutterLine)
return;
this.$highlightGutterLine = shouldHighlightGutterLine;
this.$updateHighlightGutterLine();
};
this.getHighlightGutterLine = function() {
return this.$highlightGutterLine;
};
this.$highlightSelectedWord = true;
/**
* Editor.setHighlightSelectedWord(shouldHighlight)
@ -1013,6 +1056,14 @@ var Editor = function(renderer, session) {
return this.renderer.$gutterLayer.getShowFoldWidgets();
};
this.setFadeFoldWidgets = function(show) {
this.renderer.setFadeFoldWidgets(show);
};
this.getFadeFoldWidgets = function() {
return this.renderer.getFadeFoldWidgets();
};
/**
* Editor.remove(dir)
* - dir (String): The direction of the deletion to occur, either "left" or "right"
@ -1022,7 +1073,7 @@ var Editor = function(renderer, session) {
**/
this.remove = function(dir) {
if (this.selection.isEmpty()){
if(dir == "left")
if (dir == "left")
this.selection.selectLeft();
else
this.selection.selectRight();
@ -1447,15 +1498,29 @@ var Editor = function(renderer, session) {
return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
};
this.$getPageDownRow = function() {
return this.renderer.getScrollBottomRow();
};
this.$moveByPage = function(dir, select) {
var renderer = this.renderer;
var config = this.renderer.layerConfig;
var rows = dir * Math.floor(config.height / config.lineHeight);
this.$getPageUpRow = function() {
var firstRow = this.renderer.getScrollTopRow();
var lastRow = this.renderer.getScrollBottomRow();
this.$blockScrolling++;
if (select == true) {
this.selection.$moveSelection(function(){
this.moveCursorBy(rows, 0);
});
} else if (select == false) {
this.selection.moveCursorBy(rows, 0);
this.selection.clearSelection();
}
this.$blockScrolling--;
return firstRow - (lastRow - firstRow);
var scrollTop = renderer.scrollTop;
renderer.scrollBy(0, rows * config.lineHeight);
if (select != null)
renderer.scrollCursorIntoView(null, 0.5);
renderer.animateScrolling(scrollTop);
};
/**
@ -1464,14 +1529,7 @@ var Editor = function(renderer, session) {
* Selects the text from the current position of the document until where a "page down" finishes.
**/
this.selectPageDown = function() {
var row = this.$getPageDownRow() + Math.floor(this.$getVisibleRowCount() / 2);
this.scrollPageDown();
var selection = this.getSelection();
var leadScreenPos = this.session.documentToScreenPosition(selection.getSelectionLead());
var dest = this.session.screenToDocumentPosition(row, leadScreenPos.column);
selection.selectTo(dest.row, dest.column);
this.$moveByPage(1, true);
};
/**
@ -1480,15 +1538,7 @@ var Editor = function(renderer, session) {
* Selects the text from the current position of the document until where a "page up" finishes.
**/
this.selectPageUp = function() {
var visibleRows = this.renderer.getScrollTopRow() - this.renderer.getScrollBottomRow();
var row = this.$getPageUpRow() + Math.round(visibleRows / 2);
this.scrollPageUp();
var selection = this.getSelection();
var leadScreenPos = this.session.documentToScreenPosition(selection.getSelectionLead());
var dest = this.session.screenToDocumentPosition(row, leadScreenPos.column);
selection.selectTo(dest.row, dest.column);
this.$moveByPage(-1, true);
};
/**
@ -1497,11 +1547,7 @@ var Editor = function(renderer, session) {
* Shifts the document to wherever "page down" is, as well as moving the cursor position.
**/
this.gotoPageDown = function() {
var row = this.$getPageDownRow();
var column = this.getCursorPositionScreen().column;
this.scrollToRow(row);
this.getSelection().moveCursorToScreen(row, column);
this.$moveByPage(1, false);
};
/**
@ -1510,11 +1556,7 @@ var Editor = function(renderer, session) {
* Shifts the document to wherever "page up" is, as well as moving the cursor position.
**/
this.gotoPageUp = function() {
var row = this.$getPageUpRow();
var column = this.getCursorPositionScreen().column;
this.scrollToRow(row);
this.getSelection().moveCursorToScreen(row, column);
this.$moveByPage(-1, false);
};
/**
@ -1523,7 +1565,7 @@ var Editor = function(renderer, session) {
* Scrolls the document to wherever "page down" is, without changing the cursor position.
**/
this.scrollPageDown = function() {
this.scrollToRow(this.$getPageDownRow());
this.$moveByPage(1);
};
/**
@ -1532,7 +1574,7 @@ var Editor = function(renderer, session) {
* Scrolls the document to wherever "page up" is, without changing the cursor position.
**/
this.scrollPageUp = function() {
this.renderer.scrollToRow(this.$getPageUpRow());
this.$moveByPage(-1);
};
/** related to: VirtualRenderer.scrollToRow
@ -1550,11 +1592,13 @@ var Editor = function(renderer, session) {
* Editor.scrollToLine(line, center)
* - line (Number): The line to scroll to
* - center (Boolean): If `true`
* - animate (Boolean): If `true` animates scrolling
* - callback (Function): Function to be called when the animation has finished
*
* TODO scrollsa to line, if center == true, puts line in middle of screen or attempts to)
* TODO scrolls a to line, if center == true, puts line in middle of screen or attempts to)
**/
this.scrollToLine = function(line, center) {
this.renderer.scrollToLine(line, center);
this.scrollToLine = function(line, center, animate, callback) {
this.renderer.scrollToLine(line, center, animate, callback);
};
/**
@ -1672,19 +1716,21 @@ var Editor = function(renderer, session) {
* Editor.gotoLine(lineNumber, column)
* - lineNumber (Number): The line number to go to
* - column (Number): A column number to go to
* - animate (Boolean): If `true` animates scolling
*
* Moves the cursor to the specified line number, and also into the indiciated column.
*
**/
this.gotoLine = function(lineNumber, column) {
this.gotoLine = function(lineNumber, column, animate) {
this.selection.clearSelection();
this.session.unfold({row: lineNumber - 1, column: column || 0});
this.$blockScrolling += 1;
this.moveCursorTo(lineNumber-1, column || 0);
this.moveCursorTo(lineNumber - 1, column || 0);
this.$blockScrolling -= 1;
if (!this.isRowFullyVisible(this.getCursorPosition().row))
this.scrollToLine(lineNumber, true);
if (!this.isRowFullyVisible(lineNumber - 1))
this.scrollToLine(lineNumber - 1, true, animate);
};
/** related to: Editor.moveCursorTo
@ -1790,8 +1836,10 @@ var Editor = function(renderer, session) {
* Moves the cursor to the end of the current file. Note that this does de-select the current selection.
**/
this.navigateFileEnd = function() {
var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileEnd();
this.clearSelection();
this.renderer.animateScrolling(scrollTop);
};
/**
@ -1800,8 +1848,10 @@ var Editor = function(renderer, session) {
* Moves the cursor to the start of the current file. Note that this does de-select the current selection.
**/
this.navigateFileStart = function() {
var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileStart();
this.clearSelection();
this.renderer.animateScrolling(scrollTop);
};
/**
@ -1910,44 +1960,45 @@ var Editor = function(renderer, session) {
* Editor.find(needle, options)
* - needle (String): The text to search for
* - options (Object): An object defining various search properties
* - animate (Boolean): If `true` animate scrolling
*
* Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]].
**/
this.find = function(needle, options) {
this.find = function(needle, options, animate) {
this.clearSelection();
options = options || {};
options.needle = needle;
this.$search.set(options);
this.$find();
this.$find(false, animate);
};
/** related to: Editor.find
* Editor.findNext(options)
* - options (Object): search options
* - animate (Boolean): If `true` animate scrolling
*
* Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
**/
this.findNext = function(options) {
this.findNext = function(options, animate) {
options = options || {};
if (typeof options.backwards == "undefined")
options.backwards = false;
this.$search.set(options);
this.$find();
this.$find(false, animate);
};
/** related to: Editor.find
* Editor.findPrevious(options)
* - options (Object): search options
* - animate (Boolean): If `true` animate scrolling
*
* Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
**/
this.findPrevious = function(options) {
this.findPrevious = function(options, animate) {
options = options || {};
if (typeof options.backwards == "undefined")
options.backwards = true;
this.$search.set(options);
this.$find();
this.$find(true, animate);
};
this.$find = function(backwards) {
this.$find = function(backwards, animate) {
if (!this.selection.isEmpty())
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
@ -1956,24 +2007,14 @@ var Editor = function(renderer, session) {
var range = this.$search.find(this.session);
if (range) {
this.session.unfold(range);
this.$blockScrolling += 1;
this.session.unfold(range);
this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;
if (this.getAnimatedScroll()) {
var cursor = this.getCursorPosition();
if (!this.isRowFullyVisible(cursor.row))
this.scrollToLine(cursor.row, true);
//@todo scroll X
//if (!this.isColumnFullyVisible(cursor.column))
//this.scrollToRow(cursor.column);
}
else {
this.renderer.scrollSelectionIntoView(range.start, range.end);
}
var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
this.renderer.animateScrolling(scrollTop);
}
};
@ -1983,7 +2024,10 @@ var Editor = function(renderer, session) {
* {:UndoManager.undo}
**/
this.undo = function() {
this.$blockScrolling++;
this.session.getUndoManager().undo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);
};
/** related to: UndoManager.redo
@ -1992,7 +2036,10 @@ var Editor = function(renderer, session) {
* {:UndoManager.redo}
**/
this.redo = function() {
this.$blockScrolling++;
this.session.getUndoManager().redo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);
};
/**