Merge pull request #1570 from ajaxorg/papercuts
Small improvements to the api
This commit is contained in:
commit
dbff7216f0
10 changed files with 410 additions and 248 deletions
|
|
@ -402,6 +402,8 @@ var Document = function(text) {
|
|||
*
|
||||
**/
|
||||
this.remove = function(range) {
|
||||
if (!range instanceof Range)
|
||||
range = Range.fromPoints(range.start, range.end);
|
||||
// clip to document
|
||||
range.start = this.$clipPosition(range.start);
|
||||
range.end = this.$clipPosition(range.end);
|
||||
|
|
@ -520,6 +522,8 @@ var Document = function(text) {
|
|||
*
|
||||
**/
|
||||
this.replace = function(range, text) {
|
||||
if (!range instanceof Range)
|
||||
range = Range.fromPoints(range.start, range.end);
|
||||
if (text.length == 0 && range.isEmpty())
|
||||
return range.start;
|
||||
|
||||
|
|
|
|||
|
|
@ -739,25 +739,29 @@ var Editor = function(renderer, session) {
|
|||
this.renderer.updateFull();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the string of text currently highlighted.
|
||||
* @returns {String}
|
||||
**/
|
||||
this.getSelectedText = function() {
|
||||
return this.session.getTextRange(this.getSelectionRange());
|
||||
};
|
||||
|
||||
/**
|
||||
* Emitted when text is copied.
|
||||
* @event copy
|
||||
* @param {String} text The copied text
|
||||
*
|
||||
*
|
||||
**/
|
||||
/**
|
||||
*
|
||||
* Returns the string of text currently highlighted.
|
||||
* @returns {String}
|
||||
* @deprecated Use getSelectedText instead.
|
||||
**/
|
||||
|
||||
this.getCopyText = function() {
|
||||
var text = "";
|
||||
if (!this.selection.isEmpty())
|
||||
text = this.session.getTextRange(this.getSelectionRange());
|
||||
|
||||
this._emit("copy", text);
|
||||
var text = this.getSelectedText();
|
||||
this._signal("copy", text);
|
||||
return text;
|
||||
};
|
||||
|
||||
|
|
@ -2386,6 +2390,7 @@ config.defineOptions(Editor.prototype, "editor", {
|
|||
maxLines: "renderer",
|
||||
minLines: "renderer",
|
||||
scrollPastEnd: "renderer",
|
||||
fixedWidthGutter: "renderer",
|
||||
|
||||
scrollSpeed: "$mouseHandler",
|
||||
dragDelay: "$mouseHandler",
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ var Gutter = function(parentEl) {
|
|||
this.element = dom.setInnerHtml(this.element, html.join(""));
|
||||
this.element.style.height = config.minHeight + "px";
|
||||
|
||||
if (this.session.$useWrapMode)
|
||||
if (this.$fixedWidth || this.session.$useWrapMode)
|
||||
lastLineNumber = this.session.getLength();
|
||||
|
||||
var gutterWidth = ("" + lastLineNumber).length * config.characterWidth;
|
||||
|
|
@ -181,6 +181,8 @@ var Gutter = function(parentEl) {
|
|||
}
|
||||
};
|
||||
|
||||
this.$fixedWidth = false;
|
||||
|
||||
this.$showFoldWidgets = true;
|
||||
this.setShowFoldWidgets = function(show) {
|
||||
if (show)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
define(function(require, exports, module) {
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
|
||||
var buildLocationData, extend, flatten, last, repeat, _ref;
|
||||
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
|
||||
|
||||
exports.starts = function(string, literal, start) {
|
||||
return literal === string.substr(start, literal.length);
|
||||
|
|
@ -223,30 +223,48 @@ define(function(require, exports, module) {
|
|||
}
|
||||
error = new SyntaxError(message);
|
||||
error.location = location;
|
||||
error.toString = syntaxErrorToString;
|
||||
error.stack = error.toString();
|
||||
throw error;
|
||||
};
|
||||
|
||||
exports.prettyErrorMessage = function(error, filename, code, useColors) {
|
||||
var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;
|
||||
if (!error.location) {
|
||||
return error.stack || ("" + error);
|
||||
exports.updateSyntaxError = function(error, code, filename) {
|
||||
if (error.toString === syntaxErrorToString) {
|
||||
error.code || (error.code = code);
|
||||
error.filename || (error.filename = filename);
|
||||
error.stack = error.toString();
|
||||
}
|
||||
filename = error.filename || filename;
|
||||
code = error.code || code;
|
||||
_ref1 = error.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
|
||||
codeLine = code.split('\n')[first_line];
|
||||
return error;
|
||||
};
|
||||
|
||||
syntaxErrorToString = function() {
|
||||
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
|
||||
if (!(this.code && this.location)) {
|
||||
return Error.prototype.toString.call(this);
|
||||
}
|
||||
_ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
|
||||
if (last_line == null) {
|
||||
last_line = first_line;
|
||||
}
|
||||
if (last_column == null) {
|
||||
last_column = first_column;
|
||||
}
|
||||
filename = this.filename || '[stdin]';
|
||||
codeLine = this.code.split('\n')[first_line];
|
||||
start = first_column;
|
||||
end = first_line === last_line ? last_column + 1 : codeLine.length;
|
||||
marker = repeat(' ', start) + repeat('^', end - start);
|
||||
if (useColors) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
|
||||
}
|
||||
if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
|
||||
colorize = function(str) {
|
||||
return "\x1B[1;31m" + str + "\x1B[0m";
|
||||
};
|
||||
codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
|
||||
marker = colorize(marker);
|
||||
}
|
||||
message = "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + error.message + "\n" + codeLine + "\n" + marker;
|
||||
return message;
|
||||
return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ define(function(require, exports, module) {
|
|||
}
|
||||
this.literate = opts.literate;
|
||||
this.indent = 0;
|
||||
this.baseIndent = 0;
|
||||
this.indebt = 0;
|
||||
this.outdebt = 0;
|
||||
this.indents = [];
|
||||
|
|
@ -373,11 +374,17 @@ define(function(require, exports, module) {
|
|||
this.suppressNewlines();
|
||||
return indent.length;
|
||||
}
|
||||
if (!this.tokens.length) {
|
||||
this.baseIndent = this.indent = size;
|
||||
return indent.length;
|
||||
}
|
||||
diff = size - this.indent + this.outdebt;
|
||||
this.token('INDENT', diff, indent.length - size, size);
|
||||
this.indents.push(diff);
|
||||
this.ends.push('OUTDENT');
|
||||
this.outdebt = this.indebt = 0;
|
||||
} else if (size < this.baseIndent) {
|
||||
this.error('missing indentation', indent.length);
|
||||
} else {
|
||||
this.indebt = 0;
|
||||
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
||||
|
|
@ -801,10 +808,15 @@ define(function(require, exports, module) {
|
|||
return quote + this.escapeLines(body, heredoc) + quote;
|
||||
};
|
||||
|
||||
Lexer.prototype.error = function(message) {
|
||||
Lexer.prototype.error = function(message, offset) {
|
||||
var first_column, first_line, _ref2;
|
||||
if (offset == null) {
|
||||
offset = 0;
|
||||
}
|
||||
_ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
|
||||
return throwSyntaxError(message, {
|
||||
first_line: this.chunkLine,
|
||||
first_column: this.chunkColumn
|
||||
first_line: first_line,
|
||||
first_column: first_column
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -256,7 +256,10 @@ define(function(require, exports, module) {
|
|||
Base.prototype.assigns = NO;
|
||||
|
||||
Base.prototype.updateLocationDataIfMissing = function(locationData) {
|
||||
this.locationData || (this.locationData = locationData);
|
||||
if (this.locationData) {
|
||||
return this;
|
||||
}
|
||||
this.locationData = locationData;
|
||||
return this.eachChild(function(child) {
|
||||
return child.updateLocationDataIfMissing(locationData);
|
||||
});
|
||||
|
|
@ -849,11 +852,11 @@ define(function(require, exports, module) {
|
|||
|
||||
Comment.prototype.compileNode = function(o, level) {
|
||||
var code;
|
||||
code = "/*" + (multident(this.comment, this.tab)) + (__indexOf.call(this.comment, '\n') >= 0 ? "\n" + this.tab : '') + "*/\n";
|
||||
code = "/*" + (multident(this.comment, this.tab)) + (__indexOf.call(this.comment, '\n') >= 0 ? "\n" + this.tab : '') + "*/";
|
||||
if ((level || o.level) === LEVEL_TOP) {
|
||||
code = o.indent + code;
|
||||
}
|
||||
return [this.makeCode(code)];
|
||||
return [this.makeCode("\n"), this.makeCode(code)];
|
||||
};
|
||||
|
||||
return Comment;
|
||||
|
|
@ -2879,6 +2882,7 @@ define(function(require, exports, module) {
|
|||
} else {
|
||||
this.isChain = elseBody instanceof If;
|
||||
this.elseBody = this.ensureBlock(elseBody);
|
||||
this.elseBody.updateLocationDataIfMissing(elseBody.locationData);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -72,7 +72,7 @@ module.exports = {
|
|||
"test unexpected indent": function() {
|
||||
var e = parse("a\n a\n");
|
||||
assert.equal(e.message, "Unexpected 'INDENT'");
|
||||
assertLocation(e, 0, 0, 0, 0);
|
||||
assertLocation(e, 1, 0, 1, 1);
|
||||
},
|
||||
"test invalid destructuring": function() {
|
||||
var e = parse("\n{b: 5} = {}");
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ var Editor = require("./editor").Editor;
|
|||
this.multiSelect.toSingleRange();
|
||||
};
|
||||
|
||||
this.getCopyText = function() {
|
||||
this.getSelectedText = function() {
|
||||
var text = "";
|
||||
if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
|
||||
var ranges = this.multiSelect.rangeList.ranges;
|
||||
|
|
@ -534,7 +534,6 @@ var Editor = require("./editor").Editor;
|
|||
} else if (!this.selection.isEmpty()) {
|
||||
text = this.session.getTextRange(this.getSelectionRange());
|
||||
}
|
||||
this._signal("copy", text);
|
||||
return text;
|
||||
};
|
||||
|
||||
|
|
@ -887,24 +886,25 @@ function MultiSelect(editor) {
|
|||
function addAltCursorListeners(editor){
|
||||
var el = editor.textInput.getElement();
|
||||
var altCursor = false;
|
||||
var contentEl = editor.renderer.content;
|
||||
event.addListener(el, "keydown", function(e) {
|
||||
if (e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey)) {
|
||||
if (!altCursor) {
|
||||
contentEl.style.cursor = "crosshair";
|
||||
editor.renderer.setMouseCursor("crosshair");
|
||||
altCursor = true;
|
||||
}
|
||||
} else if (altCursor) {
|
||||
contentEl.style.cursor = "";
|
||||
reset();
|
||||
}
|
||||
});
|
||||
|
||||
event.addListener(el, "keyup", reset);
|
||||
event.addListener(el, "blur", reset);
|
||||
function reset() {
|
||||
function reset(e) {
|
||||
if (altCursor) {
|
||||
contentEl.style.cursor = "";
|
||||
editor.renderer.setMouseCursor("");
|
||||
altCursor = false;
|
||||
// TODO disable menu poping up
|
||||
// e && e.preventDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1292,12 +1292,20 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.$loop.schedule(this.CHANGE_H_SCROLL);
|
||||
};
|
||||
|
||||
/**
|
||||
* Scrolls the editor across both x- and y-axes.
|
||||
* @param {Number} x The x value to scroll to
|
||||
* @param {Number} y The y value to scroll to
|
||||
**/
|
||||
this.scrollTo = function(x, y) {
|
||||
this.session.setScrollTop(y);
|
||||
this.session.setScrollLeft(y);
|
||||
};
|
||||
|
||||
/**
|
||||
* Scrolls the editor across both x- and y-axes.
|
||||
* @param {Number} deltaX The x value to scroll by
|
||||
* @param {Number} deltaY The y value to scroll by
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.scrollBy = function(deltaX, deltaY) {
|
||||
deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
|
||||
|
|
@ -1496,9 +1504,8 @@ var VirtualRenderer = function(container, theme) {
|
|||
* [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle}
|
||||
* @param {String} style A class name
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setStyle = function setStyle(style, include) {
|
||||
this.setStyle = function(style, include) {
|
||||
dom.setCssClass(this.container, style, include != false);
|
||||
};
|
||||
|
||||
|
|
@ -1506,14 +1513,20 @@ var VirtualRenderer = function(container, theme) {
|
|||
* [Removes the class `style` from the editor.]{: #VirtualRenderer.unsetStyle}
|
||||
* @param {String} style A class name
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.unsetStyle = function unsetStyle(style) {
|
||||
this.unsetStyle = function(style) {
|
||||
dom.removeCssClass(this.container, style);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} cursorStyle A css cursor style
|
||||
*
|
||||
**/
|
||||
this.setMouseCursor = function(cursorStyle) {
|
||||
this.content.style.cursor = cursorStyle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the text and cursor layers for this renderer.
|
||||
**/
|
||||
this.destroy = function() {
|
||||
|
|
@ -1642,6 +1655,12 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
|
|||
},
|
||||
initialValue: 0,
|
||||
handlesSet: true
|
||||
},
|
||||
fixedWidthGutter: {
|
||||
set: function(val) {
|
||||
this.gutterLayer.fixedWidth = !!val;
|
||||
this.$loop.schedule(this.CHANGE_GUTTER);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue