Merge pull request #2254 from ajaxorg/do-not-scroll
Disable automatic scroll into view
This commit is contained in:
commit
e1933043dc
11 changed files with 235 additions and 153 deletions
|
|
@ -209,6 +209,8 @@ var AcePopup = function(parentNode) {
|
||||||
return this.screenWidth = 0;
|
return this.screenWidth = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
popup.$blockScrolling = Infinity;
|
||||||
|
|
||||||
// public
|
// public
|
||||||
popup.isOpen = false;
|
popup.isOpen = false;
|
||||||
popup.isTopdown = false;
|
popup.isTopdown = false;
|
||||||
|
|
@ -241,6 +243,7 @@ var AcePopup = function(parentNode) {
|
||||||
popup.on("changeSelection", function() {
|
popup.on("changeSelection", function() {
|
||||||
if (popup.isOpen)
|
if (popup.isOpen)
|
||||||
popup.setRow(popup.selection.lead.row);
|
popup.setRow(popup.selection.lead.row);
|
||||||
|
popup.renderer.scrollCursorIntoView();
|
||||||
});
|
});
|
||||||
|
|
||||||
popup.hide = function() {
|
popup.hide = function() {
|
||||||
|
|
|
||||||
|
|
@ -205,12 +205,14 @@ exports.commands = [{
|
||||||
bindKey: bindKey("Shift-Up", "Shift-Up"),
|
bindKey: bindKey("Shift-Up", "Shift-Up"),
|
||||||
exec: function(editor) { editor.getSelection().selectUp(); },
|
exec: function(editor) { editor.getSelection().selectUp(); },
|
||||||
multiSelectAction: "forEach",
|
multiSelectAction: "forEach",
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "golineup",
|
name: "golineup",
|
||||||
bindKey: bindKey("Up", "Up|Ctrl-P"),
|
bindKey: bindKey("Up", "Up|Ctrl-P"),
|
||||||
exec: function(editor, args) { editor.navigateUp(args.times); },
|
exec: function(editor, args) { editor.navigateUp(args.times); },
|
||||||
multiSelectAction: "forEach",
|
multiSelectAction: "forEach",
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selecttoend",
|
name: "selecttoend",
|
||||||
|
|
@ -395,12 +397,21 @@ exports.commands = [{
|
||||||
bindKey: bindKey("Ctrl-P", "Ctrl-P"),
|
bindKey: bindKey("Ctrl-P", "Ctrl-P"),
|
||||||
exec: function(editor) { editor.jumpToMatching(); },
|
exec: function(editor) { editor.jumpToMatching(); },
|
||||||
multiSelectAction: "forEach",
|
multiSelectAction: "forEach",
|
||||||
|
scrollIntoView: "animate",
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selecttomatching",
|
name: "selecttomatching",
|
||||||
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
|
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
|
||||||
exec: function(editor) { editor.jumpToMatching(true); },
|
exec: function(editor) { editor.jumpToMatching(true); },
|
||||||
multiSelectAction: "forEach",
|
multiSelectAction: "forEach",
|
||||||
|
scrollIntoView: "animate",
|
||||||
|
readOnly: true
|
||||||
|
}, {
|
||||||
|
name: "expandToMatching",
|
||||||
|
bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
|
||||||
|
exec: function(editor) { editor.jumpToMatching(true, true); },
|
||||||
|
multiSelectAction: "forEach",
|
||||||
|
scrollIntoView: "animate",
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "passKeysToBrowser",
|
name: "passKeysToBrowser",
|
||||||
|
|
@ -458,11 +469,13 @@ exports.commands = [{
|
||||||
name: "modifyNumberUp",
|
name: "modifyNumberUp",
|
||||||
bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
|
bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
|
||||||
exec: function(editor) { editor.modifyNumber(1); },
|
exec: function(editor) { editor.modifyNumber(1); },
|
||||||
|
scrollIntoView: "cursor",
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
}, {
|
}, {
|
||||||
name: "modifyNumberDown",
|
name: "modifyNumberDown",
|
||||||
bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
|
bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
|
||||||
exec: function(editor) { editor.modifyNumber(-1); },
|
exec: function(editor) { editor.modifyNumber(-1); },
|
||||||
|
scrollIntoView: "cursor",
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
}, {
|
}, {
|
||||||
name: "replace",
|
name: "replace",
|
||||||
|
|
@ -629,7 +642,7 @@ exports.commands = [{
|
||||||
var isBackwards = editor.selection.isBackwards();
|
var isBackwards = editor.selection.isBackwards();
|
||||||
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
||||||
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
||||||
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
|
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
|
||||||
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
|
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
|
||||||
var selectedCount = selectedText.replace(/\n\s*/, " ").length;
|
var selectedCount = selectedText.replace(/\n\s*/, " ").length;
|
||||||
var insertLine = editor.session.doc.getLine(selectionStart.row);
|
var insertLine = editor.session.doc.getLine(selectionStart.row);
|
||||||
|
|
@ -640,7 +653,7 @@ exports.commands = [{
|
||||||
curLine = " " + curLine;
|
curLine = " " + curLine;
|
||||||
}
|
}
|
||||||
insertLine += curLine;
|
insertLine += curLine;
|
||||||
};
|
}
|
||||||
|
|
||||||
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
|
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
|
||||||
// Don't insert a newline at the end of the document
|
// Don't insert a newline at the end of the document
|
||||||
|
|
|
||||||
|
|
@ -35,41 +35,49 @@ exports.defaultCommands = [{
|
||||||
name: "addCursorAbove",
|
name: "addCursorAbove",
|
||||||
exec: function(editor) { editor.selectMoreLines(-1); },
|
exec: function(editor) { editor.selectMoreLines(-1); },
|
||||||
bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
|
bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "addCursorBelow",
|
name: "addCursorBelow",
|
||||||
exec: function(editor) { editor.selectMoreLines(1); },
|
exec: function(editor) { editor.selectMoreLines(1); },
|
||||||
bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
|
bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "addCursorAboveSkipCurrent",
|
name: "addCursorAboveSkipCurrent",
|
||||||
exec: function(editor) { editor.selectMoreLines(-1, true); },
|
exec: function(editor) { editor.selectMoreLines(-1, true); },
|
||||||
bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
|
bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "addCursorBelowSkipCurrent",
|
name: "addCursorBelowSkipCurrent",
|
||||||
exec: function(editor) { editor.selectMoreLines(1, true); },
|
exec: function(editor) { editor.selectMoreLines(1, true); },
|
||||||
bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
|
bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selectMoreBefore",
|
name: "selectMoreBefore",
|
||||||
exec: function(editor) { editor.selectMore(-1); },
|
exec: function(editor) { editor.selectMore(-1); },
|
||||||
bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
|
bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selectMoreAfter",
|
name: "selectMoreAfter",
|
||||||
exec: function(editor) { editor.selectMore(1); },
|
exec: function(editor) { editor.selectMore(1); },
|
||||||
bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
|
bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selectNextBefore",
|
name: "selectNextBefore",
|
||||||
exec: function(editor) { editor.selectMore(-1, true); },
|
exec: function(editor) { editor.selectMore(-1, true); },
|
||||||
bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
|
bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "selectNextAfter",
|
name: "selectNextAfter",
|
||||||
exec: function(editor) { editor.selectMore(1, true); },
|
exec: function(editor) { editor.selectMore(1, true); },
|
||||||
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
|
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}, {
|
}, {
|
||||||
name: "splitIntoLines",
|
name: "splitIntoLines",
|
||||||
|
|
@ -79,11 +87,13 @@ exports.defaultCommands = [{
|
||||||
}, {
|
}, {
|
||||||
name: "alignCursors",
|
name: "alignCursors",
|
||||||
exec: function(editor) { editor.alignCursors(); },
|
exec: function(editor) { editor.alignCursors(); },
|
||||||
bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"}
|
bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
|
||||||
|
scrollIntoView: "cursor"
|
||||||
}, {
|
}, {
|
||||||
name: "findAll",
|
name: "findAll",
|
||||||
exec: function(editor) { editor.findAll(); },
|
exec: function(editor) { editor.findAll(); },
|
||||||
bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
|
bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true
|
readonly: true
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
@ -92,6 +102,7 @@ exports.multiSelectCommands = [{
|
||||||
name: "singleSelection",
|
name: "singleSelection",
|
||||||
bindKey: "esc",
|
bindKey: "esc",
|
||||||
exec: function(editor) { editor.exitMultiSelectMode(); },
|
exec: function(editor) { editor.exitMultiSelectMode(); },
|
||||||
|
scrollIntoView: "cursor",
|
||||||
readonly: true,
|
readonly: true,
|
||||||
isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
|
isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
|
||||||
}];
|
}];
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ define(function(require, exports, module) {
|
||||||
var lang = require("./lib/lang");
|
var lang = require("./lib/lang");
|
||||||
var oop = require("./lib/oop");
|
var oop = require("./lib/oop");
|
||||||
var net = require("./lib/net");
|
var net = require("./lib/net");
|
||||||
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
var AppConfig = require("./lib/app_config").AppConfig;
|
||||||
|
|
||||||
|
module.exports = exports = new AppConfig();
|
||||||
|
|
||||||
var global = (function() {
|
var global = (function() {
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -69,8 +71,6 @@ exports.all = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// module loading
|
// module loading
|
||||||
oop.implement(exports, EventEmitter);
|
|
||||||
|
|
||||||
exports.moduleUrl = function(name, component) {
|
exports.moduleUrl = function(name, component) {
|
||||||
if (options.$moduleUrls[name])
|
if (options.$moduleUrls[name])
|
||||||
return options.$moduleUrls[name];
|
return options.$moduleUrls[name];
|
||||||
|
|
@ -142,7 +142,6 @@ exports.loadModule = function(moduleName, onLoad) {
|
||||||
net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
|
net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// initialization
|
// initialization
|
||||||
function init(packaged) {
|
function init(packaged) {
|
||||||
options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
|
options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
|
||||||
|
|
@ -200,102 +199,4 @@ function deHyphenate(str) {
|
||||||
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
|
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
var optionsProvider = {
|
|
||||||
setOptions: function(optList) {
|
|
||||||
Object.keys(optList).forEach(function(key) {
|
|
||||||
this.setOption(key, optList[key]);
|
|
||||||
}, this);
|
|
||||||
},
|
|
||||||
getOptions: function(optionNames) {
|
|
||||||
var result = {};
|
|
||||||
if (!optionNames) {
|
|
||||||
optionNames = Object.keys(this.$options);
|
|
||||||
} else if (!Array.isArray(optionNames)) {
|
|
||||||
result = optionNames;
|
|
||||||
optionNames = Object.keys(result);
|
|
||||||
}
|
|
||||||
optionNames.forEach(function(key) {
|
|
||||||
result[key] = this.getOption(key);
|
|
||||||
}, this);
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
setOption: function(name, value) {
|
|
||||||
if (this["$" + name] === value)
|
|
||||||
return;
|
|
||||||
var opt = this.$options[name];
|
|
||||||
if (!opt) {
|
|
||||||
if (typeof console != "undefined" && console.warn)
|
|
||||||
console.warn('misspelled option "' + name + '"');
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (opt.forwardTo)
|
|
||||||
return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
|
|
||||||
|
|
||||||
if (!opt.handlesSet)
|
|
||||||
this["$" + name] = value;
|
|
||||||
if (opt && opt.set)
|
|
||||||
opt.set.call(this, value);
|
|
||||||
},
|
|
||||||
getOption: function(name) {
|
|
||||||
var opt = this.$options[name];
|
|
||||||
if (!opt) {
|
|
||||||
if (typeof console != "undefined" && console.warn)
|
|
||||||
console.warn('misspelled option "' + name + '"');
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (opt.forwardTo)
|
|
||||||
return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
|
|
||||||
return opt && opt.get ? opt.get.call(this) : this["$" + name];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var defaultOptions = {};
|
|
||||||
/*
|
|
||||||
* option {name, value, initialValue, setterName, set, get }
|
|
||||||
*/
|
|
||||||
exports.defineOptions = function(obj, path, options) {
|
|
||||||
if (!obj.$options)
|
|
||||||
defaultOptions[path] = obj.$options = {};
|
|
||||||
|
|
||||||
Object.keys(options).forEach(function(key) {
|
|
||||||
var opt = options[key];
|
|
||||||
if (typeof opt == "string")
|
|
||||||
opt = {forwardTo: opt};
|
|
||||||
|
|
||||||
opt.name || (opt.name = key);
|
|
||||||
obj.$options[opt.name] = opt;
|
|
||||||
if ("initialValue" in opt)
|
|
||||||
obj["$" + opt.name] = opt.initialValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
// implement option provider interface
|
|
||||||
oop.implement(obj, optionsProvider);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.resetOptions = function(obj) {
|
|
||||||
Object.keys(obj.$options).forEach(function(key) {
|
|
||||||
var opt = obj.$options[key];
|
|
||||||
if ("value" in opt)
|
|
||||||
obj.setOption(key, opt.value);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.setDefaultValue = function(path, name, value) {
|
|
||||||
var opts = defaultOptions[path] || (defaultOptions[path] = {});
|
|
||||||
if (opts[name]) {
|
|
||||||
if (opts.forwardTo)
|
|
||||||
exports.setDefaultValue(opts.forwardTo, name, value);
|
|
||||||
else
|
|
||||||
opts[name].value = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.setDefaultValues = function(path, optionHash) {
|
|
||||||
Object.keys(optionHash).forEach(function(key) {
|
|
||||||
exports.setDefaultValue(path, key, optionHash[key]);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -969,8 +969,7 @@ var EditSession = function(text, mode) {
|
||||||
try {
|
try {
|
||||||
this.$worker = this.$mode.createWorker(this);
|
this.$worker = this.$mode.createWorker(this);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof console == "object" && console.error)
|
config.warn("Could not load worker", e);
|
||||||
console.log("Could not load worker", e);
|
|
||||||
this.$worker = null;
|
this.$worker = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,8 @@ var Editor = function(renderer, session) {
|
||||||
args: commadEvent.args,
|
args: commadEvent.args,
|
||||||
scrollTop: this.renderer.scrollTop
|
scrollTop: this.renderer.scrollTop
|
||||||
};
|
};
|
||||||
|
if (this.curOp.command.name)
|
||||||
|
this.$blockScrolling++;
|
||||||
// this.selections.push(this.selection.toJSON());
|
// this.selections.push(this.selection.toJSON());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -160,6 +161,8 @@ var Editor = function(renderer, session) {
|
||||||
return this.curOp = null;
|
return this.curOp = null;
|
||||||
this._signal("beforeEndOperation");
|
this._signal("beforeEndOperation");
|
||||||
var command = this.curOp.command;
|
var command = this.curOp.command;
|
||||||
|
if (command.name && this.$blockScrolling)
|
||||||
|
this.$blockScrolling--;
|
||||||
if (command && command.scrollIntoView) {
|
if (command && command.scrollIntoView) {
|
||||||
switch (command.scrollIntoView) {
|
switch (command.scrollIntoView) {
|
||||||
case "center":
|
case "center":
|
||||||
|
|
@ -714,6 +717,10 @@ var Editor = function(renderer, session) {
|
||||||
this.$cursorChange();
|
this.$cursorChange();
|
||||||
|
|
||||||
if (!this.$blockScrolling) {
|
if (!this.$blockScrolling) {
|
||||||
|
config.warn("Automatically scrolling cursor into view after selection change",
|
||||||
|
"this will be disabled in the next version",
|
||||||
|
"set editor.$blockScrolling = Infinity to disable this message"
|
||||||
|
);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -902,9 +909,28 @@ var Editor = function(renderer, session) {
|
||||||
// todo this should change when paste becomes a command
|
// todo this should change when paste becomes a command
|
||||||
if (this.$readOnly)
|
if (this.$readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var e = {text: text};
|
var e = {text: text};
|
||||||
this._signal("paste", e);
|
this._signal("paste", e);
|
||||||
this.insert(e.text, true);
|
text = e.text;
|
||||||
|
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
|
||||||
|
this.insert(text);
|
||||||
|
} else {
|
||||||
|
var lines = text.split(/\r\n|\r|\n/);
|
||||||
|
var ranges = this.selection.rangeList.ranges;
|
||||||
|
|
||||||
|
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
|
||||||
|
return this.commands.exec("insertstring", this, text);
|
||||||
|
|
||||||
|
for (var i = ranges.length; i--;) {
|
||||||
|
var range = ranges[i];
|
||||||
|
if (!range.isEmpty())
|
||||||
|
this.session.remove(range);
|
||||||
|
|
||||||
|
this.session.insert(range.start, lines[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.execCommand = function(command, args) {
|
this.execCommand = function(command, args) {
|
||||||
|
|
|
||||||
158
lib/ace/lib/app_config.js
Normal file
158
lib/ace/lib/app_config.js
Normal 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) {
|
||||||
|
"no use strict";
|
||||||
|
|
||||||
|
var lang = require("./lang");
|
||||||
|
var oop = require("./oop");
|
||||||
|
var EventEmitter = require("./event_emitter").EventEmitter;
|
||||||
|
|
||||||
|
var optionsProvider = {
|
||||||
|
setOptions: function(optList) {
|
||||||
|
Object.keys(optList).forEach(function(key) {
|
||||||
|
this.setOption(key, optList[key]);
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
getOptions: function(optionNames) {
|
||||||
|
var result = {};
|
||||||
|
if (!optionNames) {
|
||||||
|
optionNames = Object.keys(this.$options);
|
||||||
|
} else if (!Array.isArray(optionNames)) {
|
||||||
|
result = optionNames;
|
||||||
|
optionNames = Object.keys(result);
|
||||||
|
}
|
||||||
|
optionNames.forEach(function(key) {
|
||||||
|
result[key] = this.getOption(key);
|
||||||
|
}, this);
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
setOption: function(name, value) {
|
||||||
|
if (this["$" + name] === value)
|
||||||
|
return;
|
||||||
|
var opt = this.$options[name];
|
||||||
|
if (!opt) {
|
||||||
|
return warn('misspelled option "' + name + '"');
|
||||||
|
}
|
||||||
|
if (opt.forwardTo)
|
||||||
|
return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
|
||||||
|
|
||||||
|
if (!opt.handlesSet)
|
||||||
|
this["$" + name] = value;
|
||||||
|
if (opt && opt.set)
|
||||||
|
opt.set.call(this, value);
|
||||||
|
},
|
||||||
|
getOption: function(name) {
|
||||||
|
var opt = this.$options[name];
|
||||||
|
if (!opt) {
|
||||||
|
return warn('misspelled option "' + name + '"');
|
||||||
|
}
|
||||||
|
if (opt.forwardTo)
|
||||||
|
return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
|
||||||
|
return opt && opt.get ? opt.get.call(this) : this["$" + name];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function warn(message) {
|
||||||
|
if (typeof console != "undefined" && console.warn)
|
||||||
|
console.warn.apply(console, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportError(msg, data) {
|
||||||
|
var e = new Error(msg);
|
||||||
|
e.data = data;
|
||||||
|
if (typeof console == "object" && console.error)
|
||||||
|
console.error(e);
|
||||||
|
setTimeout(function() { throw e; });
|
||||||
|
};
|
||||||
|
|
||||||
|
var AppConfig = function() {
|
||||||
|
this.$defaultOptions = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
// module loading
|
||||||
|
oop.implement(this, EventEmitter);
|
||||||
|
/*
|
||||||
|
* option {name, value, initialValue, setterName, set, get }
|
||||||
|
*/
|
||||||
|
this.defineOptions = function(obj, path, options) {
|
||||||
|
if (!obj.$options)
|
||||||
|
this.$defaultOptions[path] = obj.$options = {};
|
||||||
|
|
||||||
|
Object.keys(options).forEach(function(key) {
|
||||||
|
var opt = options[key];
|
||||||
|
if (typeof opt == "string")
|
||||||
|
opt = {forwardTo: opt};
|
||||||
|
|
||||||
|
opt.name || (opt.name = key);
|
||||||
|
obj.$options[opt.name] = opt;
|
||||||
|
if ("initialValue" in opt)
|
||||||
|
obj["$" + opt.name] = opt.initialValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
// implement option provider interface
|
||||||
|
oop.implement(obj, optionsProvider);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.resetOptions = function(obj) {
|
||||||
|
Object.keys(obj.$options).forEach(function(key) {
|
||||||
|
var opt = obj.$options[key];
|
||||||
|
if ("value" in opt)
|
||||||
|
obj.setOption(key, opt.value);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setDefaultValue = function(path, name, value) {
|
||||||
|
var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
|
||||||
|
if (opts[name]) {
|
||||||
|
if (opts.forwardTo)
|
||||||
|
this.setDefaultValue(opts.forwardTo, name, value);
|
||||||
|
else
|
||||||
|
opts[name].value = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setDefaultValues = function(path, optionHash) {
|
||||||
|
Object.keys(optionHash).forEach(function(key) {
|
||||||
|
this.setDefaultValue(path, key, optionHash[key]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.warn = warn;
|
||||||
|
this.reportError = reportError;
|
||||||
|
|
||||||
|
}).call(AppConfig.prototype);
|
||||||
|
|
||||||
|
exports.AppConfig = AppConfig;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -31,9 +31,6 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
if (typeof document == "undefined")
|
|
||||||
return;
|
|
||||||
|
|
||||||
var XHTML_NS = "http://www.w3.org/1999/xhtml";
|
var XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||||
|
|
||||||
exports.getDocumentHead = function(doc) {
|
exports.getDocumentHead = function(doc) {
|
||||||
|
|
@ -175,6 +172,10 @@ exports.getInnerHeight = function(element) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof document == "undefined")
|
||||||
|
return;
|
||||||
|
|
||||||
if (window.pageYOffset !== undefined) {
|
if (window.pageYOffset !== undefined) {
|
||||||
exports.getPageScrollTop = function() {
|
exports.getPageScrollTop = function() {
|
||||||
return window.pageYOffset;
|
return window.pageYOffset;
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,10 @@ function DefaultHandlers(mouseHandler) {
|
||||||
if (button !== 0) {
|
if (button !== 0) {
|
||||||
var selectionRange = editor.getSelectionRange();
|
var selectionRange = editor.getSelectionRange();
|
||||||
var selectionEmpty = selectionRange.isEmpty();
|
var selectionEmpty = selectionRange.isEmpty();
|
||||||
|
editor.$blockScrolling++;
|
||||||
if (selectionEmpty)
|
if (selectionEmpty)
|
||||||
editor.selection.moveToPosition(pos);
|
editor.selection.moveToPosition(pos);
|
||||||
|
editor.$blockScrolling--;
|
||||||
// 2: contextmenu, 1: linux paste
|
// 2: contextmenu, 1: linux paste
|
||||||
editor.textInput.onContextMenu(ev.domEvent);
|
editor.textInput.onContextMenu(ev.domEvent);
|
||||||
return; // stopping event here breaks contextmenu on ff mac
|
return; // stopping event here breaks contextmenu on ff mac
|
||||||
|
|
@ -100,7 +100,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
|
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
|
||||||
var editor = this.editor;
|
var editor = this.editor;
|
||||||
// allow double/triple click handlers to change selection
|
// allow double/triple click handlers to change selection
|
||||||
|
editor.$blockScrolling++;
|
||||||
if (this.mousedownEvent.getShiftKey())
|
if (this.mousedownEvent.getShiftKey())
|
||||||
editor.selection.selectToPosition(pos);
|
editor.selection.selectToPosition(pos);
|
||||||
else if (!waitForClickSelection)
|
else if (!waitForClickSelection)
|
||||||
|
|
@ -112,12 +112,13 @@ function DefaultHandlers(mouseHandler) {
|
||||||
}
|
}
|
||||||
editor.setStyle("ace_selecting");
|
editor.setStyle("ace_selecting");
|
||||||
this.setState("select");
|
this.setState("select");
|
||||||
|
editor.$blockScrolling--;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.select = function() {
|
this.select = function() {
|
||||||
var anchor, editor = this.editor;
|
var anchor, editor = this.editor;
|
||||||
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
|
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
|
||||||
|
editor.$blockScrolling++;
|
||||||
if (this.$clickSelection) {
|
if (this.$clickSelection) {
|
||||||
var cmp = this.$clickSelection.comparePoint(cursor);
|
var cmp = this.$clickSelection.comparePoint(cursor);
|
||||||
|
|
||||||
|
|
@ -133,7 +134,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
|
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
|
||||||
}
|
}
|
||||||
editor.selection.selectToPosition(cursor);
|
editor.selection.selectToPosition(cursor);
|
||||||
|
editor.$blockScrolling--;
|
||||||
editor.renderer.scrollCursorIntoView();
|
editor.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -141,7 +142,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
var anchor, editor = this.editor;
|
var anchor, editor = this.editor;
|
||||||
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
|
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
|
||||||
var range = editor.selection[unitName](cursor.row, cursor.column);
|
var range = editor.selection[unitName](cursor.row, cursor.column);
|
||||||
|
editor.$blockScrolling++;
|
||||||
if (this.$clickSelection) {
|
if (this.$clickSelection) {
|
||||||
var cmpStart = this.$clickSelection.comparePoint(range.start);
|
var cmpStart = this.$clickSelection.comparePoint(range.start);
|
||||||
var cmpEnd = this.$clickSelection.comparePoint(range.end);
|
var cmpEnd = this.$clickSelection.comparePoint(range.end);
|
||||||
|
|
@ -165,7 +166,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
|
editor.selection.setSelectionAnchor(anchor.row, anchor.column);
|
||||||
}
|
}
|
||||||
editor.selection.selectToPosition(cursor);
|
editor.selection.selectToPosition(cursor);
|
||||||
|
editor.$blockScrolling--;
|
||||||
editor.renderer.scrollCursorIntoView();
|
editor.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -558,33 +558,6 @@ var Editor = require("./editor").Editor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo this should change when paste becomes a command
|
|
||||||
this.onPaste = function(text) {
|
|
||||||
if (this.$readOnly)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
var e = {text: text};
|
|
||||||
this._signal("paste", e);
|
|
||||||
text = e.text;
|
|
||||||
if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
|
|
||||||
return this.insert(text);
|
|
||||||
|
|
||||||
var lines = text.split(/\r\n|\r|\n/);
|
|
||||||
var ranges = this.selection.rangeList.ranges;
|
|
||||||
|
|
||||||
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
|
|
||||||
return this.commands.exec("insertstring", this, text);
|
|
||||||
|
|
||||||
for (var i = ranges.length; i--;) {
|
|
||||||
var range = ranges[i];
|
|
||||||
if (!range.isEmpty())
|
|
||||||
this.session.remove(range);
|
|
||||||
|
|
||||||
this.session.insert(range.start, lines[i]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and selects all the occurences of `needle`.
|
* Finds and selects all the occurences of `needle`.
|
||||||
* @param {String} The text to find
|
* @param {String} The text to find
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var config = require("./config");
|
||||||
// tokenizing lines longer than this makes editor very slow
|
// tokenizing lines longer than this makes editor very slow
|
||||||
var MAX_TOKEN_COUNT = 2000;
|
var MAX_TOKEN_COUNT = 2000;
|
||||||
/**
|
/**
|
||||||
|
|
@ -353,13 +354,8 @@ var Tokenizer = function(rules) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reportError = function(msg, data) {
|
this.reportError = config.reportError;
|
||||||
var e = new Error(msg);
|
|
||||||
e.data = data;
|
|
||||||
if (typeof console == "object" && console.error)
|
|
||||||
console.error(e);
|
|
||||||
setTimeout(function() { throw e; });
|
|
||||||
};
|
|
||||||
}).call(Tokenizer.prototype);
|
}).call(Tokenizer.prototype);
|
||||||
|
|
||||||
exports.Tokenizer = Tokenizer;
|
exports.Tokenizer = Tokenizer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue