Merge pull request #1828 from ajaxorg/c9

Update Ace and fix several small issues
This commit is contained in:
Lennart Kats 2014-03-06 15:46:22 +01:00
commit 86e7a49666
27 changed files with 675 additions and 519 deletions

View file

@ -293,27 +293,30 @@ function getWriteFilters(options, projectType, main) {
if (options.noconflict)
filters.push(namespace(options.ns));
if (options.exportModule && projectType == "main" || projectType == "ext") {
filters.push(exportAce(options.ns, options.exportModule,
options.noconflict ? options.ns : "", projectType == "ext" && main));
}
if (options.compress)
filters.push(copy.filter.uglifyjs);
// copy.filter.uglifyjs.options.ascii = true; doesn't work with some uglify.js versions
// copy.filter.uglifyjs.options.ascii_only = true; doesn't work with some uglify.js versions
filters.push(function(text) {
var t1 = text.replace(/[\x80-\uffff]/g, function(c) {
var text = text.replace(/[\x00-\x08\x0b\x0c\x0e\x19\x80-\uffff]/g, function(c) {
c = c.charCodeAt(0).toString(16);
if (c.length == 1)
return "\\x0" + c;
if (c.length == 2)
return "\\x" + c;
if (c.length == 3)
c = "0" + c;
return "\\u0" + c;
return "\\u" + c;
});
return text;
});
if (options.exportModule && projectType == "main" || projectType == "ext") {
filters.push(exportAce(options.ns, options.exportModule,
options.noconflict ? options.ns : "", projectType == "ext" && main));
}
return filters;
}
@ -550,15 +553,6 @@ var detectTextModules = function(input, source) {
detectTextModules.onRead = true;
copy.filter.addDefines = detectTextModules;
function generateThemesModule(themes) {
var themelist = [
'define(function(require, exports, module) {',
'\n\nmodule.exports.themes = ' + JSON.stringify(themes, null, ' '),
';\n\n});'
].join('');
fs.writeFileSync(__dirname + '/lib/ace/ext/themelist_utils/themes.js', themelist, 'utf8');
}
function inlineTextModules(text) {
var deps = [];
return text.replace(/, *['"]ace\/requirejs\/text!(.*?)['"]| require\(['"](?:ace|[.\/]+)\/requirejs\/text!(.*?)['"]\)/g, function(_, dep, call) {
@ -574,14 +568,38 @@ function inlineTextModules(text) {
});
call = textModules[dep];
// if (deps.length > 1)
// console.log(call.length)
if (call)
return " " + call;
}
});
}
var CommonJsProject = copy.createCommonJsProject({roots:[]}).constructor;
CommonJsProject.prototype.getCurrentModules = function() {
function isDep(child, parent) {
if (!modules[parent])
return false;
var deps = modules[parent].deps;
if (deps[child]) return true;
return Object.keys(deps).some(function(x) {
return isDep(child, x)
});
}
var depMap = {}, modules = this.currentModules;
return Object.keys(this.currentModules).map(function(moduleName) {
module = modules[moduleName];
module.id = moduleName;
module.isSpecial = !/define\(\'[^']*',/.test(module.source);
return module;
}).sort(function(a, b) {
if (a.isSpecial) return -1;
if (b.isSpecial) return 1;
if (isDep(a.id, b.id)) return -1;
if (isDep(b.id, a.id)) return 1;
return Object.keys(a.deps).length - Object.keys(b.deps).length || a.id.localeCompare(b.id)
});
};
// TODO: replace with project.clone once it is fixed in dryice
function cloneProject(project) {
var clone = copy.createCommonJsProject({
@ -602,16 +620,12 @@ function cloneProject(project) {
}
function copyFileSync(srcFile, destFile) {
var BUF_LENGTH = 64*1024,
buf = new Buffer(BUF_LENGTH),
bytesRead = BUF_LENGTH,
pos = 0,
fdr = null,
fdw = null;
fdr = fs.openSync(srcFile, 'r');
fdw = fs.openSync(destFile, 'w');
var BUF_LENGTH = 64*1024;
var buf = new Buffer(BUF_LENGTH);
var bytesRead = BUF_LENGTH;
var pos = 0;
var fdr = fs.openSync(srcFile, 'r');
var fdw = fs.openSync(destFile, 'w');
while (bytesRead === BUF_LENGTH) {
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
@ -652,13 +666,12 @@ function exportAce(ns, module, requireBase, extModule) {
requireBase = requireBase || "window";
module = module || "ace/ace";
return function(text) {
var template = function() {
(function() {
REQUIRE_NS.require(["MODULE"], function(a) {
a && a.config.init();
a && a.config.init(true);
if (!window.NS)
window.NS = {};
window.NS = a;
for (var key in a) if (a.hasOwnProperty(key))
NS[key] = a[key];
});
@ -674,6 +687,8 @@ function exportAce(ns, module, requireBase, extModule) {
};
}
text = text.replace(/function init\(packaged\) {/, "init(true);$&\n");
return (text + ";" + template
.toString()
.replace(/MODULE/g, module)
@ -696,6 +711,15 @@ function updateModes() {
})
}
function generateThemesModule(themes) {
var themelist = [
'define(function(require, exports, module) {',
'\n\nmodule.exports.themes = ' + JSON.stringify(themes, null, ' '),
';\n\n});'
].join('');
fs.writeFileSync(__dirname + '/lib/ace/ext/themelist_utils/themes.js', themelist, 'utf8');
}
if (!module.parent)
main(process.argv);
else

View file

@ -86,8 +86,7 @@ var AcePopup = function(parentNode) {
popup.on("mousedown", function(e) {
var pos = e.getDocumentPosition();
popup.moveCursorToPosition(pos);
popup.selection.clearSelection();
popup.selection.moveToPosition(pos);
selectionMarker.start.row = selectionMarker.end.row = pos.row;
e.stop();
});

View file

@ -144,8 +144,8 @@ exports.loadModule = function(moduleName, onLoad) {
// initialization
exports.init = function() {
options.packaged = require.packaged || module.packaged || (global.define && define.packaged);
function init(packaged) {
options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
if (!global.document)
return "";
@ -190,6 +190,8 @@ exports.init = function() {
exports.set(key, scriptOptions[key]);
};
exports.init = init;
function deHyphenate(str) {
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
}

View file

@ -56,7 +56,7 @@ var Document = function(text) {
// There has to be one line at least in the document. If you pass an empty
// string to the insert function, nothing will happen. Workaround.
if (text.length == 0) {
if (text.length === 0) {
this.$lines = [""];
} else if (Array.isArray(text)) {
this._insertLines(0, text);
@ -107,10 +107,10 @@ var Document = function(text) {
**/
// check for IE split bug
if ("aaa".split(/a/).length == 0)
if ("aaa".split(/a/).length === 0)
this.$split = function(text) {
return text.replace(/\r\n|\r/g, "\n").split("\n");
}
};
else
this.$split = function(text) {
return text.split(/\r\n|\r|\n/);
@ -120,6 +120,7 @@ var Document = function(text) {
this.$detectNewLine = function(text) {
var match = text.match(/^.*?(\r\n|\r|\n)/m);
this.$autoNewLine = match ? match[1] : "\n";
this._signal("changeNewLineMode");
};
/**
@ -136,11 +137,11 @@ var Document = function(text) {
case "unix":
return "\n";
default:
return this.$autoNewLine;
return this.$autoNewLine || "\n";
}
};
this.$autoNewLine = "\n";
this.$autoNewLine = "";
this.$newLineMode = "auto";
/**
* [Sets the new line mode.]{: #Document.setNewLineMode.desc}
@ -152,6 +153,7 @@ var Document = function(text) {
return;
this.$newLineMode = newLineMode;
this._signal("changeNewLineMode");
};
/**
@ -311,9 +313,10 @@ var Document = function(text) {
// apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF)
// to circumvent that we have to break huge inserts into smaller chunks here
if (lines.length > 0xFFFF) {
var end = this._insertLines(row, lines.slice(0xFFFF));
lines = lines.slice(0, 0xFFFF);
while (lines.length > 0xF000) {
var end = this._insertLines(row, lines.slice(0, 0xF000));
lines = lines.slice(0xF000);
row = end.row;
}
var args = [row, 0];
@ -327,7 +330,7 @@ var Document = function(text) {
lines: lines
};
this._signal("change", { data: delta });
return end || range.end;
return range.end;
};
/**

View file

@ -281,13 +281,13 @@ var EditSession = function(text, mode) {
**/
this.setValue = function(text) {
this.doc.setValue(text);
this.selection.moveCursorTo(0, 0);
this.selection.clearSelection();
this.selection.moveTo(0, 0);
this.$resetRowCache(0);
this.$deltas = [];
this.$deltasDoc = [];
this.$deltasFold = [];
this.setUndoManager(this.$undoManager);
this.getUndoManager().reset();
};
@ -412,7 +412,7 @@ var EditSession = function(text, mode) {
}
self.mergeUndoDeltas = false;
self.$deltas = [];
}
};
this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
}
};
@ -470,7 +470,7 @@ var EditSession = function(text, mode) {
* @param {Number} tabSize The new tab size
**/
this.setTabSize = function(tabSize) {
this.setOption("tabSize", tabSize)
this.setOption("tabSize", tabSize);
};
/**
* Returns the current tab size.
@ -486,7 +486,7 @@ var EditSession = function(text, mode) {
*
**/
this.isTabStop = function(position) {
return this.$useSoftTabs && (position.column % this.$tabSize == 0);
return this.$useSoftTabs && (position.column % this.$tabSize === 0);
};
this.$overwrite = false;
@ -500,7 +500,7 @@ var EditSession = function(text, mode) {
*
**/
this.setOverwrite = function(overwrite) {
this.setOption("overwrite", overwrite)
this.setOption("overwrite", overwrite);
};
/**
@ -622,14 +622,14 @@ var EditSession = function(text, mode) {
clazz : clazz,
inFront: !!inFront,
id: id
}
};
if (inFront) {
this.$frontMarkers[id] = marker;
this._signal("changeFrontMarker")
this._signal("changeFrontMarker");
} else {
this.$backMarkers[id] = marker;
this._signal("changeBackMarker")
this._signal("changeBackMarker");
}
return id;
@ -652,10 +652,10 @@ var EditSession = function(text, mode) {
if (inFront) {
this.$frontMarkers[id] = marker;
this._signal("changeFrontMarker")
this._signal("changeFrontMarker");
} else {
this.$backMarkers[id] = marker;
this._signal("changeBackMarker")
this._signal("changeBackMarker");
}
return marker;
@ -696,7 +696,7 @@ var EditSession = function(text, mode) {
this.$searchHighlight = this.addDynamicMarker(highlight);
}
this.$searchHighlight.setRegexp(re);
}
};
// experimental
this.highlightLines = function(startRow, endRow, clazz, inFront) {
@ -1043,14 +1043,14 @@ var EditSession = function(text, mode) {
};
this.getLineWidgetMaxWidth = function() {
if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth
if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
var width = 0;
this.lineWidgets.forEach(function(w) {
if (w && w.screenWidth > width)
width = w.screenWidth;
});
return this.lineWidgetWidth = width;
}
};
this.$computeWidth = function(force) {
if (this.$modified || force) {
@ -1268,7 +1268,7 @@ var EditSession = function(text, mode) {
// Check if this range and the last undo range has something in common.
// If true, merge the ranges.
if (lastUndoRange != null) {
if (Range.comparePoints(lastUndoRange.start, range.start) == 0) {
if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
lastUndoRange.start.column += range.end.column - range.start.column;
lastUndoRange.end.column += range.end.column - range.start.column;
}
@ -1556,10 +1556,7 @@ var EditSession = function(text, mode) {
// If wrapMode is activaed, the wrapData array has to be initialized.
if (useWrapMode) {
var len = this.getLength();
this.$wrapData = [];
for (var i = 0; i < len; i++) {
this.$wrapData.push([]);
}
this.$wrapData = Array(len);
this.$updateWrapData(0, len - 1);
}
@ -1719,16 +1716,10 @@ var EditSession = function(text, mode) {
lastRow = firstRow;
} else {
var args;
if (useWrapMode) {
args = [firstRow, 0];
for (var i = 0; i < len; i++) args.push([]);
this.$wrapData.splice.apply(this.$wrapData, args);
} else {
args = Array(len);
args.unshift(firstRow, 0);
this.$rowLengthCache.splice.apply(this.$rowLengthCache, args);
}
var args = Array(len);
args.unshift(firstRow, 0);
var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
arr.splice.apply(arr, args);
// If some new line is added inside of a foldLine, then split
// the fold line up.
@ -1833,8 +1824,7 @@ var EditSession = function(text, mode) {
lines[foldLine.end.row].length + 1
);
wrapData[foldLine.start.row]
= this.$computeWrapSplits(tokens, wrapLimit, tabSize);
wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row = foldLine.end.row + 1;
}
}
@ -2023,9 +2013,6 @@ var EditSession = function(text, mode) {
* The first position indicates the number of columns for `str` on screen.<br/>
* The second value contains the position of the document column that this function read until.
*
*
*
*
**/
this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
if (maxScreenColumn == 0)
@ -2326,14 +2313,16 @@ var EditSession = function(text, mode) {
// Clamp textLine if in wrapMode.
if (this.$useWrapMode) {
var wrapRow = this.$wrapData[foldStartRow];
var screenRowOffset = 0;
while (textLine.length >= wrapRow[screenRowOffset]) {
screenRow ++;
screenRowOffset++;
if (wrapRow) {
var screenRowOffset = 0;
while (textLine.length >= wrapRow[screenRowOffset]) {
screenRow ++;
screenRowOffset++;
}
textLine = textLine.substring(
wrapRow[screenRowOffset - 1] || 0, textLine.length
);
}
textLine = textLine.substring(
wrapRow[screenRowOffset - 1] || 0, textLine.length
);
}
return {
@ -2387,7 +2376,8 @@ var EditSession = function(text, mode) {
var foldStart = fold ? fold.start.row :Infinity;
while (row < lastRow) {
screenRows += this.$wrapData[row].length + 1;
var splits = this.$wrapData[row];
screenRows += splits ? splits.length + 1 : 1;
row ++;
if (row > foldStart) {
row = fold.end.row+1;
@ -2403,14 +2393,17 @@ var EditSession = function(text, mode) {
return screenRows;
};
// For every keystroke this gets called once per char in the whole doc!!
// Wouldn't hurt to make it a bit faster for c >= 0x1100
/**
* @private
*
*/
this.$setFontMetrics = function(fm) {
// todo
}
// For every keystroke this gets called once per char in the whole doc!!
// Wouldn't hurt to make it a bit faster for c >= 0x1100
function isFullWidth(c) {
if (c < 0x1100)
return false;

View file

@ -289,14 +289,13 @@ var Editor = function(renderer, session) {
* Sets a new editsession to use. This method also emits the `'changeSession'` event.
* @param {EditSession} session The new session to use
*
*
**/
this.setSession = function(session) {
if (this.session == session)
return;
if (this.session) {
var oldSession = this.session;
var oldSession = this.session;
if (oldSession) {
this.session.removeEventListener("change", this.$onDocumentChange);
this.session.removeEventListener("changeMode", this.$onChangeMode);
this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
@ -318,76 +317,80 @@ var Editor = function(renderer, session) {
}
this.session = session;
this.$onDocumentChange = this.onDocumentChange.bind(this);
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onChangeMode = this.onChangeMode.bind(this);
session.addEventListener("changeMode", this.$onChangeMode);
this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
session.addEventListener("changeTabSize", this.$onChangeTabSize);
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
this.$onChangeFold = this.onChangeFold.bind(this);
session.addEventListener("changeFold", this.$onChangeFold);
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.$onScrollTopChange = this.onScrollTopChange.bind(this);
this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
this.selection = session.getSelection();
this.selection.addEventListener("changeCursor", this.$onCursorChange);
this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onChangeMode();
this.$blockScrolling += 1;
this.onCursorChange();
this.$blockScrolling -= 1;
this.onScrollTopChange();
this.onScrollLeftChange();
this.onSelectionChange();
this.onChangeFrontMarker();
this.onChangeBackMarker();
this.onChangeBreakpoint();
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.updateFull();
if (session) {
this.$onDocumentChange = this.onDocumentChange.bind(this);
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onChangeMode = this.onChangeMode.bind(this);
session.addEventListener("changeMode", this.$onChangeMode);
this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
session.addEventListener("changeTabSize", this.$onChangeTabSize);
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
this.$onChangeFold = this.onChangeFold.bind(this);
session.addEventListener("changeFold", this.$onChangeFold);
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.$onScrollTopChange = this.onScrollTopChange.bind(this);
this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
this.selection = session.getSelection();
this.selection.addEventListener("changeCursor", this.$onCursorChange);
this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onChangeMode();
this.$blockScrolling += 1;
this.onCursorChange();
this.$blockScrolling -= 1;
this.onScrollTopChange();
this.onScrollLeftChange();
this.onSelectionChange();
this.onChangeFrontMarker();
this.onChangeBackMarker();
this.onChangeBreakpoint();
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.updateFull();
}
this._signal("changeSession", {
session: session,
oldSession: oldSession
});
oldSession && oldSession._signal("changeEditor", {oldEditor: this});
session && session._signal("changeEditor", {editor: this});
};
/**
@ -660,7 +663,7 @@ var Editor = function(renderer, session) {
if (this.$highlightActiveLine) {
if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
highlight = this.getCursorPosition();
if (this.renderer.$maxLines && this.session.getLength() === 1)
if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
highlight = false;
}
@ -846,14 +849,13 @@ var Editor = function(renderer, session) {
* Inserts `text` into wherever the cursor is pointing.
* @param {String} text The new text to add
*
*
**/
this.insert = function(text) {
this.insert = function(text, pasted) {
var session = this.session;
var mode = session.getMode();
var cursor = this.getCursorPosition();
if (this.getBehavioursEnabled()) {
if (this.getBehavioursEnabled() && !pasted) {
// Get a transform if the current mode wants one.
var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
if (transform) {
@ -1942,8 +1944,7 @@ var Editor = function(renderer, session) {
else
this.selection.selectTo(pos.row, pos.column);
} else {
this.clearSelection();
this.moveCursorTo(pos.row, pos.column);
this.selection.moveTo(pos.row, pos.column);
}
}
};
@ -1978,8 +1979,7 @@ var Editor = function(renderer, session) {
* @related Editor.moveCursorTo
**/
this.navigateTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
this.selection.moveTo(row, column);
};
/**
@ -1994,8 +1994,7 @@ var Editor = function(renderer, session) {
return this.moveCursorToPosition(selectionStart);
}
this.selection.clearSelection();
times = times || 1;
this.selection.moveCursorBy(-times, 0);
this.selection.moveCursorBy(-times || -1, 0);
};
/**
@ -2010,8 +2009,7 @@ var Editor = function(renderer, session) {
return this.moveCursorToPosition(selectionEnd);
}
this.selection.clearSelection();
times = times || 1;
this.selection.moveCursorBy(times, 0);
this.selection.moveCursorBy(times || 1, 0);
};
/**
@ -2155,8 +2153,7 @@ var Editor = function(renderer, session) {
this.$blockScrolling += 1;
var selection = this.getSelectionRange();
this.clearSelection();
this.selection.moveCursorTo(0, 0);
this.selection.moveTo(0, 0);
for (var i = ranges.length - 1; i >= 0; --i) {
if(this.$tryReplace(ranges[i], replacement)) {

View file

@ -130,8 +130,7 @@ AceEmmetEditor.prototype = {
*/
setCaretPos: function(index){
var pos = this.ace.indexToPosition(index);
this.ace.clearSelection();
this.ace.selection.moveCursorToPosition(pos);
this.ace.selection.moveToPosition(pos);
},
/**

View file

@ -122,8 +122,7 @@ exports.showErrorMarker = function(editor, dir) {
};
}
editor.session.unfold(pos.row);
editor.selection.moveCursorToPosition(pos);
editor.selection.clearSelection();
editor.selection.moveToPosition(pos);
var w = {
row: pos.row,
@ -143,12 +142,12 @@ exports.showErrorMarker = function(editor, dir) {
el.className = "error_widget " + gutterAnno.className;
el.innerHTML = gutterAnno.text.join("<br>");
var kb = {
handleKeyboard:function(_,hashId, keyString) {
if (hashId === 0 && keyString === "esc") {
w.destroy();
return true;
}
el.appendChild(dom.createElement("div"));
var kb = function(_, hashId, keyString) {
if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
w.destroy();
return {command: "null"};
}
};

View file

@ -145,8 +145,8 @@ exports.handler = {
if (hashId == -1 || hashId == 1 || hashId === 0 && key.length > 1) {
if (cmds.inputBuffer.idle && startCommands[key])
return startCommands[key];
cmds.inputBuffer.push(editor, key);
return {command: "null", passEvent: false};
var isHandled = cmds.inputBuffer.push(editor, key);
return {command: "null", passEvent: !isHandled};
} // if no modifier || shift: wait for input.
else if (key.length == 1 && (hashId === 0 || hashId == 4)) {
return {command: "null", passEvent: true};

View file

@ -201,8 +201,7 @@ var actions = exports.actions = {
//editor.selection.selectLine();
//editor.selection.selectLeft();
var row = editor.getCursorPosition().row;
editor.selection.clearSelection();
editor.selection.moveCursorTo(row, 0);
editor.selection.moveTo(row, 0);
editor.selection.selectLineEnd();
editor.selection.visualLineStart = row;
@ -582,13 +581,11 @@ var handleCursorMove = exports.onCursorMove = function(editor, e) {
var cursorRow = editor.getCursorPosition().row;
if(originRow <= cursorRow) {
var endLine = editor.session.getLine(cursorRow);
editor.selection.clearSelection();
editor.selection.moveCursorTo(originRow, 0);
editor.selection.moveTo(originRow, 0);
editor.selection.selectTo(cursorRow, endLine.length);
} else {
var endLine = editor.session.getLine(originRow);
editor.selection.clearSelection();
editor.selection.moveCursorTo(originRow, endLine.length);
editor.selection.moveTo(originRow, endLine.length);
editor.selection.selectTo(cursorRow, 0);
}
}

View file

@ -53,8 +53,7 @@ function Motion(m) {
var a = getPos(editor, range, count, param, false);
if (!a)
return;
editor.clearSelection();
editor.moveCursorTo(a.row, a.column);
editor.selection.moveTo(a.row, a.column);
};
m.sel = function(editor, range, count, param) {
var a = getPos(editor, range, count, param, true);

View file

@ -122,13 +122,11 @@ module.exports = {
},
copyLine: function(editor) {
var pos = editor.getCursorPosition();
editor.selection.clearSelection();
editor.moveCursorTo(pos.row, pos.column);
editor.selection.moveTo(pos.row, pos.column);
editor.selection.selectLine();
registers._default.isLine = true;
registers._default.text = editor.getCopyText().replace(/\n$/, "");
editor.selection.clearSelection();
editor.moveCursorTo(pos.row, pos.column);
editor.selection.moveTo(pos.row, pos.column);
}
};
});

View file

@ -190,7 +190,7 @@ var Cursor = function(parentEl) {
for (var i = 0, n = selections.length; i < n; i++) {
var pixelPos = this.getPixelPosition(selections[i].cursor, true);
if ((pixelPos.top > config.height + config.offset ||
pixelPos.top < -config.offset) && i > 1) {
pixelPos.top < 0) && i > 1) {
continue;
}

View file

@ -0,0 +1,158 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var oop = require("../lib/oop");
var dom = require("../lib/dom");
var lang = require("../lib/lang");
var EventEmitter = require("../lib/event_emitter").EventEmitter;
var CHAR_COUNT = 0;
var FontMetrics = exports.FontMetrics = function(parentEl, interval) {
this.el = dom.createElement("div");
this.$setMeasureNodeStyles(this.el.style, true);
this.$main = dom.createElement("div");
this.$setMeasureNodeStyles(this.$main.style);
this.$measureNode = dom.createElement("div");
this.$setMeasureNodeStyles(this.$measureNode.style);
this.el.appendChild(this.$main);
this.el.appendChild(this.$measureNode);
parentEl.appendChild(this.el);
if (!CHAR_COUNT)
this.$testFractionalRect();
this.$measureNode.textContent = lang.stringRepeat("X", CHAR_COUNT);
this.$characterSize = {width: 0, height: 0};
this.checkForSizeChanges();
};
(function() {
oop.implement(this, EventEmitter);
this.$characterSize = {width: 0, height: 0};
this.$testFractionalRect = function() {
var el = dom.createElement("div");
this.$setMeasureNodeStyles(el.style);
el.style.width = "0.2px";
document.documentElement.appendChild(el);
var w = el.getBoundingClientRect().width;
if (w > 0 && w < 1)
CHAR_COUNT = 1;
else
CHAR_COUNT = 100;
el.parentNode.removeChild(el);
};
this.$setMeasureNodeStyles = function(style, isRoot) {
style.width = style.height = "auto";
style.left = style.top = "-100px";
style.visibility = "hidden";
style.position = "fixed";
style.whiteSpace = "pre";
style.font = "inherit";
style.overflow = isRoot ? "hidden" : "visible";
};
this.checkForSizeChanges = function() {
var size = this.$measureSizes();
if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
this.$measureNode.style.fontWeight = "bold";
var boldSize = this.$measureSizes();
this.$measureNode.style.fontWeight = "";
this.$characterSize = size;
this.charSizes = Object.create(null);
this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
this._emit("changeCharacterSize", {data: size});
}
};
this.$pollSizeChanges = function() {
if (this.$pollSizeChangesTimer)
return this.$pollSizeChangesTimer;
var self = this;
return this.$pollSizeChangesTimer = setInterval(function() {
self.checkForSizeChanges();
}, 500);
};
this.setPolling = function(val) {
if (val) {
this.$pollSizeChanges();
} else {
if (this.$pollSizeChangesTimer)
this.$pollSizeChangesTimer;
}
};
this.$measureSizes = function() {
var rect = this.$measureNode.getBoundingClientRect();
var size = {
height: rect.height,
width: rect.width / CHAR_COUNT
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width === 0 || size.height === 0)
return null;
return size;
};
this.$measureCharWidth = function(ch) {
this.$main.textContent = lang.stringRepeat(ch, CHAR_COUNT);
var rect = this.$main.getBoundingClientRect();
return rect.width / CHAR_COUNT;
};
this.getCharacterWidth = function(ch) {
var w = this.charSizes[ch];
if (w === undefined) {
this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
}
return w;
};
this.destroy = function() {
clearInterval(this.$pollSizeChangesTimer);
if (this.el && this.el.parentNode)
this.el.parentNode.removeChild(this.el);
};
}).call(FontMetrics.prototype);
});

View file

@ -120,7 +120,8 @@ var Gutter = function(parentEl) {
this.update = function(config) {
var session = this.session;
var firstRow = config.firstRow;
var lastRow = Math.min(config.lastRow + 1, session.getLength() - 1); // needed to compensate
var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
session.getLength() - 1);
var fold = session.getNextFoldLine(firstRow);
var foldStart = fold ? fold.start.row : Infinity;
var foldWidgets = this.$showFoldWidgets && session.foldWidgets;

View file

@ -41,154 +41,58 @@ var Text = function(parentEl) {
this.element = dom.createElement("div");
this.element.className = "ace_layer ace_text-layer";
parentEl.appendChild(this.element);
this.$characterSize = {width: 0, height: 0};
this.checkForSizeChanges();
this.$pollSizeChanges();
this.$updateEolChar = this.$updateEolChar.bind(this);
};
(function() {
oop.implement(this, EventEmitter);
this.EOF_CHAR = "\xB6"; //"&para;";
this.EOL_CHAR = "\xAC"; //"&not;";
this.TAB_CHAR = "\u2192"; //"&rarr;" "\u21E5";
this.SPACE_CHAR = "\xB7"; //"&middot;";
this.EOF_CHAR = "\xB6";
this.EOL_CHAR_LF = "\xAC";
this.EOL_CHAR_CRLF = "\xa4";
this.EOL_CHAR = this.EOL_CHAR_LF;
this.TAB_CHAR = "\u2192"; //"\u21E5";
this.SPACE_CHAR = "\xB7";
this.$padding = 0;
this.$updateEolChar = function() {
var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
? this.EOL_CHAR_LF
: this.EOL_CHAR_CRLF;
if (this.EOL_CHAR != EOL_CHAR) {
this.EOL_CHAR = EOL_CHAR;
return true;
}
}
this.setPadding = function(padding) {
this.$padding = padding;
this.element.style.padding = "0 " + padding + "px";
};
this.getLineHeight = function() {
return this.$characterSize.height || 0;
return this.$fontMetrics.$characterSize.height || 0;
};
this.getCharacterWidth = function() {
return this.$characterSize.width || 0;
return this.$fontMetrics.$characterSize.width || 0;
};
this.$setFontMetrics = function(measure) {
this.$fontMetrics = measure;
this.$fontMetrics.on("changeCharacterSize", function(e) {
this._signal("changeCharacterSize", e);
}.bind(this));
this.$pollSizeChanges();
}
this.checkForSizeChanges = function() {
var size = this.$measureSizes();
if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
this.$measureNode.style.fontWeight = "bold";
var boldSize = this.$measureSizes();
this.$measureNode.style.fontWeight = "";
this.$characterSize = size;
this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
this._emit("changeCharacterSize", {data: size});
}
this.$fontMetrics.checkForSizeChanges();
};
this.$pollSizeChanges = function() {
var self = this;
this.$pollSizeChangesTimer = setInterval(function() {
self.checkForSizeChanges();
}, 500);
return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
};
this.$fontStyles = {
fontFamily : 1,
fontSize : 1,
fontWeight : 1,
fontStyle : 1,
lineHeight : 1
};
this.$measureSizes = useragent.isIE || useragent.isOldGecko ? function() {
var n = 1000;
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
var style = measureNode.style;
style.width = style.height = "auto";
style.left = style.top = (-n * 40) + "px";
style.visibility = "hidden";
style.position = "fixed";
style.overflow = "visible";
style.whiteSpace = "nowrap";
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
// that's why we have to measure many characters
// Note: characterWidth can be a float!
measureNode.innerHTML = lang.stringRepeat("Xy", n);
if (this.element.ownerDocument.body) {
this.element.ownerDocument.body.appendChild(measureNode);
} else {
var container = this.element.parentNode;
while (!dom.hasCssClass(container, "ace_editor"))
container = container.parentNode;
container.appendChild(measureNode);
}
}
// Size and width can be null if the editor is not visible or
// detached from the document
if (!this.element.offsetWidth)
return null;
var style = this.$measureNode.style;
var computedStyle = dom.computedStyle(this.element);
for (var prop in this.$fontStyles)
style[prop] = computedStyle[prop];
var size = {
height: this.$measureNode.offsetHeight,
width: this.$measureNode.offsetWidth / (n * 2)
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width == 0 || size.height == 0)
return null;
return size;
}
: function() {
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
var style = measureNode.style;
style.width = style.height = "auto";
style.left = style.top = -100 + "px";
style.visibility = "hidden";
style.position = "fixed";
style.overflow = "visible";
style.whiteSpace = "nowrap";
// fixes fractional fixed-width fonts; see http://git.io/CavZNw
measureNode.innerHTML = lang.stringRepeat("X", 100);
var container = this.element.parentNode;
while (container && !dom.hasCssClass(container, "ace_editor"))
container = container.parentNode;
if (!container)
return this.$measureNode = null;
container.appendChild(measureNode);
}
var rect = this.$measureNode.getBoundingClientRect();
var size = {
height: rect.height,
width: rect.width / 100
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width == 0 || size.height == 0)
return null;
return size;
};
this.setSession = function(session) {
this.session = session;
this.$computeTabString();

View file

@ -33,7 +33,6 @@ define(function(require, exports, module) {
var keys = require("./keys");
var useragent = require("./useragent");
var dom = require("./dom");
exports.addListener = function(elem, type, callback) {
if (elem.addEventListener) {
@ -170,7 +169,7 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac
};
exports.addListener(el, "mousedown", function(e) {
if (exports.getButton(e) != 0) {
if (exports.getButton(e) !== 0) {
clicks = 0;
} else if (e.detail > 1) {
clicks++;
@ -210,22 +209,27 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac
}
};
function normalizeCommandKeys(callback, e, keyCode) {
var hashId = 0;
if ((useragent.isOpera && !("KeyboardEvent" in window)) && useragent.isMac) {
hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0)
| (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
} else {
hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0)
| (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
? function(e) {
return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
}
: function(e) {
return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
};
exports.getModifierString = function(e) {
return keys.KEY_MODS[getModifierHash(e)];
};
function normalizeCommandKeys(callback, e, keyCode) {
var hashId = getModifierHash(e);
if (!useragent.isMac && pressedKeys) {
if (pressedKeys[91] || pressedKeys[92])
hashId |= 8;
if (pressedKeys.altGr) {
if ((3 & hashId) != 3)
pressedKeys.altGr = 0
pressedKeys.altGr = 0;
else
return;
}
@ -267,12 +271,11 @@ function normalizeCommandKeys(callback, e, keyCode) {
if (!hashId && keyCode === 13) {
if (e.location || e.keyLocation === 3) {
callback(e, hashId, -keyCode)
callback(e, hashId, -keyCode);
if (e.defaultPrevented)
return;
}
}
// If there is no hashId and the keyCode is not a function key, then
// we don't call the callback as we don't handle a command key here
@ -281,8 +284,6 @@ function normalizeCommandKeys(callback, e, keyCode) {
return false;
}
return callback(e, hashId, keyCode);
}

View file

@ -133,6 +133,15 @@ var Keys = (function() {
// workaround for firefox bug
ret[173] = '-';
(function() {
var mods = ["cmd", "ctrl", "alt", "shift"];
for (var i = Math.pow(2, mods.length); i--;) {
ret.KEY_MODS[i] = mods.filter(function(x) {
return i & ret.KEY_MODS[x];
}).join("-") + "-";
}
})();
return ret;
})();
@ -140,6 +149,6 @@ oop.mixin(exports, Keys);
exports.keyCodeToString = function(keyCode) {
return (Keys[keyCode] || String.fromCharCode(keyCode)).toLowerCase();
}
};
});

View file

@ -41,89 +41,34 @@ var SAFE_INSERT_IN_TOKENS =
var SAFE_INSERT_BEFORE_TOKENS =
["text", "paren.rparen", "punctuation.operator", "comment"];
var context;
var contextCache = {}
var initContext = function(editor) {
var id = -1;
if (editor.multiSelect) {
id = editor.selection.id;
if (contextCache.rangeCount != editor.multiSelect.rangeCount)
contextCache = {rangeCount: editor.multiSelect.rangeCount};
}
if (contextCache[id])
return context = contextCache[id];
context = contextCache[id] = {
autoInsertedBrackets: 0,
autoInsertedRow: -1,
autoInsertedLineEnd: "",
maybeInsertedBrackets: 0,
maybeInsertedRow: -1,
maybeInsertedLineStart: "",
maybeInsertedLineEnd: ""
};
};
var autoInsertedBrackets = 0;
var autoInsertedRow = -1;
var autoInsertedLineEnd = "";
var maybeInsertedBrackets = 0;
var maybeInsertedRow = -1;
var maybeInsertedLineStart = "";
var maybeInsertedLineEnd = "";
var CstyleBehaviour = function () {
CstyleBehaviour.isSaneInsertion = function(editor, session) {
var cursor = editor.getCursorPosition();
var iterator = new TokenIterator(session, cursor.row, cursor.column);
// Don't insert in the middle of a keyword/identifier/lexical
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
// Look ahead in case we're at the end of a token
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
return false;
}
// Only insert in front of whitespace/comments
iterator.stepForward();
return iterator.getCurrentTokenRow() !== cursor.row ||
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
};
CstyleBehaviour.$matchTokenType = function(token, types) {
return types.indexOf(token.type || token) > -1;
};
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
// Reset previous state if text or context changed too much
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
autoInsertedBrackets = 0;
autoInsertedRow = cursor.row;
autoInsertedLineEnd = bracket + line.substr(cursor.column);
autoInsertedBrackets++;
};
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (!this.isMaybeInsertedClosing(cursor, line))
maybeInsertedBrackets = 0;
maybeInsertedRow = cursor.row;
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
maybeInsertedLineEnd = line.substr(cursor.column);
maybeInsertedBrackets++;
};
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
return autoInsertedBrackets > 0 &&
cursor.row === autoInsertedRow &&
bracket === autoInsertedLineEnd[0] &&
line.substr(cursor.column) === autoInsertedLineEnd;
};
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
return maybeInsertedBrackets > 0 &&
cursor.row === maybeInsertedRow &&
line.substr(cursor.column) === maybeInsertedLineEnd &&
line.substr(0, cursor.column) == maybeInsertedLineStart;
};
CstyleBehaviour.popAutoInsertedClosing = function() {
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
autoInsertedBrackets--;
};
CstyleBehaviour.clearMaybeInsertedClosing = function() {
maybeInsertedBrackets = 0;
maybeInsertedRow = -1;
};
this.add("braces", "insertion", function (state, action, editor, session, text) {
var CstyleBehaviour = function() {
this.add("braces", "insertion", function(state, action, editor, session, text) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (text == '{') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
@ -147,6 +92,7 @@ var CstyleBehaviour = function () {
}
}
} else if (text == '}') {
initContext(editor);
var rightChar = line.substring(cursor.column, cursor.column + 1);
if (rightChar == '}') {
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
@ -159,9 +105,10 @@ var CstyleBehaviour = function () {
}
}
} else if (text == "\n" || text == "\r\n") {
initContext(editor);
var closing = "";
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
closing = lang.stringRepeat("}", maybeInsertedBrackets);
closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
CstyleBehaviour.clearMaybeInsertedClosing();
}
var rightChar = line.substring(cursor.column, cursor.column + 1);
@ -173,6 +120,7 @@ var CstyleBehaviour = function () {
} else if (closing) {
var next_indent = this.$getIndent(line);
} else {
CstyleBehaviour.clearMaybeInsertedClosing();
return;
}
var indent = next_indent + session.getTabString();
@ -186,22 +134,24 @@ var CstyleBehaviour = function () {
}
});
this.add("braces", "deletion", function (state, action, editor, session, range) {
this.add("braces", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '{') {
initContext(editor);
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.end.column, range.end.column + 1);
if (rightChar == '}') {
range.end.column++;
return range;
} else {
maybeInsertedBrackets--;
context.maybeInsertedBrackets--;
}
}
});
this.add("parens", "insertion", function (state, action, editor, session, text) {
this.add("parens", "insertion", function(state, action, editor, session, text) {
if (text == '(') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
@ -217,6 +167,7 @@ var CstyleBehaviour = function () {
};
}
} else if (text == ')') {
initContext(editor);
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
var rightChar = line.substring(cursor.column, cursor.column + 1);
@ -233,9 +184,10 @@ var CstyleBehaviour = function () {
}
});
this.add("parens", "deletion", function (state, action, editor, session, range) {
this.add("parens", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '(') {
initContext(editor);
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
if (rightChar == ')') {
@ -245,8 +197,9 @@ var CstyleBehaviour = function () {
}
});
this.add("brackets", "insertion", function (state, action, editor, session, text) {
this.add("brackets", "insertion", function(state, action, editor, session, text) {
if (text == '[') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
@ -262,6 +215,7 @@ var CstyleBehaviour = function () {
};
}
} else if (text == ']') {
initContext(editor);
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
var rightChar = line.substring(cursor.column, cursor.column + 1);
@ -278,9 +232,10 @@ var CstyleBehaviour = function () {
}
});
this.add("brackets", "deletion", function (state, action, editor, session, range) {
this.add("brackets", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '[') {
initContext(editor);
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
if (rightChar == ']') {
@ -290,8 +245,9 @@ var CstyleBehaviour = function () {
}
});
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
if (text == '"' || text == "'") {
initContext(editor);
var quote = text;
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
@ -350,9 +306,10 @@ var CstyleBehaviour = function () {
}
});
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
initContext(editor);
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
if (rightChar == selected) {
@ -364,6 +321,79 @@ var CstyleBehaviour = function () {
};
CstyleBehaviour.isSaneInsertion = function(editor, session) {
var cursor = editor.getCursorPosition();
var iterator = new TokenIterator(session, cursor.row, cursor.column);
// Don't insert in the middle of a keyword/identifier/lexical
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
// Look ahead in case we're at the end of a token
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
return false;
}
// Only insert in front of whitespace/comments
iterator.stepForward();
return iterator.getCurrentTokenRow() !== cursor.row ||
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
};
CstyleBehaviour.$matchTokenType = function(token, types) {
return types.indexOf(token.type || token) > -1;
};
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
// Reset previous state if text or context changed too much
if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
context.autoInsertedBrackets = 0;
context.autoInsertedRow = cursor.row;
context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
context.autoInsertedBrackets++;
};
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (!this.isMaybeInsertedClosing(cursor, line))
context.maybeInsertedBrackets = 0;
context.maybeInsertedRow = cursor.row;
context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
context.maybeInsertedLineEnd = line.substr(cursor.column);
context.maybeInsertedBrackets++;
};
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
return context.autoInsertedBrackets > 0 &&
cursor.row === context.autoInsertedRow &&
bracket === context.autoInsertedLineEnd[0] &&
line.substr(cursor.column) === context.autoInsertedLineEnd;
};
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
return context.maybeInsertedBrackets > 0 &&
cursor.row === context.maybeInsertedRow &&
line.substr(cursor.column) === context.maybeInsertedLineEnd &&
line.substr(0, cursor.column) == context.maybeInsertedLineStart;
};
CstyleBehaviour.popAutoInsertedClosing = function() {
context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
context.autoInsertedBrackets--;
};
CstyleBehaviour.clearMaybeInsertedClosing = function() {
if (context) {
context.maybeInsertedBrackets = 0;
context.maybeInsertedRow = -1;
}
};
oop.inherits(CstyleBehaviour, Behaviour);
exports.CstyleBehaviour = CstyleBehaviour;

View file

@ -1,5 +1,5 @@
define(["require", "exports", "module"], function(require, exports, module){
require=(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
define(function(require, exports, module){
var req = require=(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(req,module,exports){
function isScopeMarker(node) {
if (node.namespaceURI === "http://www.w3.org/1999/xhtml") {
return node.localName === "applet"
@ -228,9 +228,9 @@ Object.defineProperty(ElementStack.prototype, 'length', {
exports.ElementStack = ElementStack;
},{}],2:[function(require,module,exports){
var entities = require('html5-entities');
var InputStream = require('./InputStream').InputStream;
},{}],2:[function(req,module,exports){
var entities = req('html5-entities');
var InputStream = req('./InputStream').InputStream;
/**
* Magic value for UTF-16 operations.
@ -413,7 +413,7 @@ EntityParser.replaceEntityNumbers = function(c) {
exports.EntityParser = EntityParser;
},{"./InputStream":3,"html5-entities":12}],3:[function(require,module,exports){
},{"./InputStream":3,"html5-entities":12}],3:[function(req,module,exports){
// FIXME convert CR to LF http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#input-stream
function InputStream() {
this.data = '';
@ -523,7 +523,7 @@ InputStream.prototype = {
exports.InputStream = InputStream;
},{}],4:[function(require,module,exports){
},{}],4:[function(req,module,exports){
var SpecialElements = {
"http://www.w3.org/1999/xhtml": [
'address',
@ -704,9 +704,9 @@ StackItem.prototype.isMathMLTextIntegrationPoint = function() {
exports.StackItem = StackItem;
},{}],5:[function(require,module,exports){
var InputStream = require('./InputStream').InputStream;
var EntityParser = require('./EntityParser').EntityParser;
},{}],5:[function(req,module,exports){
var InputStream = req('./InputStream').InputStream;
var EntityParser = req('./EntityParser').EntityParser;
function isWhitespace(c){
return c === " " || c === "\n" || c === "\t" || c === "\r" || c === "\f";
@ -2257,17 +2257,17 @@ Tokenizer.prototype.tokenize = function(source) {
exports.Tokenizer = Tokenizer;
},{"./EntityParser":2,"./InputStream":3}],6:[function(require,module,exports){
(function(){var assert = require('assert');
},{"./EntityParser":2,"./InputStream":3}],6:[function(req,module,exports){
(function(){var assert = req('assert');
var messages = require('./messages.json');
var constants = require('./constants');
var messages = req('./messages.json');
var constants = req('./constants');
var EventEmitter = require('events').EventEmitter;
var EventEmitter = req('events').EventEmitter;
var Tokenizer = require('./Tokenizer').Tokenizer;
var ElementStack = require('./ElementStack').ElementStack;
var StackItem = require('./StackItem').StackItem;
var Tokenizer = req('./Tokenizer').Tokenizer;
var ElementStack = req('./ElementStack').ElementStack;
var StackItem = req('./StackItem').StackItem;
var Marker = {};
@ -5322,7 +5322,7 @@ function formatMessage(format, args) {
exports.TreeBuilder = TreeBuilder;
})()
},{"./ElementStack":1,"./StackItem":4,"./Tokenizer":5,"./constants":7,"./messages.json":8,"assert":13,"events":14}],7:[function(require,module,exports){
},{"./ElementStack":1,"./StackItem":4,"./Tokenizer":5,"./constants":7,"./messages.json":8,"assert":13,"events":14}],7:[function(req,module,exports){
exports.SVGTagMap = {
"altglyph": "altGlyph",
"altglyphdef": "altGlyphDef",
@ -5445,7 +5445,7 @@ exports.ForeignAttributeMap = {
"xmlns": {prefix: null, localName: "xmlns", namespaceURI: "http://www.w3.org/2000/xmlns/"},
"xmlns:xlink": {prefix: "xmlns", localName: "xlink", namespaceURI: "http://www.w3.org/2000/xmlns/"},
};
},{}],8:[function(require,module,exports){
},{}],8:[function(req,module,exports){
module.exports={
"null-character":
"Null character in input stream, replaced with U+FFFD.",
@ -5702,10 +5702,10 @@ module.exports={
"unexpected-start-tag-in-table":
"Unexpected {name}. Expected table content."
}
},{}],"DaboPu":[function(require,module,exports){
var SAXTreeBuilder = require('./SAXTreeBuilder').SAXTreeBuilder;
var Tokenizer = require('../Tokenizer').Tokenizer;
var TreeParser = require('./TreeParser').TreeParser;
},{}],"DaboPu":[function(req,module,exports){
var SAXTreeBuilder = req('./SAXTreeBuilder').SAXTreeBuilder;
var Tokenizer = req('../Tokenizer').Tokenizer;
var TreeParser = req('./TreeParser').TreeParser;
function SAXParser() {
this.contentHandler = null;
@ -5754,9 +5754,9 @@ Object.defineProperty(SAXParser.prototype, 'errorHandler', {
exports.SAXParser = SAXParser;
},{"../Tokenizer":5,"./SAXTreeBuilder":10,"./TreeParser":11}],10:[function(require,module,exports){
var util = require('util');
var TreeBuilder = require('../TreeBuilder').TreeBuilder;
},{"../Tokenizer":5,"./SAXTreeBuilder":10,"./TreeParser":11}],10:[function(req,module,exports){
var util = req('util');
var TreeBuilder = req('../TreeBuilder').TreeBuilder;
function SAXTreeBuilder() {
TreeBuilder.call(this);
@ -6429,7 +6429,7 @@ DTD.prototype.revisit = function(treeParser) {
exports.SAXTreeBuilder = SAXTreeBuilder;
},{"../TreeBuilder":6,"util":15}],11:[function(require,module,exports){
},{"../TreeBuilder":6,"util":15}],11:[function(req,module,exports){
/**
* A tree visitor that replays a tree as SAX events.
* @version $Id$
@ -6712,7 +6712,7 @@ NullLexicalHandler.prototype.startEntity = function() {};
exports.TreeParser = TreeParser;
},{}],12:[function(require,module,exports){
},{}],12:[function(req,module,exports){
module.exports = {
"AElig": "\u00C6",
"AElig;": "\u00C6",
@ -8947,10 +8947,10 @@ module.exports = {
"zwnj;": "\u200C"
};
},{}],13:[function(require,module,exports){
},{}],13:[function(req,module,exports){
(function(){// UTILITY
var util = require('util');
var Buffer = require("buffer").Buffer;
var util = req('util');
var Buffer = req("buffer").Buffer;
var pSlice = Array.prototype.slice;
function objectKeys(object) {
@ -9262,7 +9262,7 @@ assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
assert.ifError = function(err) { if (err) {throw err;}};
})()
},{"buffer":17,"util":15}],14:[function(require,module,exports){
},{"buffer":17,"util":15}],14:[function(req,module,exports){
(function(process){if (!process.EventEmitter) process.EventEmitter = function () {};
var EventEmitter = exports.EventEmitter = process.EventEmitter;
@ -9447,9 +9447,9 @@ EventEmitter.prototype.listeners = function(type) {
return this._events[type];
};
})(require("__browserify_process"))
},{"__browserify_process":20}],15:[function(require,module,exports){
var events = require('events');
})(req("__browserify_process"))
},{"__browserify_process":20}],15:[function(req,module,exports){
var events = req('events');
exports.isArray = isArray;
exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
@ -9795,7 +9795,7 @@ exports.format = function(f) {
return str;
};
},{"events":14}],16:[function(require,module,exports){
},{"events":14}],16:[function(req,module,exports){
exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
var e, m,
eLen = nBytes * 8 - mLen - 1,
@ -9881,8 +9881,8 @@ exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
buffer[offset + i - d] |= s * 128;
};
},{}],17:[function(require,module,exports){
(function(){var assert = require('assert');
},{}],17:[function(req,module,exports){
(function(){var assert = req('assert');
exports.Buffer = Buffer;
exports.SlowBuffer = Buffer;
Buffer.poolSize = 8192;
@ -9992,7 +9992,7 @@ Buffer.prototype.base64Write = function (string, offset, length) {
Buffer.prototype.base64Slice = function (start, end) {
var bytes = Array.prototype.slice.apply(this, arguments)
return require("base64-js").fromByteArray(bytes);
return req("base64-js").fromByteArray(bytes);
};
Buffer.prototype.utf8Slice = function () {
@ -10353,7 +10353,7 @@ function asciiToBytes(str) {
}
function base64ToBytes(str) {
return require("base64-js").toByteArray(str);
return req("base64-js").toByteArray(str);
}
function blitBuffer(src, dst, offset, length) {
@ -10618,7 +10618,7 @@ function readFloat(buffer, offset, isBigEndian, noAssert) {
'Trying to read beyond buffer length');
}
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
return req('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
23, 4);
}
@ -10639,7 +10639,7 @@ function readDouble(buffer, offset, isBigEndian, noAssert) {
'Trying to read beyond buffer length');
}
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
return req('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
52, 8);
}
@ -10923,7 +10923,7 @@ function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
}
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
req('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
23, 4);
}
@ -10952,7 +10952,7 @@ function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
}
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
req('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
52, 8);
}
@ -10965,7 +10965,7 @@ Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
};
})()
},{"./buffer_ieee754":16,"assert":13,"base64-js":18}],18:[function(require,module,exports){
},{"./buffer_ieee754":16,"assert":13,"base64-js":18}],18:[function(req,module,exports){
(function (exports) {
'use strict';
@ -11051,9 +11051,9 @@ Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
module.exports.fromByteArray = uint8ToBase64;
}());
},{}],"./lib/sax/SAXParser.js":[function(require,module,exports){
module.exports=require('DaboPu');
},{}],20:[function(require,module,exports){
},{}],"./lib/sax/SAXParser.js":[function(req,module,exports){
module.exports=req('DaboPu');
},{}],20:[function(req,module,exports){
// shim for using process in browser
var process = module.exports = {};
@ -11109,5 +11109,5 @@ process.chdir = function (dir) {
},{}]},{},["DaboPu"])
;
exports.SAXParser = require('./lib/sax/SAXParser.js').SAXParser;
});
exports.SAXParser = req('./lib/sax/SAXParser.js').SAXParser;
});

View file

@ -72,8 +72,7 @@ function DefaultHandlers(mouseHandler) {
var selectionEmpty = selectionRange.isEmpty();
if (selectionEmpty) {
editor.moveCursorToPosition(pos);
editor.selection.clearSelection();
editor.selection.moveToPosition(pos);
}
// 2: contextmenu, 1: linux paste
@ -93,6 +92,7 @@ function DefaultHandlers(mouseHandler) {
}
}
this.captureMouse(ev);
if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
// Directly pick STATE_SELECT, since the user is not clicking inside
// a selection.
@ -101,7 +101,6 @@ function DefaultHandlers(mouseHandler) {
this.mousedownEvent.time = Date.now();
this.startSelect(pos);
}
this.captureMouse(ev);
return ev.preventDefault();
};
@ -114,8 +113,7 @@ function DefaultHandlers(mouseHandler) {
editor.selection.selectToPosition(pos);
}
else if (!this.$clickSelection) {
editor.moveCursorToPosition(pos);
editor.selection.clearSelection();
editor.selection.moveToPosition(pos);
}
if (editor.renderer.scroller.setCapture) {
editor.renderer.scroller.setCapture();

View file

@ -32,7 +32,6 @@ define(function(require, exports, module) {
var event = require("../lib/event");
// mouse
function isSamePoint(p1, p2) {
return p1.row == p2.row && p1.column == p2.column;
@ -51,7 +50,7 @@ function onMouseDown(e) {
}
if (!ctrl && !alt) {
if (button == 0 && e.editor.inMultiSelectMode)
if (button === 0 && e.editor.inMultiSelectMode)
e.editor.exitMultiSelectMode();
return;
}
@ -79,8 +78,7 @@ function onMouseDown(e) {
return;
screenCursor = newCursor;
editor.selection.moveCursorToPosition(cursor);
editor.selection.clearSelection();
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel);
@ -95,7 +93,7 @@ function onMouseDown(e) {
if (ctrl && !shift && !alt && button == 0) {
if (ctrl && !alt && !shift && button === 0) {
if (!isMultiSelect && inSelection)
return; // dragging
@ -122,7 +120,7 @@ function onMouseDown(e) {
editor.$blockScrolling--;
});
} else if (alt && button == 0) {
} else if (alt && button === 0) {
e.stop();
if (isMultiSelect && !ctrl)
@ -135,8 +133,7 @@ function onMouseDown(e) {
screenAnchor = session.documentToScreenPosition(selection.lead);
blockSelect();
} else {
selection.moveCursorToPosition(pos);
selection.clearSelection();
selection.moveToPosition(pos);
}

View file

@ -437,6 +437,7 @@ var Editor = require("./editor").Editor;
this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
this.renderer.updateCursor();
this.renderer.updateBackMarkers();
this._emit("changeSelection");
};
this.$onMultiSelectExec = function(e) {
@ -487,9 +488,10 @@ var Editor = require("./editor").Editor;
i--;
}
tmpSel.fromOrientedRange(rangeList.ranges[i]);
tmpSel.id = rangeList.ranges[i].marker;
this.selection = session.selection = tmpSel;
var cmdResult = cmd.exec(this, args || {});
if (!result == undefined)
if (result !== undefined)
result = cmdResult;
tmpSel.toOrientedRange(rangeList.ranges[i]);
}

View file

@ -298,6 +298,27 @@ var Selection = function(session) {
});
};
/**
* Moves the selection cursor to the indicated row and column.
* @param {Number} row The row to select to
* @param {Number} column The column to select to
*
**/
this.moveTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
};
/**
* Moves the selection cursor to the row and column indicated by `pos`.
* @param {Object} pos An object containing the row and column
**/
this.moveToPosition = function(pos) {
this.clearSelection();
this.moveCursorToPosition(pos);
};
/**
*
* Moves the selection up one row.

View file

@ -33,7 +33,6 @@ define(function(require, exports, module) {
var oop = require("./lib/oop");
var dom = require("./lib/dom");
var useragent = require("./lib/useragent");
var config = require("./config");
var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker;
@ -42,6 +41,7 @@ var CursorLayer = require("./layer/cursor").Cursor;
var HScrollBar = require("./scrollbar").HScrollBar;
var VScrollBar = require("./scrollbar").VScrollBar;
var RenderLoop = require("./renderloop").RenderLoop;
var FontMetrics = require("./layer/font_metrics").FontMetrics;
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var editorCss = require("./requirejs/text!./css/editor.css");
@ -125,10 +125,12 @@ var VirtualRenderer = function(container, theme) {
column : 0
};
this.$textLayer.addEventListener("changeCharacterSize", function() {
this.$fontMetrics = new FontMetrics(this.container, 500);
this.$textLayer.$setFontMetrics(this.$fontMetrics);
this.$textLayer.addEventListener("changeCharacterSize", function(e) {
_self.updateCharacterSize();
_self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
_self._signal("changeCharacterSize");
_self._signal("changeCharacterSize", e);
});
this.$size = {
@ -150,7 +152,8 @@ var VirtualRenderer = function(container, theme) {
minHeight : 1,
maxHeight : 1,
offset : 0,
height : 1
height : 1,
gutterOffset: 1
};
this.scrollMargin = {
@ -224,8 +227,13 @@ var VirtualRenderer = function(container, theme) {
* Associates the renderer with an [[EditSession `EditSession`]].
**/
this.setSession = function(session) {
if (this.session)
this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
this.session = session;
if (!session)
return;
if (this.scrollMargin.top && session.getScrollTop() <= 0)
session.setScrollTop(-this.scrollMargin.top);
@ -235,6 +243,11 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL);
this.session.$setFontMetrics(this.$fontMetrics);
this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
this.onChangeNewLineMode()
this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
};
/**
@ -268,6 +281,11 @@ var VirtualRenderer = function(container, theme) {
this.$loop.schedule(this.CHANGE_LINES);
};
this.onChangeNewLineMode = function() {
this.$loop.schedule(this.CHANGE_TEXT);
this.$textLayer.$updateEolChar();
};
this.onChangeTabSize = function() {
this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
this.$textLayer.onChangeTabSize();
@ -702,7 +720,7 @@ var VirtualRenderer = function(container, theme) {
sm.v = sm.top + sm.bottom;
sm.h = sm.left + sm.right;
if (sm.top && this.scrollTop <= 0 && this.session)
this.session.setScrollTop(sm.top);
this.session.setScrollTop(-sm.top);
this.updateFull();
};
@ -984,7 +1002,7 @@ var VirtualRenderer = function(container, theme) {
minHeight : minHeight,
maxHeight : maxHeight,
offset : offset,
gutterOffset : Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight),
gutterOffset : Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)),
height : this.$size.scrollerHeight
};
@ -1605,6 +1623,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
showGutter: {
set: function(show){
this.$gutter.style.display = show ? "block" : "none";
this.$loop.schedule(this.CHANGE_FULL);
this.onGutterResize();
},
initialValue: true

View file

@ -42,7 +42,7 @@ window.normalizeModule = function(parentId, moduleName) {
window.require = function(parentId, id) {
if (!id) {
id = parentId
id = parentId;
parentId = null;
}
if (!id.charAt)
@ -81,14 +81,14 @@ window.define = function(id, deps, factory) {
}
} else if (arguments.length == 1) {
factory = id;
deps = []
deps = [];
id = window.require.id;
}
if (!deps.length)
// If there is no dependencies, we inject 'require', 'exports' and
// 'module' as dependencies, to provide CommonJS compatibility.
deps = ['require', 'exports', 'module']
deps = ['require', 'exports', 'module'];
if (id.indexOf("text!") === 0)
return;
@ -105,12 +105,12 @@ window.define = function(id, deps, factory) {
switch(dep) {
// Because 'require', 'exports' and 'module' aren't actual
// dependencies, we must handle them seperately.
case 'require': return req
case 'exports': return module.exports
case 'module': return module
case 'require': return req;
case 'exports': return module.exports;
case 'module': return module;
// But for all other dependencies, we can just go ahead and
// require them.
default: return req(dep)
default: return req(dep);
}
}));
if (returnExports)
@ -119,11 +119,11 @@ window.define = function(id, deps, factory) {
}
};
};
window.define.amd = {}
window.define.amd = {};
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
require.tlns = topLevelNamespaces;
}
};
window.initSender = function initSender() {
@ -155,10 +155,10 @@ window.initSender = function initSender() {
}).call(Sender.prototype);
return new Sender();
}
};
window.main = null;
window.sender = null;
var main = window.main = null;
var sender = window.sender = null;
window.onmessage = function(e) {
var msg = e.data;
@ -171,9 +171,9 @@ window.onmessage = function(e) {
else if (msg.init) {
initBaseUrls(msg.tlns);
require("ace/lib/es5-shim");
sender = initSender();
sender = window.sender = initSender();
var clazz = require(msg.module)[msg.classname];
main = new clazz(sender);
main = window.main = new clazz(sender);
}
else if (msg.event && sender) {
sender._signal(msg.event, msg.data);

View file

@ -179,16 +179,15 @@ var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) {
};
this.$workerBlob = function(workerUrl) {
var script = 'importScripts("' + workerUrl + '");';
var script = "importScripts('" + workerUrl + "');";
try {
var blob = new Blob([script], {'type': 'application/javascript'});
return new Blob([script], {"type": "application/javascript"});
} catch (e) { // Backwards-compatibility
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
var blobBuilder = new BlobBuilder();
blobBuilder.append(script);
blob = blobBuilder.getBlob('application/javascript');
return blobBuilder.getBlob("application/javascript");
}
return blob;
};
}).call(WorkerClient.prototype);
@ -202,6 +201,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.messageBuffer = [];
var main = null;
var emitSync = false;
var sender = Object.create(EventEmitter);
var _self = this;
@ -209,8 +209,14 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.$worker.terminate = function() {};
this.$worker.postMessage = function(e) {
_self.messageBuffer.push(e);
main && setTimeout(processNext);
if (main) {
if (emitSync)
setTimeout(processNext);
else
processNext();
}
};
this.setEmitSync = function(val) { emitSync = val };
var processNext = function() {
var msg = _self.messageBuffer.shift();