This commit is contained in:
nightwing 2014-02-15 12:33:54 +04:00
commit 6e9c9417fc
9 changed files with 62 additions and 56 deletions

View file

@ -470,7 +470,7 @@ var EditSession = function(text, mode) {
* @param {Number} tabSize The new tab size * @param {Number} tabSize The new tab size
**/ **/
this.setTabSize = function(tabSize) { this.setTabSize = function(tabSize) {
this.setOption("tabSize", tabSize) this.setOption("tabSize", tabSize);
}; };
/** /**
* Returns the current tab size. * Returns the current tab size.
@ -486,7 +486,7 @@ var EditSession = function(text, mode) {
* *
**/ **/
this.isTabStop = function(position) { this.isTabStop = function(position) {
return this.$useSoftTabs && (position.column % this.$tabSize == 0); return this.$useSoftTabs && (position.column % this.$tabSize === 0);
}; };
this.$overwrite = false; this.$overwrite = false;
@ -500,7 +500,7 @@ var EditSession = function(text, mode) {
* *
**/ **/
this.setOverwrite = function(overwrite) { this.setOverwrite = function(overwrite) {
this.setOption("overwrite", overwrite) this.setOption("overwrite", overwrite);
}; };
/** /**
@ -622,14 +622,14 @@ var EditSession = function(text, mode) {
clazz : clazz, clazz : clazz,
inFront: !!inFront, inFront: !!inFront,
id: id id: id
} };
if (inFront) { if (inFront) {
this.$frontMarkers[id] = marker; this.$frontMarkers[id] = marker;
this._signal("changeFrontMarker") this._signal("changeFrontMarker");
} else { } else {
this.$backMarkers[id] = marker; this.$backMarkers[id] = marker;
this._signal("changeBackMarker") this._signal("changeBackMarker");
} }
return id; return id;
@ -652,10 +652,10 @@ var EditSession = function(text, mode) {
if (inFront) { if (inFront) {
this.$frontMarkers[id] = marker; this.$frontMarkers[id] = marker;
this._signal("changeFrontMarker") this._signal("changeFrontMarker");
} else { } else {
this.$backMarkers[id] = marker; this.$backMarkers[id] = marker;
this._signal("changeBackMarker") this._signal("changeBackMarker");
} }
return marker; return marker;
@ -1043,14 +1043,14 @@ var EditSession = function(text, mode) {
}; };
this.getLineWidgetMaxWidth = function() { this.getLineWidgetMaxWidth = function() {
if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
var width = 0; var width = 0;
this.lineWidgets.forEach(function(w) { this.lineWidgets.forEach(function(w) {
if (w && w.screenWidth > width) if (w && w.screenWidth > width)
width = w.screenWidth; width = w.screenWidth;
}); });
return this.lineWidgetWidth = width; return this.lineWidgetWidth = width;
} };
this.$computeWidth = function(force) { this.$computeWidth = function(force) {
if (this.$modified || 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. // Check if this range and the last undo range has something in common.
// If true, merge the ranges. // If true, merge the ranges.
if (lastUndoRange != null) { 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.start.column += range.end.column - range.start.column;
lastUndoRange.end.column += range.end.column - range.start.column; lastUndoRange.end.column += range.end.column - range.start.column;
} }

View file

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

View file

@ -120,7 +120,8 @@ var Gutter = function(parentEl) {
this.update = function(config) { this.update = function(config) {
var session = this.session; var session = this.session;
var firstRow = config.firstRow; 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 fold = session.getNextFoldLine(firstRow);
var foldStart = fold ? fold.start.row : Infinity; var foldStart = fold ? fold.start.row : Infinity;
var foldWidgets = this.$showFoldWidgets && session.foldWidgets; var foldWidgets = this.$showFoldWidgets && session.foldWidgets;

View file

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

View file

@ -51,7 +51,7 @@ function onMouseDown(e) {
} }
if (!ctrl && !alt) { if (!ctrl && !alt) {
if (button == 0 && e.editor.inMultiSelectMode) if (button === 0 && e.editor.inMultiSelectMode)
e.editor.exitMultiSelectMode(); e.editor.exitMultiSelectMode();
return; return;
} }

View file

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

View file

@ -33,7 +33,6 @@ define(function(require, exports, module) {
var oop = require("./lib/oop"); var oop = require("./lib/oop");
var dom = require("./lib/dom"); var dom = require("./lib/dom");
var useragent = require("./lib/useragent");
var config = require("./config"); var config = require("./config");
var GutterLayer = require("./layer/gutter").Gutter; var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker; var MarkerLayer = require("./layer/marker").Marker;
@ -153,7 +152,8 @@ var VirtualRenderer = function(container, theme) {
minHeight : 1, minHeight : 1,
maxHeight : 1, maxHeight : 1,
offset : 0, offset : 0,
height : 1 height : 1,
gutterOffset: 1
}; };
this.scrollMargin = { this.scrollMargin = {

View file

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

View file

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