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

@ -1,3 +1,5 @@
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
body { body {
margin:0; margin:0;
padding:0; padding:0;

View file

@ -301,7 +301,8 @@ split.on("focus", function(editor) {
}); });
env.split = split; env.split = split;
window.env = env; window.env = env;
window.ace = env.editor; window.editor = window.ace = env.editor;
env.editor.setAnimatedScroll(true);
var docEl = document.getElementById("doc"); var docEl = document.getElementById("doc");
var modeEl = document.getElementById("mode"); var modeEl = document.getElementById("mode");
@ -395,10 +396,28 @@ function saveOption(el, val) {
} }
} }
event.addListener(themeEl, "mouseover", function(e){
this.desiredValue = e.target.value;
if (!this.$timer)
this.$timer = setTimeout(this.updateTheme);
})
event.addListener(themeEl, "mouseout", function(e){
this.desiredValue = null;
if (!this.$timer)
this.$timer = setTimeout(this.updateTheme, 20);
})
themeEl.updateTheme = function(){
env.split.setTheme(themeEl.desiredValue || themeEl.selectedValue);
themeEl.$timer = null;
}
bindDropdown("theme", function(value) { bindDropdown("theme", function(value) {
if (!value) if (!value)
return; return;
env.editor.setTheme(value); env.editor.setTheme(value);
themeEl.selectedValue = value;
}); });
bindDropdown("keybinding", function(value) { bindDropdown("keybinding", function(value) {
@ -480,6 +499,9 @@ bindCheckbox("enable_behaviours", function(checked) {
env.editor.setBehavioursEnabled(checked); env.editor.setBehavioursEnabled(checked);
}); });
bindCheckbox("fade_fold_widgets", function(checked) {
env.editor.setFadeFoldWidgets(checked);
});
var secondSession = null; var secondSession = null;
bindDropdown("split", function(value) { bindDropdown("split", function(value) {

View file

@ -1,3 +1,5 @@
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
html { html {
height: 100%; height: 100%;
width: 100%; width: 100%;

@ -1 +1 @@
Subproject commit d2a65d0addc2e5ab922bbff9cb6022a4652b4f13 Subproject commit cc5ccde4565f7b21c81345f47e941e011e94b810

View file

@ -200,6 +200,14 @@
<input type="checkbox" id="enable_behaviours"> <input type="checkbox" id="enable_behaviours">
</td> </td>
</tr> </tr>
<tr>
<td >
<label for="fade_fold_widgets">Fade Fold Widgets</label>
</td>
<td>
<input type="checkbox" id="fade_fold_widgets" checked>
</td>
</tr>
</table> </table>
<div id="editor"> <div id="editor">

View file

@ -31,7 +31,7 @@ var CommandManager = function(platform, commands) {
this.addCommands(commands); this.addCommands(commands);
this.setDefaultHandler("exec", function(e) { this.setDefaultHandler("exec", function(e) {
e.command.exec(e.editor, e.args || {}); return e.command.exec(e.editor, e.args || {});
}); });
}; };
@ -51,8 +51,18 @@ oop.inherits(CommandManager, HashHandler);
if (editor && editor.$readOnly && !command.readOnly) if (editor && editor.$readOnly && !command.readOnly)
return false; return false;
this._emit("exec", {editor: editor, command: command, args: args}); try {
var retvalue = this._emit("exec", {
editor: editor,
command: command,
args: args
});
} catch (e) {
window.console && window.console.log(e);
return true; return true;
}
return retvalue === false ? false : true;
}; };
this.toggleRecording = function() { this.toggleRecording = function() {

View file

@ -311,7 +311,7 @@ exports.commands = [{
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {
name: "togglecomment", name: "togglecomment",
bindKey: bindKey("Ctrl-7", "Command-7"), bindKey: bindKey("Ctrl-/", "Command-/"),
exec: function(editor) { editor.toggleCommentLines(); }, exec: function(editor) { editor.toggleCommentLines(); },
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {

View file

@ -84,16 +84,17 @@ exports.defaultCommands = [{
exec: function(editor) { editor.multiSelect.splitIntoLines(); }, exec: function(editor) { editor.multiSelect.splitIntoLines(); },
bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"}, bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"},
readonly: true readonly: true
}]; }, {
// commands active in multiselect mode
exports.multiEditCommands = [{
name: "singleSelection", name: "singleSelection",
bindKey: "esc", bindKey: "esc",
exec: function(editor) { editor.exitMultiSelectMode(); }, exec: function(editor) { editor.exitMultiSelectMode(); },
readonly: true readonly: true,
isAvailable: function(editor) {return editor.inMultiSelectMode}
}]; }];
// commands active in multiselect mode
exports.multiEditCommands = {"singleSelection": "esc"};
var HashHandler = require("../keyboard/hash_handler").HashHandler; var HashHandler = require("../keyboard/hash_handler").HashHandler;
exports.keyboardHandler = new HashHandler(exports.multiEditCommands); exports.keyboardHandler = new HashHandler(exports.multiEditCommands);

View file

@ -1,4 +1,3 @@
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
.ace_editor { .ace_editor {
position: absolute; position: absolute;
@ -131,6 +130,7 @@
.ace_text-layer { .ace_text-layer {
color: black; color: black;
font: inherit !important;
} }
.ace_cjk { .ace_cjk {
@ -179,10 +179,6 @@
z-index: 2; z-index: 2;
} }
.ace_gutter .ace_gutter_active_line{
background-color : #dcdcdc;
}
.ace_marker-layer .ace_selected_word { .ace_marker-layer .ace_selected_word {
position: absolute; position: absolute;
z-index: 4; z-index: 4;
@ -289,3 +285,25 @@
background-color: #FFB4B4; background-color: #FFB4B4;
border-color: #DE5555; border-color: #DE5555;
} }
.ace_fade-fold-widgets .ace_fold-widget {
-moz-transition: 0.5s opacity;
-webkit-transition: 0.5s opacity;
-o-transition: 0.5s opacity;
-ms-transition: 0.5s opacity;
transition: 0.5s opacity;
opacity: 0;
}
.ace_fade-fold-widgets:hover .ace_fold-widget {
-moz-transition-duration: 0.05s;
-webkit-transition-duration: 0.05s;
-o-transition-duration: 0.05s;
-ms-transition-duration: 0.05s;
transition-duration: 0.05s;
-moz-transition-delay: 0.2s;
-webkit-transition-delay: 0.2s;
-o-transition-delay: 0.2s;
-ms-transition-delay: 0.2s;
transition-delay: 0.2s;
opacity:1;
}

View file

@ -257,10 +257,9 @@ var Document = function(text) {
range.end.column); range.end.column);
} }
else { else {
var lines = []; var lines = this.getLines(range.start.row+1, range.end.row-1);
lines.push(this.$lines[range.start.row].substring(range.start.column)); lines.unshift((this.$lines[range.start.row] || "").substring(range.start.column));
lines.push.apply(lines, this.getLines(range.start.row+1, range.end.row-1)); lines.push((this.$lines[range.end.row] || "").substring(0, range.end.column));
lines.push(this.$lines[range.end.row].substring(0, range.end.column));
return lines.join(this.getNewLineCharacter()); return lines.join(this.getNewLineCharacter());
} }
}; };

View file

@ -93,10 +93,7 @@ var EditSession = function(text, mode) {
} }
this.selection = new Selection(this); this.selection = new Selection(this);
if (mode)
this.setMode(mode); this.setMode(mode);
else
this.setMode(new TextMode());
}; };
@ -784,6 +781,7 @@ var EditSession = function(text, mode) {
return callback(_self.$modes[mode]); return callback(_self.$modes[mode]);
_self.$modes[mode] = new module.Mode(); _self.$modes[mode] = new module.Mode();
_self.$modes[mode].$id = mode;
_self._emit("loadmode", { _self._emit("loadmode", {
name: mode, name: mode,
mode: _self.$modes[mode] mode: _self.$modes[mode]
@ -801,8 +799,6 @@ var EditSession = function(text, mode) {
} }
}; };
this.$mode = null;
this.$origMode = null;
/** /**
* EditSession.setMode(mode) * EditSession.setMode(mode)
* - mode (TextMode): Set a new text mode * - mode (TextMode): Set a new text mode
@ -810,24 +806,34 @@ var EditSession = function(text, mode) {
* Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted.
* *
**/ **/
this.$mode = null;
this.$modeId = null;
this.setMode = function(mode) { this.setMode = function(mode) {
this.$origMode = mode;
// load on demand // load on demand
if (typeof mode === "string") { if (typeof mode === "string") {
if (this.$modeId == mode)
return;
this.$modeId = mode;
var _self = this; var _self = this;
this._loadMode(mode, function(module) { this._loadMode(mode, function(module) {
if (_self.$origMode !== mode) if (_self.$modeId !== mode)
return; return;
_self.setMode(module); _self.setMode(module);
}); });
return; return;
} else if (mode == null) {
mode = "ace/mode/text"
this.$modeId = mode;
this.$modes[mode] = this.$modes[mode] || (new TextMode());
this.setMode(this.$modes[mode]);
return;
} }
if (this.$mode === mode) return; if (this.$mode === mode) return;
this.$mode = mode; this.$mode = mode;
this.$modeId = mode.$id;
this.$stopWorker(); this.$stopWorker();

View file

@ -177,7 +177,9 @@ function FoldLine(foldData, folds) {
&& fold.start.column != column && fold.start.column != column
&& fold.start.row != row) && fold.start.row != row)
{ {
throw "Moving characters inside of a fold should never be reached"; //throwing here breaks whole editor
//@todo properly handle this
window.console && window.console.log(row, column, fold);
} else if (fold.start.row == row) { } else if (fold.start.row == row) {
folds = this.folds; folds = this.folds;
var i = folds.indexOf(fold); var i = folds.indexOf(fold);

View file

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

View file

@ -82,7 +82,7 @@ module.exports = {
editor.navigateTo(0, 0); editor.navigateTo(0, 0);
editor.gotoLine(101); editor.gotoLine(101);
assert.position(editor.getCursorPosition(), 100, 0); assert.position(editor.getCursorPosition(), 100, 0);
assert.equal(editor.getFirstVisibleRow(), 90); assert.equal(editor.getFirstVisibleRow(), 89);
editor.navigateTo(100, 0); editor.navigateTo(100, 0);
editor.gotoLine(11); editor.gotoLine(11);
@ -102,7 +102,7 @@ module.exports = {
editor.navigateTo(0, 0); editor.navigateTo(0, 0);
editor.gotoLine(191); editor.gotoLine(191);
assert.position(editor.getCursorPosition(), 190, 0); assert.position(editor.getCursorPosition(), 190, 0);
assert.equal(editor.getFirstVisibleRow(), 180); assert.equal(editor.getFirstVisibleRow(), 179);
editor.navigateTo(0, 0); editor.navigateTo(0, 0);
editor.gotoLine(196); editor.gotoLine(196);

View file

@ -78,6 +78,18 @@ function HashHandler(config, platform) {
} }
}; };
this.bindKey = function(key, command) {
if(!key)
return;
var ckb = this.commmandKeyBinding;
key.split("|").forEach(function(keyPart) {
var binding = this.parseKeys(keyPart, command);
var hashId = binding.hashId;
(ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
}, this);
};
this.addCommands = function(commands) { this.addCommands = function(commands) {
commands && Object.keys(commands).forEach(function(name) { commands && Object.keys(commands).forEach(function(name) {
var command = commands[name]; var command = commands[name];
@ -100,18 +112,6 @@ function HashHandler(config, platform) {
}, this); }, this);
}; };
this.bindKey = function(key, command) {
if(!key)
return;
var ckb = this.commmandKeyBinding;
key.split("|").forEach(function(keyPart) {
var binding = parseKeys(keyPart, command);
var hashId = binding.hashId;
(ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
});
};
this.bindKeys = function(keyList) { this.bindKeys = function(keyList) {
Object.keys(keyList).forEach(function(key) { Object.keys(keyList).forEach(function(key) {
this.bindKey(key, keyList[key]); this.bindKey(key, keyList[key]);
@ -127,10 +127,10 @@ function HashHandler(config, platform) {
this.bindKey(key, command); this.bindKey(key, command);
}; };
function parseKeys(keys, val, ret) { this.parseKeys = function(keys, val) {
var key; var key;
var hashId = 0; var hashId = 0;
var parts = splitSafe(keys.toLowerCase()); var parts = keys.toLowerCase().trim().split(/\s*\-\s*/);
for (var i = 0, l = parts.length; i < l; i++) { for (var i = 0, l = parts.length; i < l; i++) {
if (keyUtil.KEY_MODS[parts[i]]) if (keyUtil.KEY_MODS[parts[i]])
@ -143,17 +143,12 @@ function HashHandler(config, platform) {
key: key, key: key,
hashId: hashId hashId: hashId
}; };
} };
function splitSafe(s) {
return (s.trim()
.split(new RegExp("[\\s ]*\\-[\\s ]*", "g"), 999));
}
this.findKeyCommand = function findKeyCommand(hashId, keyString) { this.findKeyCommand = function findKeyCommand(hashId, keyString) {
var ckbr = this.commmandKeyBinding; var ckbr = this.commmandKeyBinding;
return ckbr[hashId] && ckbr[hashId][keyString.toLowerCase()]; return ckbr[hashId] && ckbr[hashId][keyString.toLowerCase()];
} };
this.handleKeyboard = function(data, hashId, keyString, keyCode) { this.handleKeyboard = function(data, hashId, keyString, keyCode) {
return { return {

View file

@ -47,15 +47,27 @@ require("../commands/default_commands");
var KeyBinding = function(editor) { var KeyBinding = function(editor) {
this.$editor = editor; this.$editor = editor;
this.$data = { }; this.$data = { };
this.$handlers = [this]; this.$handlers = [];
this.setDefaultHandler(editor.commands);
}; };
(function() { (function() {
this.setDefaultHandler = function(keyboardHandler) {
this.removeKeyboardHandler(this.$defaultHandler);
this.$defaultHandler = keyboardHandler;
if (keyboardHandler)
this.$handlers.unshift(keyboardHandler);
this.$data = { };
};
this.setKeyboardHandler = function(keyboardHandler) { this.setKeyboardHandler = function(keyboardHandler) {
if (this.$handlers[this.$handlers.length - 1] == keyboardHandler) if (this.$handlers[this.$handlers.length - 1] == keyboardHandler)
return; return;
this.$data = { }; this.$data = { };
this.$handlers = keyboardHandler ? [this, keyboardHandler] : [this]; this.$handlers = [];
this.setDefaultHandler(this.$defaultHandler);
if (keyboardHandler)
this.$handlers.push(keyboardHandler);
}; };
this.addKeyboardHandler = function(keyboardHandler) { this.addKeyboardHandler = function(keyboardHandler) {
@ -93,7 +105,7 @@ var KeyBinding = function(editor) {
// allow keyboardHandler to consume keys // allow keyboardHandler to consume keys
if (toExecute.command != "null") if (toExecute.command != "null")
success = commands.exec(toExecute.command, this.$editor, toExecute.args); success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
else else
success = true; success = true;
@ -103,20 +115,14 @@ var KeyBinding = function(editor) {
return success; return success;
}; };
this.handleKeyboard = function(data, hashId, keyString) {
return {
command: this.$editor.commands.findKeyCommand(hashId, keyString)
};
};
this.onCommandKey = function(e, hashId, keyCode) { this.onCommandKey = function(e, hashId, keyCode) {
var keyString = keyUtil.keyCodeToString(keyCode); var keyString = keyUtil.keyCodeToString(keyCode);
this.$callKeyboardHandlers(hashId, keyString, keyCode, e); this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
}; };
this.onTextInput = function(text, pasted) { this.onTextInput = function(text) {
var success = false; var success = false;
if (!pasted && text.length == 1) if (text.length == 1)
success = this.$callKeyboardHandlers(0, text); success = this.$callKeyboardHandlers(0, text);
if (!success) if (!success)
this.$editor.commands.exec("insertstring", this.$editor, text); this.$editor.commands.exec("insertstring", this.$editor, text);

View file

@ -72,13 +72,18 @@ var TextInput = function(parentNode, host) {
if (!copied) { if (!copied) {
var value = valueToSend || text.value; var value = valueToSend || text.value;
if (value) { if (value) {
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) { if (value.length > 1) {
if (value.charAt(0) == PLACEHOLDER)
value = value.substr(1);
else if (value.charAt(value.length - 1) == PLACEHOLDER)
value = value.slice(0, -1); value = value.slice(0, -1);
if (value)
host.onTextInput(value, pasted);
} }
else {
host.onTextInput(value, pasted); if (value && value != PLACEHOLDER) {
if (pasted)
host.onPaste(value);
else
host.onTextInput(value);
} }
// If editor is no longer focused we quit immediately, since // If editor is no longer focused we quit immediately, since
@ -155,6 +160,7 @@ var TextInput = function(parentNode, host) {
}; };
event.addCommandKeyListener(text, host.onCommandKey.bind(host)); event.addCommandKeyListener(text, host.onCommandKey.bind(host));
if (useragent.isOldIE) { if (useragent.isOldIE) {
var keytable = { 13:1, 27:1 }; var keytable = { 13:1, 27:1 };
event.addListener(text, "keyup", function (e) { event.addListener(text, "keyup", function (e) {

View file

@ -390,21 +390,18 @@ var Text = function(parentEl) {
this.$renderToken = function(stringBuilder, screenColumn, token, value) { this.$renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this; var self = this;
var replaceReg = /\t|&|<|( +)|([\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000])|[\u1100-\u115F]|[\u11A3-\u11A7]|[\u11FA-\u11FF]|[\u2329-\u232A]|[\u2E80-\u2E99]|[\u2E9B-\u2EF3]|[\u2F00-\u2FD5]|[\u2FF0-\u2FFB]|[\u3000-\u303E]|[\u3041-\u3096]|[\u3099-\u30FF]|[\u3105-\u312D]|[\u3131-\u318E]|[\u3190-\u31BA]|[\u31C0-\u31E3]|[\u31F0-\u321E]|[\u3220-\u3247]|[\u3250-\u32FE]|[\u3300-\u4DBF]|[\u4E00-\uA48C]|[\uA490-\uA4C6]|[\uA960-\uA97C]|[\uAC00-\uD7A3]|[\uD7B0-\uD7C6]|[\uD7CB-\uD7FB]|[\uF900-\uFAFF]|[\uFE10-\uFE19]|[\uFE30-\uFE52]|[\uFE54-\uFE66]|[\uFE68-\uFE6B]|[\uFF01-\uFF60]|[\uFFE0-\uFFE6]/g; var replaceReg = /\t|&|<|( +)|([\u0000-\u0019\u00a0\u2000-\u200b\u2028\u2029\u3000])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
var replaceFunc = function(c, a, b, tabIdx, idx4) { var replaceFunc = function(c, a, b, tabIdx, idx4) {
if (c.charCodeAt(0) == 32) { if (a) {
return new Array(c.length+1).join("&#160;"); return new Array(c.length+1).join("&#160;");
} else if (c == "&") {
return useragent.isOldGecko ? "&" : "&amp;";
} else if (c == "<") {
return "&lt;";
} else if (c == "\t") { } else if (c == "\t") {
var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx); var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
screenColumn += tabSize - 1; screenColumn += tabSize - 1;
return self.$tabStrings[tabSize]; return self.$tabStrings[tabSize];
} else if (c == "&") {
if (useragent.isOldGecko)
return "&";
else
return "&amp;";
} else if (c == "<") {
return "&lt;";
} else if (c == "\u3000") { } else if (c == "\u3000") {
// U+3000 is both invisible AND full-width, so must be handled uniquely // U+3000 is both invisible AND full-width, so must be handled uniquely
var classToUse = self.showInvisibles ? "ace_cjk ace_invisible" : "ace_cjk"; var classToUse = self.showInvisibles ? "ace_cjk ace_invisible" : "ace_cjk";
@ -413,13 +410,11 @@ var Text = function(parentEl) {
return "<span class='" + classToUse + "' style='width:" + return "<span class='" + classToUse + "' style='width:" +
(self.config.characterWidth * 2) + (self.config.characterWidth * 2) +
"px'>" + space + "</span>"; "px'>" + space + "</span>";
} else if (c.match(/[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]/)) { } else if (b) {
if (self.showInvisibles) { if (self.showInvisibles)
var space = new Array(c.length+1).join(self.SPACE_CHAR); return "<span class='ace_invisible ace_invalid'>" + self.SPACE_CHAR + "</span>";
return "<span class='ace_invisible'>" + space + "</span>"; else
} else {
return "&#160;"; return "&#160;";
}
} else { } else {
screenColumn += 1; screenColumn += 1;
return "<span class='ace_cjk' style='width:" + return "<span class='ace_cjk' style='width:" +

View file

@ -75,7 +75,7 @@ EventEmitter._dispatchEvent = function(eventName, e) {
} }
if (defaultHandler && !e.defaultPrevented) if (defaultHandler && !e.defaultPrevented)
defaultHandler(e); return defaultHandler(e);
}; };
EventEmitter.setDefaultHandler = function(eventName, callback) { EventEmitter.setDefaultHandler = function(eventName, callback) {

View file

@ -76,6 +76,19 @@ function DefaultHandlers(editor) {
var selectionEmpty = selectionRange.isEmpty(); var selectionEmpty = selectionRange.isEmpty();
var state = STATE_UNKNOWN; var state = STATE_UNKNOWN;
var button = ev.getButton();
if (button !== 0) {
if (selectionEmpty) {
editor.moveCursorToPosition(pos);
editor.selection.clearSelection();
}
if (button == 2) {
editor.textInput.onContextMenu({x: ev.clientX, y: ev.clientY}, selectionEmpty);
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
}
return;
}
// if this click caused the editor to be focused should not clear the // if this click caused the editor to be focused should not clear the
// selection // selection
if ( if (
@ -89,18 +102,6 @@ function DefaultHandlers(editor) {
return; return;
} }
var button = ev.getButton();
if (button !== 0) {
if (selectionEmpty) {
editor.moveCursorToPosition(pos);
}
if (button == 2) {
editor.textInput.onContextMenu({x: ev.clientX, y: ev.clientY}, selectionEmpty);
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
}
return;
}
if (!inSelection) { if (!inSelection) {
// Directly pick STATE_SELECT, since the user is not clicking inside // Directly pick STATE_SELECT, since the user is not clicking inside
// a selection. // a selection.

View file

@ -42,6 +42,7 @@ var RangeList = require("./range_list").RangeList;
var Range = require("./range").Range; var Range = require("./range").Range;
var Selection = require("./selection").Selection; var Selection = require("./selection").Selection;
var onMouseDown = require("./mouse/multi_select_handler").onMouseDown; var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
var event = require("./lib/event");
exports.commands = require("./commands/multi_select_commands"); exports.commands = require("./commands/multi_select_commands");
// Todo: session.find or editor.findVolatile that returns range // Todo: session.find or editor.findVolatile that returns range
@ -195,6 +196,37 @@ var EditSession = require("./edit_session").EditSession;
}; };
this.splitIntoLines = function () { this.splitIntoLines = function () {
if (this.rangeCount > 1) {
var ranges = this.rangeList.ranges;
var lastRange = ranges[ranges.length - 1];
var range = Range.fromPoints(ranges[0].start, lastRange.end);
this.toSingleRange();
this.setSelectionRange(range, lastRange.cursor == lastRange.start);
} else {
var range = this.getRange();
var startRow = range.start.row;
var endRow = range.end.row;
if (startRow == endRow)
return;
var rectSel = [];
var r = this.getLineRange(startRow, true);
r.start.column = range.start.column;
rectSel.push(r);
for (var i = startRow + 1; i < endRow; i++)
rectSel.push(this.getLineRange(i, true));
r = this.getLineRange(endRow, true);
r.end.column = range.end.column;
rectSel.push(r);
rectSel.forEach(this.addRange, this);
}
};
this.toggleBlockSelection = function () {
if (this.rangeCount > 1) { if (this.rangeCount > 1) {
var ranges = this.rangeList.ranges; var ranges = this.rangeList.ranges;
var lastRange = ranges[ranges.length - 1]; var lastRange = ranges[ranges.length - 1];
@ -441,7 +473,7 @@ var Editor = require("./editor").Editor;
}; };
/** extension /** extension
* Editor.exitMultiSelectMode() * Editor.exitMultiSelectMode() -> Void
* *
* Removes all the selections except the last added one. * Removes all the selections except the last added one.
**/ **/
@ -467,15 +499,35 @@ var Editor = require("./editor").Editor;
return text; return text;
}; };
this.onPaste = function(text) {
this._emit("paste", text);
if (!this.inMultiSelectMode)
return this.insert(text);
var lines = text.split(this.session.getDocument().getNewLineCharacter());
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length) {
this.commands.exec("insertstring", this, text);
return;
}
for (var i = ranges.length; i--; ) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
};
/** extension /** extension
* Editor.findAll(needle, dir, additive) -> Number * Editor.findAll(dir, options) -> Number
* - needle (String): The text to find * - needle: text to find
* - options (Object): Any of the additional [[Search search options]] * - options: search options
* - additive (Boolean): TODO * - additive: keeps
* + (Number): The number of found ranges.
* *
* Finds and selects all the occurences of `needle`. * Finds and selects all the occurences of `needle`.
*
**/ **/
this.findAll = function(needle, options, additive) { this.findAll = function(needle, options, additive) {
options = options || {}; options = options || {};
@ -551,7 +603,6 @@ var Editor = require("./editor").Editor;
* - dir (Number): The direction to rotate selections * - dir (Number): The direction to rotate selections
* *
* Transposes the selected ranges. * Transposes the selected ranges.
*
**/ **/
this.transposeSelections = function(dir) { this.transposeSelections = function(dir) {
var session = this.session; var session = this.session;
@ -684,7 +735,7 @@ function addAltCursorListeners(editor){
var el = editor.textInput.getElement(); var el = editor.textInput.getElement();
var altCursor = false; var altCursor = false;
var contentEl = editor.renderer.content; var contentEl = editor.renderer.content;
el.addEventListener("keydown", function(e) { event.addListener(el, "keydown", function(e) {
if (e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey)) { if (e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey)) {
if (!altCursor) { if (!altCursor) {
contentEl.style.cursor = "crosshair"; contentEl.style.cursor = "crosshair";
@ -695,8 +746,8 @@ function addAltCursorListeners(editor){
} }
}); });
el.addEventListener("keyup", reset); event.addListener(el, "keyup", reset);
el.addEventListener("blur", reset); event.addListener(el, "blur", reset);
function reset() { function reset() {
if (altCursor) { if (altCursor) {
contentEl.style.cursor = ""; contentEl.style.cursor = "";

View file

@ -389,10 +389,18 @@ var Selection = function(session) {
* *
* Moves the selection to highlight the entire word. * Moves the selection to highlight the entire word.
**/ **/
this.getWordRange = function(row, column) {
if (typeof column == "undefined") {
var cursor = row || this.selectionLead;
row = cursor.row;
column = cursor.column;
}
return this.session.getWordRange(row, column);
};
>>>>>>> ui/navbar
this.selectWord = function() { this.selectWord = function() {
var cursor = this.getCursor(); this.setSelectionRange(this.getWordRange());
var range = this.session.getWordRange(cursor.row, cursor.column);
this.setSelectionRange(range);
}; };
/** related to: EditSession.getAWordRange /** related to: EditSession.getAWordRange
@ -406,13 +414,8 @@ var Selection = function(session) {
this.setSelectionRange(range); this.setSelectionRange(range);
}; };
/** this.getLineRange = function(row, excludeLastChar) {
* Selection.selectLine() var rowStart = typeof row == "number" ? row : this.selectionLead.row;
*
* Selects the entire line.
**/
this.selectLine = function() {
var rowStart = this.selectionLead.row;
var rowEnd; var rowEnd;
var foldLine = this.session.getFoldLine(rowStart); var foldLine = this.session.getFoldLine(rowStart);
@ -422,10 +425,19 @@ var Selection = function(session) {
} else { } else {
rowEnd = rowStart; rowEnd = rowStart;
} }
this.setSelectionAnchor(rowStart, 0); if (excludeLastChar)
this.$moveSelection(function() { return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
this.moveCursorTo(rowEnd + 1, 0); else
}); return new Range(rowStart, 0, rowEnd + 1, 0);
};
/**
* Selection.selectLine()
*
* Selects the entire line.
**/
this.selectLine = function() {
this.setSelectionRange(this.getLineRange());
}; };
/** /**
@ -567,11 +579,11 @@ var Selection = function(session) {
}; };
/** /**
* Selection.moveCursorWordRight() * Selection.moveCursorLongWordRight()
* *
* Moves the cursor to the word on the right. * Moves the cursor to the word on the right.
**/ **/
this.moveCursorWordRight = function() { this.moveCursorLongWordRight = function() {
var row = this.selectionLead.row; var row = this.selectionLead.row;
var column = this.selectionLead.column; var column = this.selectionLead.column;
var line = this.doc.getLine(row); var line = this.doc.getLine(row);
@ -614,11 +626,11 @@ var Selection = function(session) {
}; };
/** /**
* Selection.moveCursorWordLeft() * Selection.moveCursorLongWordLeft()
* *
* Moves the cursor to the word on the left. * Moves the cursor to the word on the left.
**/ **/
this.moveCursorWordLeft = function() { this.moveCursorLongWordLeft = function() {
var row = this.selectionLead.row; var row = this.selectionLead.row;
var column = this.selectionLead.column; var column = this.selectionLead.column;
@ -664,6 +676,92 @@ var Selection = function(session) {
this.moveCursorTo(row, column); this.moveCursorTo(row, column);
}; };
this.$shortWordEndIndex = function(rightOfCursor) {
var match, index = 0, ch;
var whitespaceRe = /\s/;
var tokenRe = this.session.tokenRe;
tokenRe.lastIndex = 0;
if (match = this.session.tokenRe.exec(rightOfCursor)) {
index = this.session.tokenRe.lastIndex;
} else {
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
index ++;
if (index <= 1) {
tokenRe.lastIndex = 0;
while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
tokenRe.lastIndex = 0;
index ++;
if (whitespaceRe.test(ch)) {
if (index > 2) {
index--
break;
} else {
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
index ++;
if (index > 2)
break
}
}
}
}
}
tokenRe.lastIndex = 0;
return index;
};
this.moveCursorShortWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var line = this.doc.getLine(row);
var rightOfCursor = line.substring(column);
var fold = this.session.getFoldAt(row, column, 1);
if (fold)
return this.moveCursorTo(fold.end.row, fold.end.column);
if (column == line.length)
return this.moveCursorRight();
var index = this.$shortWordEndIndex(rightOfCursor);
this.moveCursorTo(row, column + index);
};
this.moveCursorShortWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var fold;
if (fold = this.session.getFoldAt(row, column, -1))
return this.moveCursorTo(fold.start.row, fold.start.column);
if (column == 0)
return this.moveCursorLeft();
var str = this.session.getLine(row).substring(0, column);
var leftOfCursor = lang.stringReverse(str);
var index = this.$shortWordEndIndex(leftOfCursor);
return this.moveCursorTo(row, column - index);
};
this.moveCursorWordRight = function() {
if (this.session.$selectLongWords)
this.moveCursorLongWordRight();
else
this.moveCursorShortWordRight();
};
this.moveCursorWordLeft = function() {
if (this.session.$selectLongWords)
this.moveCursorLongWordLeft();
else
this.moveCursorShortWordLeft();
};
/** related to: EditSession.documentToScreenPosition /** related to: EditSession.documentToScreenPosition
* Selection.moveCursorBy(rows, chars) * Selection.moveCursorBy(rows, chars)
* - rows (Number): The number of rows to move by * - rows (Number): The number of rows to move by

View file

@ -102,6 +102,7 @@ module.exports = {
].join("\n")); ].join("\n"));
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorDown(); selection.moveCursorDown();
assert.position(selection.getCursor(), 1, 0); assert.position(selection.getCursor(), 1, 0);
@ -144,6 +145,7 @@ module.exports = {
].join("\n")); ].join("\n"));
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorDown(); selection.moveCursorDown();
selection.moveCursorLineEnd(); selection.moveCursorLineEnd();
@ -171,6 +173,7 @@ module.exports = {
"test: moveCursor word left with umlauts" : function() { "test: moveCursor word left with umlauts" : function() {
var session = new EditSession(" Fuß Füße"); var session = new EditSession(" Fuß Füße");
session.$selectLongWords = true;
var selection = session.getSelection(); var selection = session.getSelection();
selection.moveCursorTo(0, 9) selection.moveCursorTo(0, 9)
@ -184,6 +187,7 @@ module.exports = {
"test: select word left if cursor in word" : function() { "test: select word left if cursor in word" : function() {
var session = new EditSession("Juhu Kinners"); var session = new EditSession("Juhu Kinners");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 8); selection.moveCursorTo(0, 8);
@ -244,6 +248,7 @@ module.exports = {
"test: select word with cursor betwen white space and word should select the word" : function() { "test: select word with cursor betwen white space and word should select the word" : function() {
var session = new EditSession("Juhu Kinners"); var session = new EditSession("Juhu Kinners");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 4); selection.moveCursorTo(0, 4);
selection.selectWord(); selection.selectWord();
@ -263,6 +268,7 @@ module.exports = {
"test: select word with cursor in white space should select white space" : function() { "test: select word with cursor in white space should select white space" : function() {
var session = new EditSession("Juhu Kinners"); var session = new EditSession("Juhu Kinners");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
selection.selectWord(); selection.selectWord();
@ -275,6 +281,7 @@ module.exports = {
"test: moving cursor should fire a 'changeCursor' event" : function() { "test: moving cursor should fire a 'changeCursor' event" : function() {
var session = new EditSession("Juhu Kinners"); var session = new EditSession("Juhu Kinners");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
@ -290,6 +297,7 @@ module.exports = {
"test: calling setCursor with the same position should not fire an event": function() { "test: calling setCursor with the same position should not fire an event": function() {
var session = new EditSession("Juhu Kinners"); var session = new EditSession("Juhu Kinners");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
@ -305,6 +313,7 @@ module.exports = {
"test: moveWordright should move past || and [": function() { "test: moveWordright should move past || and [": function() {
var session = new EditSession("||foo["); var session = new EditSession("||foo[");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
// Move behind ||foo // Move behind ||foo
selection.moveCursorWordRight(); selection.moveCursorWordRight();
@ -318,6 +327,7 @@ module.exports = {
"test: moveWordLeft should move past || and [": function() { "test: moveWordLeft should move past || and [": function() {
var session = new EditSession("||foo["); var session = new EditSession("||foo[");
var selection = session.getSelection(); var selection = session.getSelection();
session.$selectLongWords = true;
selection.moveCursorTo(0, 6); selection.moveCursorTo(0, 6);

View file

@ -107,6 +107,10 @@ MockRenderer.prototype.on = function() {
MockRenderer.prototype.updateCursor = function() { MockRenderer.prototype.updateCursor = function() {
}; };
MockRenderer.prototype.animateScrolling = function(fromValue, callback) {
callback && callback();
};
MockRenderer.prototype.scrollToX = function(scrollTop) {}; MockRenderer.prototype.scrollToX = function(scrollTop) {};
MockRenderer.prototype.scrollToY = function(scrollLeft) {}; MockRenderer.prototype.scrollToY = function(scrollLeft) {};

View file

@ -49,8 +49,8 @@ exports.cssText = "\
}\ }\
\ \
.ace-monokai .ace_gutter {\ .ace-monokai .ace_gutter {\
background: #e8e8e8;\ background: #292a24;\
color: #333;\ color: #f1f1f1;\
}\ }\
\ \
.ace-monokai .ace_print_margin {\ .ace-monokai .ace_print_margin {\
@ -97,6 +97,9 @@ exports.cssText = "\
.ace-monokai .ace_marker-layer .ace_active_line{\ .ace-monokai .ace_marker-layer .ace_active_line{\
background: #49483E;\ background: #49483E;\
}\ }\
.ace-monokai .ace_gutter_active_line{\
background: #191916;\
}\
\ \
.ace-monokai .ace_marker-layer .ace_selected_word {\ .ace-monokai .ace_marker-layer .ace_selected_word {\
border: 1px solid #49483E;\ border: 1px solid #49483E;\

View file

@ -49,8 +49,8 @@ exports.cssText = "\
}\ }\
\ \
.ace-solarized-dark .ace_gutter {\ .ace-solarized-dark .ace_gutter {\
background: #e8e8e8;\ background: #09222b;\
color: #333;\ color: #d0edf7;\
}\ }\
\ \
.ace-solarized-dark .ace_print_margin {\ .ace-solarized-dark .ace_print_margin {\
@ -97,6 +97,9 @@ exports.cssText = "\
.ace-solarized-dark .ace_marker-layer .ace_active_line {\ .ace-solarized-dark .ace_marker-layer .ace_active_line {\
background: #073642;\ background: #073642;\
}\ }\
.ace-solarized-dark .ace_gutter_active_line{\
background: #0d3440;\
}\
\ \
.ace-solarized-dark .ace_marker-layer .ace_selected_word {\ .ace-solarized-dark .ace_marker-layer .ace_selected_word {\
border: 1px solid #073642;\ border: 1px solid #073642;\

View file

@ -101,8 +101,8 @@ exports.cssText = ".ace-tm .ace_editor {\
}\ }\
\ \
.ace-tm .ace_line .ace_invalid {\ .ace-tm .ace_line .ace_invalid {\
background-color: rgb(153, 0, 0);\ background-color: rgba(255, 0, 0, 0.1);\
color: white;\ color: red;\
}\ }\
\ \
.ace-tm .ace_line .ace_support.ace_function {\ .ace-tm .ace_line .ace_support.ace_function {\
@ -189,6 +189,9 @@ exports.cssText = ".ace-tm .ace_editor {\
.ace-tm .ace_marker-layer .ace_active_line {\ .ace-tm .ace_marker-layer .ace_active_line {\
background: rgba(0, 0, 0, 0.07);\ background: rgba(0, 0, 0, 0.07);\
}\ }\
.ace-tm .ace_gutter_active_line{\
background-color : #dcdcdc;\
}\
\ \
.ace-tm .ace_marker-layer .ace_selected_word {\ .ace-tm .ace_marker-layer .ace_selected_word {\
background: rgb(250, 250, 255);\ background: rgb(250, 250, 255);\

View file

@ -49,8 +49,8 @@ exports.cssText = "\
}\ }\
\ \
.ace-tomorrow-night-blue .ace_gutter {\ .ace-tomorrow-night-blue .ace_gutter {\
background: #e8e8e8;\ background: #022346;\
color: #333;\ color: #7388b5;\
}\ }\
\ \
.ace-tomorrow-night-blue .ace_print_margin {\ .ace-tomorrow-night-blue .ace_print_margin {\
@ -97,6 +97,9 @@ exports.cssText = "\
.ace-tomorrow-night-blue .ace_marker-layer .ace_active_line{\ .ace-tomorrow-night-blue .ace_marker-layer .ace_active_line{\
background: #00346E;\ background: #00346E;\
}\ }\
.ace-tomorrow-night-blue .ace_gutter_active_line{\
background: #022040;\
}\
\ \
.ace-tomorrow-night-blue .ace_marker-layer .ace_selected_word {\ .ace-tomorrow-night-blue .ace_marker-layer .ace_selected_word {\
border: 1px solid #003F8E;\ border: 1px solid #003F8E;\

View file

@ -101,6 +101,7 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer = new GutterLayer(this.$gutter); this.$gutterLayer = new GutterLayer(this.$gutter);
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true)); this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
this.setFadeFoldWidgets(true);
this.$markerBack = new MarkerLayer(this.content); this.$markerBack = new MarkerLayer(this.content);
@ -116,13 +117,14 @@ var VirtualRenderer = function(container, theme) {
this.$cursorPadding = 8; this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible // Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true; this.$horizScroll = false;
this.$horizScrollAlwaysVisible = true; this.$horizScrollAlwaysVisible = false;
this.$animatedScroll = false; this.$animatedScroll = false;
this.scrollBar = new ScrollBar(container); this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", function(e) { this.scrollBar.addEventListener("scroll", function(e) {
if (!_self.$inScrollAnimation)
_self.session.setScrollTop(e.data); _self.session.setScrollTop(e.data);
}); });
@ -134,12 +136,9 @@ var VirtualRenderer = function(container, theme) {
_self.scrollLeft = scrollLeft; _self.scrollLeft = scrollLeft;
_self.session.setScrollLeft(scrollLeft); _self.session.setScrollLeft(scrollLeft);
if (scrollLeft == 0) { _self.scroller.className = scrollLeft == 0
_self.$gutter.className = "ace_gutter"; ? "ace_scroller"
} : "ace_scroller horscroll";
else {
_self.$gutter.className = "ace_gutter horscroll";
}
}); });
this.cursorPos = { this.cursorPos = {
@ -211,12 +210,16 @@ var VirtualRenderer = function(container, theme) {
**/ **/
this.setSession = function(session) { this.setSession = function(session) {
this.session = session; this.session = session;
this.scroller.className = "ace_scroller";
this.$cursorLayer.setSession(session); this.$cursorLayer.setSession(session);
this.$markerBack.setSession(session); this.$markerBack.setSession(session);
this.$markerFront.setSession(session); this.$markerFront.setSession(session);
this.$gutterLayer.setSession(session); this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session); this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
/** /**
@ -435,6 +438,17 @@ var VirtualRenderer = function(container, theme) {
this.onResize(true); this.onResize(true);
}; };
this.getFadeFoldWidgets = function(){
return dom.hasCssClass(this.$gutter, "ace_fade-fold-widgets");
};
this.setFadeFoldWidgets = function(show) {
if (show)
dom.addCssClass(this.$gutter, "ace_fade-fold-widgets");
else
dom.removeCssClass(this.$gutter, "ace_fade-fold-widgets");
};
this.$updatePrintMargin = function() { this.$updatePrintMargin = function() {
var containerEl; var containerEl;
@ -878,18 +892,18 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.showCursor(); this.$cursorLayer.showCursor();
}; };
this.scrollSelectionIntoView = function(anchor, lead) { this.scrollSelectionIntoView = function(anchor, lead, offset) {
// first scroll anchor into view then scroll lead into view // first scroll anchor into view then scroll lead into view
this.scrollCursorIntoView(anchor); this.scrollCursorIntoView(anchor, offset);
this.scrollCursorIntoView(lead); this.scrollCursorIntoView(lead, offset);
}; };
/** /**
* VirtualRenderer.scrollCursorIntoView() -> Void * VirtualRenderer.scrollCursorIntoView(cursor, offset) -> Void
* *
* Scrolls the cursor into the first visibile area of the editor * Scrolls the cursor into the first visibile area of the editor
**/ **/
this.scrollCursorIntoView = function(cursor) { this.scrollCursorIntoView = function(cursor, offset) {
// the editor is not visible // the editor is not visible
if (this.$size.scrollerHeight === 0) if (this.$size.scrollerHeight === 0)
return; return;
@ -900,10 +914,12 @@ var VirtualRenderer = function(container, theme) {
var top = pos.top; var top = pos.top;
if (this.scrollTop > top) { if (this.scrollTop > top) {
if (offset)
top -= offset * this.$size.scrollerHeight;
this.session.setScrollTop(top); this.session.setScrollTop(top);
} } else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
if (offset)
if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) { top += offset * this.$size.scrollerHeight;
this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight); this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
} }
@ -913,9 +929,7 @@ var VirtualRenderer = function(container, theme) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth) if (left < this.$padding + 2 * this.layerConfig.characterWidth)
left = 0; left = 0;
this.session.setScrollLeft(left); this.session.setScrollLeft(left);
} } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth)); this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
} }
}; };
@ -966,33 +980,67 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollTop(row * this.lineHeight); this.session.setScrollTop(row * this.lineHeight);
}; };
this.STEPS = 8;
this.$calcSteps = function(fromValue, toValue){
var i = 0;
var l = this.STEPS;
var steps = [];
var func = function(t, x_min, dx) {
return dx * (Math.pow(t - 1, 3) + 1) + x_min;
};
for (i = 0; i < l; ++i)
steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
return steps;
};
/** /**
* VirtualRenderer.scrollToLine(line, center) -> Void * VirtualRenderer.scrollToLine(line, center, animate, callback) -> Void
* - line (Number): A line number * - line (Number): A line number
* - center (Boolean): If `true`, centers the editor the to indicated line * - center (Boolean): If `true`, centers the editor the to indicated line
* - animate (Boolean): If `true` animates scrolling
* - callback (Function): Function to be called after the animation has finished
* *
* Gracefully scrolls the editor to the row indicated. * Gracefully scrolls the editor to the row indicated.
**/ **/
this.scrollToLine = function(line, center) { this.scrollToLine = function(line, center, animate, callback) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = pos.top; var offset = pos.top;
if (center) if (center)
offset -= this.$size.scrollerHeight / 2; offset -= this.$size.scrollerHeight / 2;
if (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 10000) { var initialScroll = this.scrollTop;
this.session.setScrollTop(offset);
if (animate !== false)
this.animateScrolling(initialScroll, callback);
};
this.animateScrolling = function(fromValue, callback) {
var toValue = this.scrollTop;
if (this.$animatedScroll && Math.abs(fromValue - toValue) < 100000) {
var _self = this; var _self = this;
var steps = _self.$calcSteps(this.scrollTop, offset); var steps = _self.$calcSteps(fromValue, toValue);
this.$inScrollAnimation = true;
clearInterval(this.$timer); clearInterval(this.$timer);
this.$timer = setInterval(function() {
_self.session.setScrollTop(steps.shift());
if (!steps.length) _self.session.setScrollTop(steps.shift());
this.$timer = setInterval(function() {
if (steps.length) {
_self.session.setScrollTop(steps.shift());
// trick session to think it's already scrolled to not loose toValue
_self.session.$scrollTop = toValue;
} else {
this.$inScrollAnimation = false;
clearInterval(_self.$timer); clearInterval(_self.$timer);
}, 10);
_self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue);
callback && callback();
} }
else { }, 10);
this.session.setScrollTop(offset);
} }
}; };