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 {
margin:0;
padding:0;

View file

@ -301,7 +301,8 @@ split.on("focus", function(editor) {
});
env.split = split;
window.env = env;
window.ace = env.editor;
window.editor = window.ace = env.editor;
env.editor.setAnimatedScroll(true);
var docEl = document.getElementById("doc");
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) {
if (!value)
return;
env.editor.setTheme(value);
themeEl.selectedValue = value;
});
bindDropdown("keybinding", function(value) {
@ -480,6 +499,9 @@ bindCheckbox("enable_behaviours", function(checked) {
env.editor.setBehavioursEnabled(checked);
});
bindCheckbox("fade_fold_widgets", function(checked) {
env.editor.setFadeFoldWidgets(checked);
});
var secondSession = null;
bindDropdown("split", function(value) {

View file

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

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

View file

@ -200,6 +200,14 @@
<input type="checkbox" id="enable_behaviours">
</td>
</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>
<div id="editor">

View file

@ -31,7 +31,7 @@ var CommandManager = function(platform, commands) {
this.addCommands(commands);
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)
return false;
this._emit("exec", {editor: editor, command: command, args: args});
return true;
try {
var retvalue = this._emit("exec", {
editor: editor,
command: command,
args: args
});
} catch (e) {
window.console && window.console.log(e);
return true;
}
return retvalue === false ? false : true;
};
this.toggleRecording = function() {

View file

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

View file

@ -84,16 +84,17 @@ exports.defaultCommands = [{
exec: function(editor) { editor.multiSelect.splitIntoLines(); },
bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"},
readonly: true
}];
// commands active in multiselect mode
exports.multiEditCommands = [{
}, {
name: "singleSelection",
bindKey: "esc",
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;
exports.keyboardHandler = new HashHandler(exports.multiEditCommands);

View file

@ -1,4 +1,3 @@
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
.ace_editor {
position: absolute;
@ -131,6 +130,7 @@
.ace_text-layer {
color: black;
font: inherit !important;
}
.ace_cjk {
@ -179,10 +179,6 @@
z-index: 2;
}
.ace_gutter .ace_gutter_active_line{
background-color : #dcdcdc;
}
.ace_marker-layer .ace_selected_word {
position: absolute;
z-index: 4;
@ -289,3 +285,25 @@
background-color: #FFB4B4;
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);
}
else {
var lines = [];
lines.push(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));
var lines = this.getLines(range.start.row+1, range.end.row-1);
lines.unshift((this.$lines[range.start.row] || "").substring(range.start.column));
lines.push((this.$lines[range.end.row] || "").substring(0, range.end.column));
return lines.join(this.getNewLineCharacter());
}
};

View file

@ -93,10 +93,7 @@ var EditSession = function(text, mode) {
}
this.selection = new Selection(this);
if (mode)
this.setMode(mode);
else
this.setMode(new TextMode());
this.setMode(mode);
};
@ -766,7 +763,7 @@ var EditSession = function(text, mode) {
this._loadMode = function(mode, callback) {
if (this.$modes[mode])
return callback(this.$modes[mode]);
var _self = this;
var module;
try {
@ -774,16 +771,17 @@ var EditSession = function(text, mode) {
} catch (e) {};
if (module)
return done(module);
fetch(function() {
require([mode], done);
});
function done(module) {
if (_self.$modes[mode])
return callback(_self.$modes[mode]);
_self.$modes[mode] = new module.Mode();
_self.$modes[mode].$id = mode;
_self._emit("loadmode", {
name: mode,
mode: _self.$modes[mode]
@ -794,40 +792,48 @@ var EditSession = function(text, mode) {
function fetch(callback) {
if (!config.get("packaged"))
return callback();
var base = mode.split("/").pop();
var filename = config.get("modePath") + "/mode-" + base + config.get("suffix");
net.loadScript(filename, callback);
}
};
/**
* EditSession.setMode(mode)
* - mode (TextMode): Set a new 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.
*
**/
this.$mode = null;
this.$origMode = null;
/**
* EditSession.setMode(mode)
* - mode (TextMode): Set a new 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.
*
**/
this.$modeId = null;
this.setMode = function(mode) {
this.$origMode = mode;
// load on demand
if (typeof mode === "string") {
if (this.$modeId == mode)
return;
this.$modeId = mode;
var _self = this;
this._loadMode(mode, function(module) {
if (_self.$origMode !== mode)
if (_self.$modeId !== mode)
return;
_self.setMode(module);
});
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;
this.$mode = mode;
this.$modeId = mode.$id;
this.$stopWorker();
@ -901,7 +907,7 @@ var EditSession = function(text, mode) {
this.getMode = function() {
return this.$mode;
};
this.$scrollTop = 0;
/**
* EditSession.setScrollTop(scrollTop)
@ -926,7 +932,7 @@ var EditSession = function(text, mode) {
this.getScrollTop = function() {
return this.$scrollTop;
};
this.$scrollLeft = 0;
/**
* EditSession.setScrollLeft(scrollLeft)
@ -1419,7 +1425,7 @@ var EditSession = function(text, mode) {
range.start.column
);
}
var len = this.doc.getLength() - 1;
if (range.end.row > len) {
range.end.row = len;

View file

@ -177,7 +177,9 @@ function FoldLine(foldData, folds) {
&& fold.start.column != column
&& 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) {
folds = this.folds;
var i = folds.indexOf(fold);

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);
};
/**

View file

@ -82,7 +82,7 @@ module.exports = {
editor.navigateTo(0, 0);
editor.gotoLine(101);
assert.position(editor.getCursorPosition(), 100, 0);
assert.equal(editor.getFirstVisibleRow(), 90);
assert.equal(editor.getFirstVisibleRow(), 89);
editor.navigateTo(100, 0);
editor.gotoLine(11);
@ -102,7 +102,7 @@ module.exports = {
editor.navigateTo(0, 0);
editor.gotoLine(191);
assert.position(editor.getCursorPosition(), 190, 0);
assert.equal(editor.getFirstVisibleRow(), 180);
assert.equal(editor.getFirstVisibleRow(), 179);
editor.navigateTo(0, 0);
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) {
commands && Object.keys(commands).forEach(function(name) {
var command = commands[name];
@ -100,18 +112,6 @@ function HashHandler(config, platform) {
}, 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) {
Object.keys(keyList).forEach(function(key) {
this.bindKey(key, keyList[key]);
@ -127,10 +127,10 @@ function HashHandler(config, platform) {
this.bindKey(key, command);
};
function parseKeys(keys, val, ret) {
this.parseKeys = function(keys, val) {
var key;
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++) {
if (keyUtil.KEY_MODS[parts[i]])
@ -143,17 +143,12 @@ function HashHandler(config, platform) {
key: key,
hashId: hashId
};
}
function splitSafe(s) {
return (s.trim()
.split(new RegExp("[\\s ]*\\-[\\s ]*", "g"), 999));
}
};
this.findKeyCommand = function findKeyCommand(hashId, keyString) {
var ckbr = this.commmandKeyBinding;
return ckbr[hashId] && ckbr[hashId][keyString.toLowerCase()];
}
};
this.handleKeyboard = function(data, hashId, keyString, keyCode) {
return {
@ -164,4 +159,4 @@ function HashHandler(config, platform) {
}).call(HashHandler.prototype)
exports.HashHandler = HashHandler;
});
});

View file

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

View file

@ -72,13 +72,18 @@ var TextInput = function(parentNode, host) {
if (!copied) {
var value = valueToSend || text.value;
if (value) {
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
value = value.slice(0, -1);
if (value)
host.onTextInput(value, pasted);
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);
}
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
@ -99,7 +104,7 @@ var TextInput = function(parentNode, host) {
var onTextInput = function(e) {
setTimeout(function () {
if (!inCompostion)
sendText(e.data);
sendText(e.data);
}, 0);
};
@ -155,6 +160,7 @@ var TextInput = function(parentNode, host) {
};
event.addCommandKeyListener(text, host.onCommandKey.bind(host));
if (useragent.isOldIE) {
var keytable = { 13:1, 27:1 };
event.addListener(text, "keyup", function (e) {

View file

@ -390,21 +390,18 @@ var Text = function(parentEl) {
this.$renderToken = function(stringBuilder, screenColumn, token, value) {
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) {
if (c.charCodeAt(0) == 32) {
if (a) {
return new Array(c.length+1).join("&#160;");
} else if (c == "&") {
return useragent.isOldGecko ? "&" : "&amp;";
} else if (c == "<") {
return "&lt;";
} else if (c == "\t") {
var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
screenColumn += tabSize - 1;
return self.$tabStrings[tabSize];
} else if (c == "&") {
if (useragent.isOldGecko)
return "&";
else
return "&amp;";
} else if (c == "<") {
return "&lt;";
} else if (c == "\u3000") {
// U+3000 is both invisible AND full-width, so must be handled uniquely
var classToUse = self.showInvisibles ? "ace_cjk ace_invisible" : "ace_cjk";
@ -413,13 +410,11 @@ var Text = function(parentEl) {
return "<span class='" + classToUse + "' style='width:" +
(self.config.characterWidth * 2) +
"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]/)) {
if (self.showInvisibles) {
var space = new Array(c.length+1).join(self.SPACE_CHAR);
return "<span class='ace_invisible'>" + space + "</span>";
} else {
} else if (b) {
if (self.showInvisibles)
return "<span class='ace_invisible ace_invalid'>" + self.SPACE_CHAR + "</span>";
else
return "&#160;";
}
} else {
screenColumn += 1;
return "<span class='ace_cjk' style='width:" +

View file

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

View file

@ -76,6 +76,19 @@ function DefaultHandlers(editor) {
var selectionEmpty = selectionRange.isEmpty();
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
// selection
if (
@ -89,18 +102,6 @@ function DefaultHandlers(editor) {
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) {
// Directly pick STATE_SELECT, since the user is not clicking inside
// a selection.

View file

@ -42,6 +42,7 @@ var RangeList = require("./range_list").RangeList;
var Range = require("./range").Range;
var Selection = require("./selection").Selection;
var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
var event = require("./lib/event");
exports.commands = require("./commands/multi_select_commands");
// Todo: session.find or editor.findVolatile that returns range
@ -195,6 +196,37 @@ var EditSession = require("./edit_session").EditSession;
};
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) {
var ranges = this.rangeList.ranges;
var lastRange = ranges[ranges.length - 1];
@ -352,13 +384,13 @@ var Editor = require("./editor").Editor;
this.renderer.updateCursor();
this.renderer.updateBackMarkers();
};
this.$onRemoveRange = function(e) {
this.removeSelectionMarkers(e.ranges);
this.renderer.updateCursor();
this.renderer.updateBackMarkers();
};
this.$onMultiSelect = function(e) {
if (this.inMultiSelectMode)
return;
@ -371,7 +403,7 @@ var Editor = require("./editor").Editor;
this.renderer.updateCursor();
this.renderer.updateBackMarkers();
};
this.$onSingleSelect = function(e) {
if (this.session.multiSelect.inVirtualMode)
return;
@ -439,9 +471,9 @@ var Editor = require("./editor").Editor;
this.onCursorChange();
this.onSelectionChange();
};
/** extension
* Editor.exitMultiSelectMode()
* Editor.exitMultiSelectMode() -> Void
*
* Removes all the selections except the last added one.
**/
@ -467,15 +499,35 @@ var Editor = require("./editor").Editor;
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
* 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.
* Editor.findAll(dir, options) -> Number
* - needle: text to find
* - options: search options
* - additive: keeps
*
* Finds and selects all the occurences of `needle`.
*
**/
this.findAll = function(needle, options, additive) {
options = options || {};
@ -488,10 +540,10 @@ var Editor = require("./editor").Editor;
this.$blockScrolling += 1;
var selection = this.multiSelect;
if (!additive)
selection.toSingleRange(ranges[0]);
for (var i = ranges.length; i--; )
selection.addRange(ranges[i], true);
@ -551,7 +603,6 @@ var Editor = require("./editor").Editor;
* - dir (Number): The direction to rotate selections
*
* Transposes the selected ranges.
*
**/
this.transposeSelections = function(dir) {
var session = this.session;
@ -569,7 +620,7 @@ var Editor = require("./editor").Editor;
}
}
sel.mergeOverlappingRanges();
var words = [];
for (var i = all.length; i--; ) {
var range = all[i];
@ -676,7 +727,7 @@ function MultiSelect(editor) {
editor.on("mousedown", onMouseDown);
editor.commands.addCommands(exports.commands.defaultCommands);
addAltCursorListeners(editor);
}
@ -684,7 +735,7 @@ function addAltCursorListeners(editor){
var el = editor.textInput.getElement();
var altCursor = false;
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 (!altCursor) {
contentEl.style.cursor = "crosshair";
@ -694,9 +745,9 @@ function addAltCursorListeners(editor){
contentEl.style.cursor = "";
}
});
el.addEventListener("keyup", reset);
el.addEventListener("blur", reset);
event.addListener(el, "keyup", reset);
event.addListener(el, "blur", reset);
function reset() {
if (altCursor) {
contentEl.style.cursor = "";

View file

@ -389,10 +389,18 @@ var Selection = function(session) {
*
* 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() {
var cursor = this.getCursor();
var range = this.session.getWordRange(cursor.row, cursor.column);
this.setSelectionRange(range);
this.setSelectionRange(this.getWordRange());
};
/** related to: EditSession.getAWordRange
@ -406,13 +414,8 @@ var Selection = function(session) {
this.setSelectionRange(range);
};
/**
* Selection.selectLine()
*
* Selects the entire line.
**/
this.selectLine = function() {
var rowStart = this.selectionLead.row;
this.getLineRange = function(row, excludeLastChar) {
var rowStart = typeof row == "number" ? row : this.selectionLead.row;
var rowEnd;
var foldLine = this.session.getFoldLine(rowStart);
@ -422,10 +425,19 @@ var Selection = function(session) {
} else {
rowEnd = rowStart;
}
this.setSelectionAnchor(rowStart, 0);
this.$moveSelection(function() {
this.moveCursorTo(rowEnd + 1, 0);
});
if (excludeLastChar)
return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
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.
**/
this.moveCursorWordRight = function() {
this.moveCursorLongWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
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.
**/
this.moveCursorWordLeft = function() {
this.moveCursorLongWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
@ -664,8 +676,94 @@ var Selection = function(session) {
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
* Selection.moveCursorBy(rows, chars)
* Selection.moveCursorBy(rows, chars)
* - rows (Number): The number of rows to move by
* - chars (Number): The number of characters to move by
*

View file

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

View file

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

View file

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

View file

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

View file

@ -101,8 +101,8 @@ exports.cssText = ".ace-tm .ace_editor {\
}\
\
.ace-tm .ace_line .ace_invalid {\
background-color: rgb(153, 0, 0);\
color: white;\
background-color: rgba(255, 0, 0, 0.1);\
color: red;\
}\
\
.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 {\
background: rgba(0, 0, 0, 0.07);\
}\
.ace-tm .ace_gutter_active_line{\
background-color : #dcdcdc;\
}\
\
.ace-tm .ace_marker-layer .ace_selected_word {\
background: rgb(250, 250, 255);\

View file

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

View file

@ -101,6 +101,7 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer = new GutterLayer(this.$gutter);
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
this.setFadeFoldWidgets(true);
this.$markerBack = new MarkerLayer(this.content);
@ -116,14 +117,15 @@ var VirtualRenderer = function(container, theme) {
this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true;
this.$horizScrollAlwaysVisible = true;
this.$horizScroll = false;
this.$horizScrollAlwaysVisible = false;
this.$animatedScroll = false;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", function(e) {
_self.session.setScrollTop(e.data);
if (!_self.$inScrollAnimation)
_self.session.setScrollTop(e.data);
});
this.scrollTop = 0;
@ -134,12 +136,9 @@ var VirtualRenderer = function(container, theme) {
_self.scrollLeft = scrollLeft;
_self.session.setScrollLeft(scrollLeft);
if (scrollLeft == 0) {
_self.$gutter.className = "ace_gutter";
}
else {
_self.$gutter.className = "ace_gutter horscroll";
}
_self.scroller.className = scrollLeft == 0
? "ace_scroller"
: "ace_scroller horscroll";
});
this.cursorPos = {
@ -211,12 +210,16 @@ var VirtualRenderer = function(container, theme) {
**/
this.setSession = function(session) {
this.session = session;
this.scroller.className = "ace_scroller";
this.$cursorLayer.setSession(session);
this.$markerBack.setSession(session);
this.$markerFront.setSession(session);
this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL);
};
/**
@ -435,6 +438,17 @@ var VirtualRenderer = function(container, theme) {
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() {
var containerEl;
@ -878,18 +892,18 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.showCursor();
};
this.scrollSelectionIntoView = function(anchor, lead) {
this.scrollSelectionIntoView = function(anchor, lead, offset) {
// first scroll anchor into view then scroll lead into view
this.scrollCursorIntoView(anchor);
this.scrollCursorIntoView(lead);
this.scrollCursorIntoView(anchor, offset);
this.scrollCursorIntoView(lead, offset);
};
/**
* VirtualRenderer.scrollCursorIntoView() -> Void
* VirtualRenderer.scrollCursorIntoView(cursor, offset) -> Void
*
* 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
if (this.$size.scrollerHeight === 0)
return;
@ -900,10 +914,12 @@ var VirtualRenderer = function(container, theme) {
var top = pos.top;
if (this.scrollTop > top) {
if (offset)
top -= offset * this.$size.scrollerHeight;
this.session.setScrollTop(top);
}
if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
} else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
if (offset)
top += offset * 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)
left = 0;
this.session.setScrollLeft(left);
}
if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
} else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
}
};
@ -966,36 +980,70 @@ var VirtualRenderer = function(container, theme) {
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
* - 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.
**/
this.scrollToLine = function(line, center) {
this.scrollToLine = function(line, center, animate, callback) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = pos.top;
if (center)
offset -= this.$size.scrollerHeight / 2;
if (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 10000) {
var _self = this;
var steps = _self.$calcSteps(this.scrollTop, offset);
clearInterval(this.$timer);
this.$timer = setInterval(function() {
_self.session.setScrollTop(steps.shift());
if (!steps.length)
clearInterval(_self.$timer);
}, 10);
}
else {
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 steps = _self.$calcSteps(fromValue, toValue);
this.$inScrollAnimation = true;
clearInterval(this.$timer);
_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);
_self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue);
callback && callback();
}
}, 10);
}
};
/**
* VirtualRenderer.scrollToY(scrollTop) -> Number
* - scrollTop (Number): The position to scroll to