pull/483/head
nightwing 2018-01-23 18:59:33 +04:00
rodzic 718f53d835
commit db4123e4f8
20 zmienionych plików z 277 dodań i 269 usunięć

6
plugins/node_modules/ace/lib/ace/ace.js wygenerowano vendored
Wyświetl plik

@ -71,9 +71,10 @@ if (typeof define === "function")
/** /**
* Embeds the Ace editor into the DOM, at the element provided by `el`. * Embeds the Ace editor into the DOM, at the element provided by `el`.
* @param {String | DOMElement} el Either the id of an element, or the element itself * @param {String | DOMElement} el Either the id of an element, or the element itself
* @param {Object } options Options for the editor
* *
**/ **/
exports.edit = function(el) { exports.edit = function(el, options) {
if (typeof el == "string") { if (typeof el == "string") {
var _id = el; var _id = el;
el = document.getElementById(_id); el = document.getElementById(_id);
@ -97,8 +98,7 @@ exports.edit = function(el) {
var doc = exports.createEditSession(value); var doc = exports.createEditSession(value);
var editor = new Editor(new Renderer(el)); var editor = new Editor(new Renderer(el), doc, options);
editor.setSession(doc);
var env = { var env = {
document: doc, document: doc,

Wyświetl plik

@ -22,8 +22,6 @@
.ace_content { .ace_content {
position: absolute; position: absolute;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
min-width: 100%; min-width: 100%;
} }
@ -151,7 +149,6 @@
/*with `pre-line` chrome inserts   instead of space*/ /*with `pre-line` chrome inserts   instead of space*/
white-space: pre!important; white-space: pre!important;
} }
.ace_text-input.ace_composition { .ace_text-input.ace_composition {
background: inherit; background: inherit;
color: inherit; color: inherit;
@ -159,6 +156,17 @@
opacity: 1; opacity: 1;
text-indent: 0; text-indent: 0;
} }
[ace_nocontext=true] {
transform: none!important;
filter: none!important;
perspective: none!important;
clip-path: none!important;
mask : none!important;
contain: none!important;
perspective: none!important;
mix-blend-mode: initial!important;
z-index: auto;
}
.ace_layer { .ace_layer {
z-index: 1; z-index: 1;
@ -169,8 +177,6 @@
white-space: pre; white-space: pre;
height: 100%; height: 100%;
width: 100%; width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
/* setting pointer-events: auto; on node under the mouse, which changes /* setting pointer-events: auto; on node under the mouse, which changes
during scroll, will break mouse wheel scrolling in Safari */ during scroll, will break mouse wheel scrolling in Safari */
@ -200,8 +206,6 @@
.ace_cursor { .ace_cursor {
z-index: 4; z-index: 4;
position: absolute; position: absolute;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
border-left: 2px solid; border-left: 2px solid;
/* workaround for smooth cursor repaintng whole screen in chrome */ /* workaround for smooth cursor repaintng whole screen in chrome */
@ -226,8 +230,7 @@
} }
.ace_smooth-blinking .ace_cursor { .ace_smooth-blinking .ace_cursor {
-webkit-transition: opacity 0.18s; transition: opacity 0.18s;
transition: opacity 0.18s;
} }
.ace_marker-layer .ace_step, .ace_marker-layer .ace_stack { .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {
@ -253,14 +256,10 @@
.ace_marker-layer .ace_selected-word { .ace_marker-layer .ace_selected-word {
position: absolute; position: absolute;
z-index: 4; z-index: 4;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
} }
.ace_line .ace_fold { .ace_line .ace_fold {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
display: inline-block; display: inline-block;
@ -293,7 +292,6 @@
.ace_tooltip { .ace_tooltip {
background-color: #FFF; background-color: #FFF;
background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));
background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1)); background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));
border: 1px solid gray; border: 1px solid gray;
border-radius: 1px; border-radius: 1px;
@ -303,8 +301,6 @@
padding: 3px 4px; padding: 3px 4px;
position: fixed; position: fixed;
z-index: 999999; z-index: 999999;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
cursor: default; cursor: default;
white-space: pre; white-space: pre;
@ -321,8 +317,6 @@
} }
.ace_fold-widget { .ace_fold-widget {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
margin: 0 -12px 0 1px; margin: 0 -12px 0 1px;
@ -383,20 +377,33 @@
box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2); box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);
} }
.ace_inline_button {
border: 1px solid lightgray;
display: inline-block;
margin: -1px 8px;
padding: 0 5px;
pointer-events: auto;
cursor: pointer;
}
.ace_inline_button:hover {
border-color: gray;
background: rgba(200,200,200,0.2);
display: inline-block;
pointer-events: auto;
}
.ace_fold-widget.ace_invalid { .ace_fold-widget.ace_invalid {
background-color: #FFB4B4; background-color: #FFB4B4;
border-color: #DE5555; border-color: #DE5555;
} }
.ace_fade-fold-widgets .ace_fold-widget { .ace_fade-fold-widgets .ace_fold-widget {
-webkit-transition: opacity 0.4s ease 0.05s; transition: opacity 0.4s ease 0.05s;
transition: opacity 0.4s ease 0.05s;
opacity: 0; opacity: 0;
} }
.ace_fade-fold-widgets:hover .ace_fold-widget { .ace_fade-fold-widgets:hover .ace_fold-widget {
-webkit-transition: opacity 0.05s ease 0.05s; transition: opacity 0.05s ease 0.05s;
transition: opacity 0.05s ease 0.05s;
opacity:1; opacity:1;
} }
@ -461,7 +468,7 @@ styles.join("\n")
.ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;} .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
.ace_text-input-ios { .ace_text-input-ios {
position: absolute !important; position: absolute !important;
top: -100000px !important; top: -100000px !important;
left: -100000px !important; left: -100000px !important;
} }

Wyświetl plik

@ -70,7 +70,7 @@ var clipboard = require("./clipboard");
* *
* @constructor * @constructor
**/ **/
var Editor = function(renderer, session) { var Editor = function(renderer, session, options) {
var container = renderer.getContainerElement(); var container = renderer.getContainerElement();
this.container = container; this.container = container;
this.renderer = renderer; this.renderer = renderer;
@ -78,7 +78,7 @@ var Editor = function(renderer, session) {
this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
if (typeof document == "object") { if (typeof document == "object") {
this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
this.renderer.textarea = this.textInput.getElement(); this.renderer.textarea = this.textInput.getElement();
// TODO detect touch event support // TODO detect touch event support
this.$mouseHandler = new MouseHandler(this); this.$mouseHandler = new MouseHandler(this);
@ -106,8 +106,10 @@ var Editor = function(renderer, session) {
_self._$emitInputEvent.schedule(31); _self._$emitInputEvent.schedule(31);
}); });
this.setSession(session || new EditSession("")); this.setSession(session || options && options.session || new EditSession(""));
config.resetOptions(this); config.resetOptions(this);
if (options)
this.setOptions(options);
config._signal("editor", this); config._signal("editor", this);
}; };
@ -638,13 +640,6 @@ Editor.$uid = 0;
* Brings the current `textInput` into focus. * Brings the current `textInput` into focus.
**/ **/
this.focus = function() { this.focus = function() {
// Safari needs the timeout
// iOS and Firefox need it called immediately
// to be on the save side we do both
var _self = this;
setTimeout(function() {
_self.textInput.focus();
});
this.textInput.focus(); this.textInput.focus();
}; };
@ -806,7 +801,9 @@ Editor.$uid = 0;
var line = session.getLine(selection.start.row); var line = session.getLine(selection.start.row);
var needle = line.substring(startColumn, endColumn); var needle = line.substring(startColumn, endColumn);
if (!/[\w\d]/.test(needle)) // maximum allowed size for regular expressions in 32000,
// but getting close to it has significant impact on the performance
if (needle.length > 5000 || !/[\w\d]/.test(needle))
return; return;
var re = this.$search.$assembleRegExp({ var re = this.$search.$assembleRegExp({
@ -2672,9 +2669,21 @@ config.defineOptions(Editor.prototype, "editor", {
}, },
keyboardHandler: { keyboardHandler: {
set: function(val) { this.setKeyboardHandler(val); }, set: function(val) { this.setKeyboardHandler(val); },
get: function() { return this.keybindingId; }, get: function() { return this.$keybindingId; },
handlesSet: true handlesSet: true
}, },
value: {
set: function(val) { this.session.setValue(val); },
get: function() { return this.getValue(); },
handlesSet: true,
hidden: true
},
session: {
set: function(val) { this.setSession(val); },
get: function() { return this.session; },
handlesSet: true,
hidden: true
},
hScrollBarAlwaysVisible: "renderer", hScrollBarAlwaysVisible: "renderer",
vScrollBarAlwaysVisible: "renderer", vScrollBarAlwaysVisible: "renderer",

Wyświetl plik

@ -179,7 +179,6 @@ exports.transform = function(iterator, maxPos, context) {
var value = ''; var value = '';
while (token!==null) { while (token!==null) {
console.log(token);
if( !token ){ if( !token ){
token = iterator.stepForward(); token = iterator.stepForward();
@ -363,4 +362,4 @@ exports.transform = function(iterator, maxPos, context) {
}); });

Wyświetl plik

@ -15,7 +15,8 @@ module.exports = {
timeout: 10000, timeout: 10000,
"test loading in node": function(next) { "test loading in node": function(next) {
assert.equal(typeof window, "undefined"); if (typeof process != "undefined")
assert.equal(typeof window, "undefined");
require("../ace"); require("../ace");
next(); next();
}, },

Wyświetl plik

@ -273,8 +273,6 @@ dom.importCssString && dom.importCssString("\
.ace_marker-layer .ace_isearch-result {\ .ace_marker-layer .ace_isearch-result {\
position: absolute;\ position: absolute;\
z-index: 6;\ z-index: 6;\
-moz-box-sizing: border-box;\
-webkit-box-sizing: border-box;\
box-sizing: border-box;\ box-sizing: border-box;\
}\ }\
div.ace_isearch-result {\ div.ace_isearch-result {\

Wyświetl plik

@ -65,8 +65,6 @@ exports.handler.attach = function(editor) {
dom.importCssString('\ dom.importCssString('\
.emacs-mode .ace_cursor{\ .emacs-mode .ace_cursor{\
border: 1px rgba(50,250,50,0.8) solid!important;\ border: 1px rgba(50,250,50,0.8) solid!important;\
-moz-box-sizing: border-box!important;\
-webkit-box-sizing: border-box!important;\
box-sizing: border-box!important;\ box-sizing: border-box!important;\
background-color: rgba(0,250,0,0.9);\ background-color: rgba(0,250,0,0.9);\
opacity: 0.5;\ opacity: 0.5;\

Wyświetl plik

@ -37,6 +37,7 @@ var dom = require("../lib/dom");
var lang = require("../lib/lang"); var lang = require("../lib/lang");
var BROKEN_SETDATA = useragent.isChrome < 18; var BROKEN_SETDATA = useragent.isChrome < 18;
var USE_IE_MIME_TYPE = useragent.isIE; var USE_IE_MIME_TYPE = useragent.isIE;
var HAS_FOCUS_ARGS = useragent.isChrome > 63;
var TextInputIOS = require("./textinput_ios").TextInput; var TextInputIOS = require("./textinput_ios").TextInput;
var TextInput = function(parentNode, host) { var TextInput = function(parentNode, host) {
@ -76,12 +77,29 @@ var TextInput = function(parentNode, host) {
host.onFocus(e); host.onFocus(e);
resetSelection(); resetSelection();
}); });
this.$focusScroll = false;
this.focus = function() { this.focus = function() {
if (tempStyle) return text.focus(); if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
return text.focus({ preventScroll: true });
var top = text.style.top; var top = text.style.top;
text.style.position = "fixed"; text.style.position = "fixed";
text.style.top = "0px"; text.style.top = "0px";
text.focus(); var isTransformed = text.getBoundingClientRect().top != 0;
var ancestors = [];
if (isTransformed) {
var t = text.parentElement;
while (t) {
ancestors.push(t);
t.setAttribute("ace_nocontext", true);
t = t.parentElement;
}
}
text.focus({ preventScroll: true });
if (isTransformed) {
ancestors.forEach(function(p) {
p.removeAttribute("ace_nocontext");
});
}
setTimeout(function() { setTimeout(function() {
text.style.position = ""; text.style.position = "";
if (text.style.top == "0px") if (text.style.top == "0px")

Wyświetl plik

@ -55,6 +55,7 @@ var Text = function(parentEl) {
this.TAB_CHAR = "\u2014"; //"\u21E5"; this.TAB_CHAR = "\u2014"; //"\u21E5";
this.SPACE_CHAR = "\xB7"; this.SPACE_CHAR = "\xB7";
this.$padding = 0; this.$padding = 0;
this.MAX_LINE_LENGTH = 10000;
this.$updateEolChar = function() { this.$updateEolChar = function() {
var doc = this.session.doc; var doc = this.session.doc;
@ -449,9 +450,19 @@ var Text = function(parentEl) {
for (var i = 1; i < tokens.length; i++) { for (var i = 1; i < tokens.length; i++) {
token = tokens[i]; token = tokens[i];
value = token.value; value = token.value;
if (screenColumn + value.length > this.MAX_LINE_LENGTH)
return this.$renderOverflowMessage(stringBuilder, screenColumn, token, value);
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value); screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
} }
}; };
this.$renderOverflowMessage = function(stringBuilder, screenColumn, token, value) {
this.$renderToken(stringBuilder, screenColumn, token,
value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
stringBuilder.push(
"<span class='ace_inline_button ace_keyword ace_toggle_wrap'>&lt;click to see more...&gt;</span>"
);
};
// row is either first row of foldline or not in fold // row is either first row of foldline or not in fold
this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) { this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {

Wyświetl plik

@ -43,7 +43,10 @@ var optionsProvider = {
getOptions: function(optionNames) { getOptions: function(optionNames) {
var result = {}; var result = {};
if (!optionNames) { if (!optionNames) {
optionNames = Object.keys(this.$options); var options = this.$options;
optionNames = Object.keys(options).filter(function(key) {
return !options[key].hidden;
});
} else if (!Array.isArray(optionNames)) { } else if (!Array.isArray(optionNames)) {
result = optionNames; result = optionNames;
optionNames = Object.keys(result); optionNames = Object.keys(result);

Wyświetl plik

@ -177,6 +177,8 @@ define(function(require, exports, module) {
} else { } else {
break; break;
} }
} else if (ch == "\n" || ch == "\r") {
break;
} else { } else {
string += ch; string += ch;
} }

Wyświetl plik

@ -1702,7 +1702,7 @@ var functionMap = {
], ],
"enchant_broker_dict_exists": [ "enchant_broker_dict_exists": [
"bool enchant_broker_dict_exists(resource broker, string tag)", "bool enchant_broker_dict_exists(resource broker, string tag)",
"Wether a dictionary exists or not. Using non-empty tag" "Whether a dictionary exists or not. Using non-empty tag"
], ],
"enchant_broker_free": [ "enchant_broker_free": [
"boolean enchant_broker_free(resource broker)", "boolean enchant_broker_free(resource broker)",
@ -4702,7 +4702,7 @@ var functionMap = {
], ],
"msg_queue_exists": [ "msg_queue_exists": [
"bool msg_queue_exists(int key)", "bool msg_queue_exists(int key)",
"Check wether a message queue exists" "Check whether a message queue exists"
], ],
"msg_receive": [ "msg_receive": [
"mixed msg_receive(resource queue, int desiredmsgtype, int &msgtype, int maxsize, mixed message [, bool unserialize=true [, int flags=0 [, int errorcode]]])", "mixed msg_receive(resource queue, int desiredmsgtype, int &msgtype, int maxsize, mixed message [, bool unserialize=true [, int flags=0 [, int errorcode]]])",
@ -8190,7 +8190,7 @@ var functionMap = {
], ],
"stream_supports_lock": [ "stream_supports_lock": [
"bool stream_supports_lock(resource stream)", "bool stream_supports_lock(resource stream)",
"Tells wether the stream supports locking through flock()." "Tells whether the stream supports locking through flock()."
], ],
"stream_wrapper_register": [ "stream_wrapper_register": [
"bool stream_wrapper_register(string protocol, string classname[, integer flags])", "bool stream_wrapper_register(string protocol, string classname[, integer flags])",

Wyświetl plik

@ -250,8 +250,8 @@ function DefaultHandlers(mouseHandler) {
var prevScroll = this.$lastScroll; var prevScroll = this.$lastScroll;
var t = ev.domEvent.timeStamp; var t = ev.domEvent.timeStamp;
var dt = t - prevScroll.t; var dt = t - prevScroll.t;
var vx = ev.wheelX / dt; var vx = dt ? ev.wheelX / dt : prevScroll.vx;
var vy = ev.wheelY / dt; var vy = dt ? ev.wheelY / dt : prevScroll.vy;
// touchbar keeps sending scroll events after touchend, if we do not stop these events, // touchbar keeps sending scroll events after touchend, if we do not stop these events,
// users can't scrol editor without scrolling the parent node // users can't scrol editor without scrolling the parent node

Wyświetl plik

@ -30,6 +30,7 @@
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict"; "use strict";
var dom = require("../lib/dom");
function FoldHandler(editor) { function FoldHandler(editor) {
@ -47,6 +48,14 @@ function FoldHandler(editor) {
e.stop(); e.stop();
} }
var target = e.domEvent && e.domEvent.target;
if (target && dom.hasCssClass(target, "ace_inline_button")) {
if (dom.hasCssClass(target, "ace_toggle_wrap")) {
session.setOption("wrap", true);
editor.renderer.scrollCursorIntoView();
}
}
}); });
editor.on("gutterclick", function(e) { editor.on("gutterclick", function(e) {

Wyświetl plik

@ -256,8 +256,8 @@ var EditSession = require("./edit_session").EditSession;
this.toSingleRange(); this.toSingleRange();
this.setSelectionRange(range, lastRange.cursor == lastRange.start); this.setSelectionRange(range, lastRange.cursor == lastRange.start);
} else { } else {
var cursor = this.session.documentToScreenPosition(this.selectionLead); var cursor = this.session.documentToScreenPosition(this.cursor);
var anchor = this.session.documentToScreenPosition(this.selectionAnchor); var anchor = this.session.documentToScreenPosition(this.anchor);
var rectSel = this.rectangularRangeBlock(cursor, anchor); var rectSel = this.rectangularRangeBlock(cursor, anchor);
rectSel.forEach(this.addRange, this); rectSel.forEach(this.addRange, this);

Wyświetl plik

@ -178,8 +178,6 @@ dom.importCssString(".ace_occur-highlight {\n\
background-color: rgba(87, 255, 8, 0.25);\n\ background-color: rgba(87, 255, 8, 0.25);\n\
position: absolute;\n\ position: absolute;\n\
z-index: 4;\n\ z-index: 4;\n\
-moz-box-sizing: border-box;\n\
-webkit-box-sizing: border-box;\n\
box-sizing: border-box;\n\ box-sizing: border-box;\n\
box-shadow: 0 0 4px rgb(91, 255, 50);\n\ box-shadow: 0 0 4px rgb(91, 255, 50);\n\
}\n\ }\n\

Wyświetl plik

@ -48,12 +48,12 @@ var Range = require("./range").Range;
* Emitted when the cursor position changes. * Emitted when the cursor position changes.
* @event changeCursor * @event changeCursor
* *
**/ **/
/** /**
* Emitted when the cursor selection changes. * Emitted when the cursor selection changes.
* *
* @event changeSelection * @event changeSelection
**/ **/
/** /**
* Creates a new `Selection` object. * Creates a new `Selection` object.
* @param {EditSession} session The session to use * @param {EditSession} session The session to use
@ -65,11 +65,11 @@ var Selection = function(session) {
this.doc = session.getDocument(); this.doc = session.getDocument();
this.clearSelection(); this.clearSelection();
this.lead = this.selectionLead = this.doc.createAnchor(0, 0); this.cursor = this.lead = this.doc.createAnchor(0, 0);
this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0); this.anchor = this.doc.createAnchor(0, 0);
var self = this; var self = this;
this.lead.on("change", function(e) { this.cursor.on("change", function(e) {
self._emit("changeCursor"); self._emit("changeCursor");
if (!self.$isEmpty) if (!self.$isEmpty)
self._emit("changeSelection"); self._emit("changeSelection");
@ -77,7 +77,7 @@ var Selection = function(session) {
self.$desiredColumn = null; self.$desiredColumn = null;
}); });
this.selectionAnchor.on("change", function() { this.anchor.on("change", function() {
if (!self.$isEmpty) if (!self.$isEmpty)
self._emit("changeSelection"); self._emit("changeSelection");
}); });
@ -88,82 +88,68 @@ var Selection = function(session) {
oop.implement(this, EventEmitter); oop.implement(this, EventEmitter);
/** /**
* * Returns `true` if the selection is empty.
* Returns `true` if the selection is empty. * @returns {Boolean}
* @returns {Boolean} **/
**/
this.isEmpty = function() { this.isEmpty = function() {
return (this.$isEmpty || ( return this.$isEmpty || (
this.anchor.row == this.lead.row && this.anchor.row == this.lead.row &&
this.anchor.column == this.lead.column this.anchor.column == this.lead.column
)); );
}; };
/** /**
* Returns `true` if the selection is a multi-line. * Returns `true` if the selection is a multi-line.
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.isMultiLine = function() { this.isMultiLine = function() {
if (this.isEmpty()) { return !this.$isEmpty && this.anchor.row != this.cursor.row;
return false;
}
return this.getRange().isMultiLine();
}; };
/** /**
* Returns an object containing the `row` and `column` current position of the cursor. * Returns an object containing the `row` and `column` current position of the cursor.
* @returns {Object} * @returns {Object}
**/ **/
this.getCursor = function() { this.getCursor = function() {
return this.lead.getPosition(); return this.lead.getPosition();
}; };
/** /**
* Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event. * Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.
* @param {Number} row The new row * @param {Number} row The new row
* @param {Number} column The new column * @param {Number} column The new column
* *
* **/
**/
this.setSelectionAnchor = function(row, column) { this.setSelectionAnchor = function(row, column) {
this.$isEmpty = false;
this.anchor.setPosition(row, column); this.anchor.setPosition(row, column);
if (this.$isEmpty) {
this.$isEmpty = false;
this._emit("changeSelection");
}
}; };
/** /**
* Returns an object containing the `row` and `column` of the calling selection anchor. * Returns an object containing the `row` and `column` of the calling selection anchor.
* *
* @returns {Object} * @returns {Object}
* @related Anchor.getPosition * @related Anchor.getPosition
**/ **/
this.getSelectionAnchor = function() { this.getSelectionAnchor = function() {
if (this.$isEmpty) if (this.$isEmpty)
return this.getSelectionLead(); return this.getSelectionLead();
else
return this.anchor.getPosition(); return this.anchor.getPosition();
}; };
/** /**
* * Returns an object containing the `row` and `column` of the calling selection lead.
* Returns an object containing the `row` and `column` of the calling selection lead. * @returns {Object}
* @returns {Object} **/
**/
this.getSelectionLead = function() { this.getSelectionLead = function() {
return this.lead.getPosition(); return this.lead.getPosition();
}; };
/** /**
* Shifts the selection up (or down, if [[Selection.isBackwards `isBackwards()`]] is true) the given number of columns. * Shifts the selection up (or down, if [[Selection.isBackwards `isBackwards()`]] is true) the given number of columns.
* @param {Number} columns The number of columns to shift by * @param {Number} columns The number of columns to shift by
* **/
*
*
**/
this.shiftSelection = function(columns) { this.shiftSelection = function(columns) {
if (this.$isEmpty) { if (this.$isEmpty) {
this.moveCursorTo(this.lead.row, this.lead.column + columns); this.moveCursorTo(this.lead.row, this.lead.column + columns);
@ -186,9 +172,9 @@ var Selection = function(session) {
}; };
/** /**
* Returns `true` if the selection is going backwards in the document. * Returns `true` if the selection is going backwards in the document.
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.isBackwards = function() { this.isBackwards = function() {
var anchor = this.anchor; var anchor = this.anchor;
var lead = this.lead; var lead = this.lead;
@ -196,27 +182,24 @@ var Selection = function(session) {
}; };
/** /**
* [Returns the [[Range]] for the selected text.]{: #Selection.getRange} * [Returns the [[Range]] for the selected text.]{: #Selection.getRange}
* @returns {Range} * @returns {Range}
**/ **/
this.getRange = function() { this.getRange = function() {
var anchor = this.anchor; var anchor = this.anchor;
var lead = this.lead; var lead = this.lead;
if (this.isEmpty()) if (this.$isEmpty)
return Range.fromPoints(lead, lead); return Range.fromPoints(lead, lead);
if (this.isBackwards()) { return this.isBackwards()
return Range.fromPoints(lead, anchor); ? Range.fromPoints(lead, anchor)
} : Range.fromPoints(anchor, lead);
else {
return Range.fromPoints(anchor, lead);
}
}; };
/** /**
* [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection} * [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection}
**/ **/
this.clearSelection = function() { this.clearSelection = function() {
if (!this.$isEmpty) { if (!this.$isEmpty) {
this.$isEmpty = true; this.$isEmpty = true;
@ -225,35 +208,29 @@ var Selection = function(session) {
}; };
/** /**
* Selects all the text in the document. * Selects all the text in the document.
**/ **/
this.selectAll = function() { this.selectAll = function() {
var lastRow = this.doc.getLength() - 1; this.anchor.setPosition(0, 0);
this.setSelectionAnchor(0, 0); this.cursor.setPosition(Number.MAX_VALUE, Number.MAX_VALUE);
this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
}; };
/** /**
* Sets the selection to the provided range. * Sets the selection to the provided range.
* @param {Range} range The range of text to select * @param {Range} range The range of text to select
* @param {Boolean} reverse Indicates if the range should go backwards (`true`) or not * @param {Boolean} reverse Indicates if the range should go backwards (`true`) or not
* *
* * @method setSelectionRange
* @method setSelectionRange * @alias setRange
* @alias setRange **/
**/
this.setRange = this.setRange =
this.setSelectionRange = function(range, reverse) { this.setSelectionRange = function(range, reverse) {
if (reverse) { var start = reverse ? range.end : range.start;
this.setSelectionAnchor(range.end.row, range.end.column); var end = reverse ? range.start : range.end;
this.selectTo(range.start.row, range.start.column); this.$isEmpty = !Range.comparePoints(start, end);
} else { this.anchor.setPosition(start.row, start.column);
this.setSelectionAnchor(range.start.row, range.start.column); this.cursor.setPosition(end.row, end.column);
this.selectTo(range.end.row, range.end.column); this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
}
if (this.getRange().isEmpty())
this.$isEmpty = true;
this.$desiredColumn = null;
}; };
this.$moveSelection = function(mover) { this.$moveSelection = function(mover) {
@ -265,13 +242,10 @@ var Selection = function(session) {
}; };
/** /**
* Moves the selection cursor to the indicated row and column. * Moves the selection cursor to the indicated row and column.
* @param {Number} row The row to select to * @param {Number} row The row to select to
* @param {Number} column The column to select to * @param {Number} column The column to select to
* **/
*
*
**/
this.selectTo = function(row, column) { this.selectTo = function(row, column) {
this.$moveSelection(function() { this.$moveSelection(function() {
this.moveCursorTo(row, column); this.moveCursorTo(row, column);
@ -279,12 +253,9 @@ var Selection = function(session) {
}; };
/** /**
* Moves the selection cursor to the row and column indicated by `pos`. * Moves the selection cursor to the row and column indicated by `pos`.
* @param {Object} pos An object containing the row and column * @param {Object} pos An object containing the row and column
* **/
*
*
**/
this.selectToPosition = function(pos) { this.selectToPosition = function(pos) {
this.$moveSelection(function() { this.$moveSelection(function() {
this.moveCursorToPosition(pos); this.moveCursorToPosition(pos);
@ -292,20 +263,20 @@ var Selection = function(session) {
}; };
/** /**
* Moves the selection cursor to the indicated row and column. * Moves the selection cursor to the indicated row and column.
* @param {Number} row The row to select to * @param {Number} row The row to select to
* @param {Number} column The column to select to * @param {Number} column The column to select to
* *
**/ **/
this.moveTo = function(row, column) { this.moveTo = function(row, column) {
this.clearSelection(); this.clearSelection();
this.moveCursorTo(row, column); this.moveCursorTo(row, column);
}; };
/** /**
* Moves the selection cursor to the row and column indicated by `pos`. * Moves the selection cursor to the row and column indicated by `pos`.
* @param {Object} pos An object containing the row and column * @param {Object} pos An object containing the row and column
**/ **/
this.moveToPosition = function(pos) { this.moveToPosition = function(pos) {
this.clearSelection(); this.clearSelection();
this.moveCursorToPosition(pos); this.moveCursorToPosition(pos);
@ -313,90 +284,79 @@ var Selection = function(session) {
/** /**
* * Moves the selection up one row.
* Moves the selection up one row. **/
**/
this.selectUp = function() { this.selectUp = function() {
this.$moveSelection(this.moveCursorUp); this.$moveSelection(this.moveCursorUp);
}; };
/** /**
* * Moves the selection down one row.
* Moves the selection down one row. **/
**/
this.selectDown = function() { this.selectDown = function() {
this.$moveSelection(this.moveCursorDown); this.$moveSelection(this.moveCursorDown);
}; };
/** /**
* * Moves the selection right one column.
* **/
* Moves the selection right one column.
**/
this.selectRight = function() { this.selectRight = function() {
this.$moveSelection(this.moveCursorRight); this.$moveSelection(this.moveCursorRight);
}; };
/** /**
* * Moves the selection left one column.
* Moves the selection left one column. **/
**/
this.selectLeft = function() { this.selectLeft = function() {
this.$moveSelection(this.moveCursorLeft); this.$moveSelection(this.moveCursorLeft);
}; };
/** /**
* * Moves the selection to the beginning of the current line.
* Moves the selection to the beginning of the current line. **/
**/
this.selectLineStart = function() { this.selectLineStart = function() {
this.$moveSelection(this.moveCursorLineStart); this.$moveSelection(this.moveCursorLineStart);
}; };
/** /**
* * Moves the selection to the end of the current line.
* Moves the selection to the end of the current line. **/
**/
this.selectLineEnd = function() { this.selectLineEnd = function() {
this.$moveSelection(this.moveCursorLineEnd); this.$moveSelection(this.moveCursorLineEnd);
}; };
/** /**
* * Moves the selection to the end of the file.
* Moves the selection to the end of the file. **/
**/
this.selectFileEnd = function() { this.selectFileEnd = function() {
this.$moveSelection(this.moveCursorFileEnd); this.$moveSelection(this.moveCursorFileEnd);
}; };
/** /**
* * Moves the selection to the start of the file.
* Moves the selection to the start of the file. **/
**/
this.selectFileStart = function() { this.selectFileStart = function() {
this.$moveSelection(this.moveCursorFileStart); this.$moveSelection(this.moveCursorFileStart);
}; };
/** /**
* * Moves the selection to the first word on the right.
* Moves the selection to the first word on the right. **/
**/
this.selectWordRight = function() { this.selectWordRight = function() {
this.$moveSelection(this.moveCursorWordRight); this.$moveSelection(this.moveCursorWordRight);
}; };
/** /**
* * Moves the selection to the first word on the left.
* Moves the selection to the first word on the left. **/
**/
this.selectWordLeft = function() { this.selectWordLeft = function() {
this.$moveSelection(this.moveCursorWordLeft); this.$moveSelection(this.moveCursorWordLeft);
}; };
/** /**
* Moves the selection to highlight the entire word. * Moves the selection to highlight the entire word.
* @related EditSession.getWordRange * @related EditSession.getWordRange
**/ **/
this.getWordRange = function(row, column) { this.getWordRange = function(row, column) {
if (typeof column == "undefined") { if (typeof column == "undefined") {
var cursor = row || this.lead; var cursor = row || this.lead;
@ -407,17 +367,16 @@ var Selection = function(session) {
}; };
/** /**
* * Selects an entire word boundary.
* Selects an entire word boundary. **/
**/
this.selectWord = function() { this.selectWord = function() {
this.setSelectionRange(this.getWordRange()); this.setSelectionRange(this.getWordRange());
}; };
/** /**
* Selects a word, including its right whitespace. * Selects a word, including its right whitespace.
* @related EditSession.getAWordRange * @related EditSession.getAWordRange
**/ **/
this.selectAWord = function() { this.selectAWord = function() {
var cursor = this.getCursor(); var cursor = this.getCursor();
var range = this.session.getAWordRange(cursor.row, cursor.column); var range = this.session.getAWordRange(cursor.row, cursor.column);
@ -442,24 +401,22 @@ var Selection = function(session) {
}; };
/** /**
* Selects the entire line. * Selects the entire line.
**/ **/
this.selectLine = function() { this.selectLine = function() {
this.setSelectionRange(this.getLineRange()); this.setSelectionRange(this.getLineRange());
}; };
/** /**
* * Moves the cursor up one row.
* Moves the cursor up one row. **/
**/
this.moveCursorUp = function() { this.moveCursorUp = function() {
this.moveCursorBy(-1, 0); this.moveCursorBy(-1, 0);
}; };
/** /**
* * Moves the cursor down one row.
* Moves the cursor down one row. **/
**/
this.moveCursorDown = function() { this.moveCursorDown = function() {
this.moveCursorBy(1, 0); this.moveCursorBy(1, 0);
}; };
@ -470,7 +427,7 @@ var Selection = function(session) {
* @param {Object} cursor the current cursor position * @param {Object} cursor the current cursor position
* @param {Number} tabSize the tab size * @param {Number} tabSize the tab size
* @param {Number} direction 1 for right, -1 for left * @param {Number} direction 1 for right, -1 for left
*/ */
this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) { this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
var start = cursor.column; var start = cursor.column;
var end = cursor.column + tabSize; var end = cursor.column + tabSize;
@ -483,9 +440,8 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor left one column.
* Moves the cursor left one column. **/
**/
this.moveCursorLeft = function() { this.moveCursorLeft = function() {
var cursor = this.lead.getPosition(), var cursor = this.lead.getPosition(),
fold; fold;
@ -509,9 +465,8 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor right one column.
* Moves the cursor right one column. **/
**/
this.moveCursorRight = function() { this.moveCursorRight = function() {
var cursor = this.lead.getPosition(), var cursor = this.lead.getPosition(),
fold; fold;
@ -535,9 +490,8 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor to the start of the line.
* Moves the cursor to the start of the line. **/
**/
this.moveCursorLineStart = function() { this.moveCursorLineStart = function() {
var row = this.lead.row; var row = this.lead.row;
var column = this.lead.column; var column = this.lead.column;
@ -560,9 +514,8 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor to the end of the line.
* Moves the cursor to the end of the line. **/
**/
this.moveCursorLineEnd = function() { this.moveCursorLineEnd = function() {
var lead = this.lead; var lead = this.lead;
var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column); var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
@ -579,9 +532,8 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor to the end of the file.
* Moves the cursor to the end of the file. **/
**/
this.moveCursorFileEnd = function() { this.moveCursorFileEnd = function() {
var row = this.doc.getLength() - 1; var row = this.doc.getLength() - 1;
var column = this.doc.getLine(row).length; var column = this.doc.getLine(row).length;
@ -589,24 +541,21 @@ var Selection = function(session) {
}; };
/** /**
* * Moves the cursor to the start of the file.
* Moves the cursor to the start of the file. **/
**/
this.moveCursorFileStart = function() { this.moveCursorFileStart = function() {
this.moveCursorTo(0, 0); this.moveCursorTo(0, 0);
}; };
/** /**
* * Moves the cursor to the word on the right.
* Moves the cursor to the word on the right. **/
**/
this.moveCursorLongWordRight = function() { this.moveCursorLongWordRight = function() {
var row = this.lead.row; var row = this.lead.row;
var column = this.lead.column; var column = this.lead.column;
var line = this.doc.getLine(row); var line = this.doc.getLine(row);
var rightOfCursor = line.substring(column); var rightOfCursor = line.substring(column);
var match;
this.session.nonTokenRe.lastIndex = 0; this.session.nonTokenRe.lastIndex = 0;
this.session.tokenRe.lastIndex = 0; this.session.tokenRe.lastIndex = 0;
@ -618,7 +567,7 @@ var Selection = function(session) {
} }
// first skip space // first skip space
if (match = this.session.nonTokenRe.exec(rightOfCursor)) { if (this.session.nonTokenRe.exec(rightOfCursor)) {
column += this.session.nonTokenRe.lastIndex; column += this.session.nonTokenRe.lastIndex;
this.session.nonTokenRe.lastIndex = 0; this.session.nonTokenRe.lastIndex = 0;
rightOfCursor = line.substring(column); rightOfCursor = line.substring(column);
@ -634,7 +583,7 @@ var Selection = function(session) {
} }
// advance to the end of the next token // advance to the end of the next token
if (match = this.session.tokenRe.exec(rightOfCursor)) { if (this.session.tokenRe.exec(rightOfCursor)) {
column += this.session.tokenRe.lastIndex; column += this.session.tokenRe.lastIndex;
this.session.tokenRe.lastIndex = 0; this.session.tokenRe.lastIndex = 0;
} }
@ -663,12 +612,11 @@ var Selection = function(session) {
} }
var leftOfCursor = lang.stringReverse(str); var leftOfCursor = lang.stringReverse(str);
var match;
this.session.nonTokenRe.lastIndex = 0; this.session.nonTokenRe.lastIndex = 0;
this.session.tokenRe.lastIndex = 0; this.session.tokenRe.lastIndex = 0;
// skip whitespace // skip whitespace
if (match = this.session.nonTokenRe.exec(leftOfCursor)) { if (this.session.nonTokenRe.exec(leftOfCursor)) {
column -= this.session.nonTokenRe.lastIndex; column -= this.session.nonTokenRe.lastIndex;
leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex); leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
this.session.nonTokenRe.lastIndex = 0; this.session.nonTokenRe.lastIndex = 0;
@ -684,7 +632,7 @@ var Selection = function(session) {
} }
// move to the begin of the word // move to the begin of the word
if (match = this.session.tokenRe.exec(leftOfCursor)) { if (this.session.tokenRe.exec(leftOfCursor)) {
column -= this.session.tokenRe.lastIndex; column -= this.session.tokenRe.lastIndex;
this.session.tokenRe.lastIndex = 0; this.session.tokenRe.lastIndex = 0;
} }
@ -693,12 +641,12 @@ var Selection = function(session) {
}; };
this.$shortWordEndIndex = function(rightOfCursor) { this.$shortWordEndIndex = function(rightOfCursor) {
var match, index = 0, ch; var index = 0, ch;
var whitespaceRe = /\s/; var whitespaceRe = /\s/;
var tokenRe = this.session.tokenRe; var tokenRe = this.session.tokenRe;
tokenRe.lastIndex = 0; tokenRe.lastIndex = 0;
if (match = this.session.tokenRe.exec(rightOfCursor)) { if (this.session.tokenRe.exec(rightOfCursor)) {
index = this.session.tokenRe.lastIndex; index = this.session.tokenRe.lastIndex;
} else { } else {
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch)) while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
@ -796,13 +744,12 @@ var Selection = function(session) {
}; };
/** /**
* Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document. * Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document.
* @param {Number} rows The number of rows to move by * @param {Number} rows The number of rows to move by
* @param {Number} chars The number of characters to move by * @param {Number} chars The number of characters to move by
* *
* * @related EditSession.documentToScreenPosition
* @related EditSession.documentToScreenPosition **/
**/
this.moveCursorBy = function(rows, chars) { this.moveCursorBy = function(rows, chars) {
var screenPos = this.session.documentToScreenPosition( var screenPos = this.session.documentToScreenPosition(
this.lead.row, this.lead.row,
@ -841,11 +788,9 @@ var Selection = function(session) {
}; };
/** /**
* Moves the selection to the position indicated by its `row` and `column`. * Moves the selection to the position indicated by its `row` and `column`.
* @param {Object} position The position to move to * @param {Object} position The position to move to
* **/
*
**/
this.moveCursorToPosition = function(position) { this.moveCursorToPosition = function(position) {
this.moveCursorTo(position.row, position.column); this.moveCursorTo(position.row, position.column);
}; };
@ -934,9 +879,9 @@ var Selection = function(session) {
try { try {
func(this); func(this);
var end = this.getCursor(); var end = this.getCursor();
return Range.fromPoints(start,end); return Range.fromPoints(start, end);
} catch(e) { } catch(e) {
return Range.fromPoints(start,start); return Range.fromPoints(start, start);
} finally { } finally {
this.moveCursorToPosition(start); this.moveCursorToPosition(start);
} }
@ -967,8 +912,9 @@ var Selection = function(session) {
this.addRange(r, true); this.addRange(r, true);
} }
return; return;
} else } else {
data = data[0]; data = data[0];
}
} }
if (this.rangeList) if (this.rangeList)
this.toSingleRange(data); this.toSingleRange(data);

Wyświetl plik

@ -37,6 +37,7 @@ define(function(require, exports, module) {
var EditSession = require("./edit_session").EditSession; var EditSession = require("./edit_session").EditSession;
var assert = require("./test/assertions"); var assert = require("./test/assertions");
var Range = require("./range").Range;
module.exports = { module.exports = {
createSession : function(rows, cols) { createSession : function(rows, cols) {
@ -470,6 +471,16 @@ module.exports = {
selection.fromJSON(data); selection.fromJSON(data);
assert.position(selection.getCursor(), 1, 4); assert.position(selection.getCursor(), 1, 4);
assert.ok(selection.isEqual(data)); assert.ok(selection.isEqual(data));
},
"test setRange inside fold": function() {
var session = new EditSession("-\n-fold-\n-");
var selection = session.getSelection();
session.addFold(".", new Range(0, 1, 2, 0));
selection.setRange(new Range(1, 1, 1, 5));
assert.equal(session.getTextRange(), "fold");
} }
}; };

Wyświetl plik

@ -1,10 +1,5 @@
.ace-ambiance .ace_gutter { .ace-ambiance .ace_gutter {
background-color: #3d3d3d; background-color: #3d3d3d;
background-image: -moz-linear-gradient(left, #3D3D3D, #333);
background-image: -ms-linear-gradient(left, #3D3D3D, #333);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#3D3D3D), to(#333));
background-image: -webkit-linear-gradient(left, #3D3D3D, #333);
background-image: -o-linear-gradient(left, #3D3D3D, #333);
background-image: linear-gradient(left, #3D3D3D, #333); background-image: linear-gradient(left, #3D3D3D, #333);
background-repeat: repeat-x; background-repeat: repeat-x;
border-right: 1px solid #4d4d4d; border-right: 1px solid #4d4d4d;

Wyświetl plik

@ -593,7 +593,7 @@ var VirtualRenderer = function(container, theme) {
} }
var style = this.$printMarginEl.style; var style = this.$printMarginEl.style;
style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px"; style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
style.visibility = this.$showPrintMargin ? "visible" : "hidden"; style.visibility = this.$showPrintMargin ? "visible" : "hidden";
if (this.session && this.session.$wrap == -1) if (this.session && this.session.$wrap == -1)
@ -1018,7 +1018,7 @@ var VirtualRenderer = function(container, theme) {
offset = this.scrollTop - firstRowScreen * lineHeight; offset = this.scrollTop - firstRowScreen * lineHeight;
var changes = 0; var changes = 0;
if (this.layerConfig.width != longestLine) if (this.layerConfig.width != longestLine || hScrollChanged)
changes = this.CHANGE_H_SCROLL; changes = this.CHANGE_H_SCROLL;
// Horizontal scrollbar visibility may have changed, which changes // Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller // the client height of the scroller
@ -1078,6 +1078,9 @@ var VirtualRenderer = function(container, theme) {
var charCount = this.session.getScreenWidth(); var charCount = this.session.getScreenWidth();
if (this.showInvisibles && !this.session.$useWrapMode) if (this.showInvisibles && !this.session.$useWrapMode)
charCount += 1; charCount += 1;
if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth)); return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
}; };