small cleanups
This commit is contained in:
parent
806114aa2e
commit
6e1215a45e
13 changed files with 172 additions and 136 deletions
|
|
@ -51,16 +51,11 @@ oop.inherits(CommandManager, HashHandler);
|
|||
if (editor && editor.$readOnly && !command.readOnly)
|
||||
return false;
|
||||
|
||||
try {
|
||||
var retvalue = this._emit("exec", {
|
||||
editor: editor,
|
||||
command: command,
|
||||
args: args
|
||||
});
|
||||
} catch (e) {
|
||||
window.console && window.console.log(e);
|
||||
return true;
|
||||
}
|
||||
var retvalue = this._emit("exec", {
|
||||
editor: editor,
|
||||
command: command,
|
||||
args: args
|
||||
});
|
||||
|
||||
return retvalue === false ? false : true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,12 +79,15 @@ exports.defaultCommands = [{
|
|||
exec: function(editor) { editor.selectMore(1, true); },
|
||||
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
|
||||
readonly: true
|
||||
}, {
|
||||
}, {
|
||||
name: "splitIntoLines",
|
||||
exec: function(editor) { editor.multiSelect.splitIntoLines(); },
|
||||
bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"},
|
||||
readonly: true
|
||||
}, {
|
||||
}];
|
||||
|
||||
// commands active in multiselect mode
|
||||
exports.multiSelectCommands = [{
|
||||
name: "singleSelection",
|
||||
bindKey: "esc",
|
||||
exec: function(editor) { editor.exitMultiSelectMode(); },
|
||||
|
|
@ -92,10 +95,7 @@ exports.defaultCommands = [{
|
|||
isAvailable: function(editor) {return editor.inMultiSelectMode}
|
||||
}];
|
||||
|
||||
// commands active in multiselect mode
|
||||
exports.multiEditCommands = {"singleSelection": "esc"};
|
||||
|
||||
var HashHandler = require("../keyboard/hash_handler").HashHandler;
|
||||
exports.keyboardHandler = new HashHandler(exports.multiEditCommands);
|
||||
exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,14 +55,14 @@ var options = {
|
|||
|
||||
exports.get = function(key) {
|
||||
if (!options.hasOwnProperty(key))
|
||||
throw new Error("Unknown confik key: " + key);
|
||||
throw new Error("Unknown config key: " + key);
|
||||
|
||||
return options[key];
|
||||
};
|
||||
|
||||
exports.set = function(key, value) {
|
||||
if (!options.hasOwnProperty(key))
|
||||
throw new Error("Unknown confik key: " + key);
|
||||
throw new Error("Unknown config key: " + key);
|
||||
|
||||
options[key] = value;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -235,6 +235,35 @@ var Editor = function(renderer, session) {
|
|||
return this.session;
|
||||
};
|
||||
|
||||
/** related to: Document.setValue
|
||||
* Editor.setValue(val [,dontSelect]) -> String
|
||||
* - val (String): The new value to set for the document
|
||||
* - cursorPos (number): 0: selectAll, -1 document start, 1 end
|
||||
*
|
||||
* Sets the current document to `val`.
|
||||
**/
|
||||
this.setValue = function(val, cursorPos) {
|
||||
this.session.doc.setValue(val);
|
||||
|
||||
if (!cursorPos)
|
||||
this.selectAll();
|
||||
else if (cursorPos == 1)
|
||||
this.navigateFileEnd();
|
||||
else if (cursorPos == -1)
|
||||
this.navigateFileStart();
|
||||
|
||||
return val;
|
||||
};
|
||||
|
||||
/** related to: EditSession.getValue
|
||||
* Editor.getValue() -> String
|
||||
*
|
||||
* Returns the current session's content.
|
||||
**/
|
||||
this.getValue = function() {
|
||||
return this.session.getValue();
|
||||
};
|
||||
|
||||
/**
|
||||
* Editor.getSelection() -> String
|
||||
*
|
||||
|
|
@ -249,8 +278,8 @@ var Editor = function(renderer, session) {
|
|||
*
|
||||
* {:VirtualRenderer.onResize}
|
||||
**/
|
||||
this.resize = function() {
|
||||
this.renderer.onResize();
|
||||
this.resize = function(force) {
|
||||
this.renderer.onResize(force);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -57,9 +57,8 @@ function HashHandler(config, platform) {
|
|||
|
||||
this.commands[command.name] = command;
|
||||
|
||||
if (command.bindKey) {
|
||||
if (command.bindKey)
|
||||
this._buildKeyHash(command);
|
||||
}
|
||||
};
|
||||
|
||||
this.removeCommand = function(command) {
|
||||
|
|
@ -81,6 +80,10 @@ function HashHandler(config, platform) {
|
|||
this.bindKey = function(key, command) {
|
||||
if(!key)
|
||||
return;
|
||||
if (typeof command == "function") {
|
||||
this.addCommand({exec: command, bindKey: key, name: key});
|
||||
return;
|
||||
}
|
||||
|
||||
var ckb = this.commmandKeyBinding;
|
||||
key.split("|").forEach(function(keyPart) {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ var KeyBinding = function(editor) {
|
|||
else
|
||||
success = toExecute.passEvent != true;
|
||||
|
||||
if (success && e)
|
||||
// do not stop input events to not break repeating
|
||||
if (success && e && hashId != -1)
|
||||
event.stopEvent(e);
|
||||
|
||||
return success;
|
||||
|
|
|
|||
|
|
@ -108,7 +108,9 @@ exports.handler = {
|
|||
editor.removeListener("click", exports.onCursorMove);
|
||||
util.noMode(editor);
|
||||
util.currentMode = "normal";
|
||||
}
|
||||
},
|
||||
|
||||
actions: cmds.actions
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,18 +52,6 @@ var MOTION = 3;
|
|||
var ACTION = 4;
|
||||
var HMARGIN = 8; // Minimum amount of line separation between margins;
|
||||
|
||||
exports.searchStore = {
|
||||
current: "",
|
||||
options: {
|
||||
needle: "",
|
||||
backwards: false,
|
||||
wrap: true,
|
||||
caseSensitive: false,
|
||||
wholeWord: false,
|
||||
regExp: false
|
||||
}
|
||||
};
|
||||
|
||||
var repeat = function repeat(fn, count, args) {
|
||||
while (0 < count--)
|
||||
fn.apply(this, args);
|
||||
|
|
@ -88,7 +76,7 @@ var ensureScrollMargin = function(editor) {
|
|||
}
|
||||
};
|
||||
|
||||
var actions = {
|
||||
var actions = exports.actions = {
|
||||
"z": {
|
||||
param: true,
|
||||
fn: function(editor, range, count, param) {
|
||||
|
|
@ -288,16 +276,17 @@ var actions = {
|
|||
},
|
||||
":": {
|
||||
fn: function(editor, range, count, param) {
|
||||
editor.blur();
|
||||
txtConsoleInput.focus();
|
||||
txtConsoleInput.setValue(":");
|
||||
// not implemented
|
||||
}
|
||||
},
|
||||
"/": {
|
||||
fn: function(editor, range, count, param) {
|
||||
editor.blur();
|
||||
txtConsoleInput.focus();
|
||||
txtConsoleInput.setValue("/");
|
||||
// not implemented
|
||||
}
|
||||
},
|
||||
"?": {
|
||||
fn: function(editor, range, count, param) {
|
||||
// not implemented
|
||||
}
|
||||
},
|
||||
".": {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ function GutterHandler(mouseHandler) {
|
|||
}
|
||||
|
||||
mouseHandler.captureMouse(e, "selectByLines");
|
||||
return e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,16 +42,12 @@ define(function(require, exports, module) {
|
|||
"use strict";
|
||||
|
||||
var dom = require("../lib/dom");
|
||||
var BrowserFocus = require("../lib/browser_focus").BrowserFocus;
|
||||
|
||||
var useragent = require("../lib/useragent");
|
||||
|
||||
var DRAG_OFFSET = 5; // pixels
|
||||
|
||||
|
||||
|
||||
function DefaultHandlers(mouseHandler) {
|
||||
mouseHandler.$clickSelection = null;
|
||||
mouseHandler.browserFocus = new BrowserFocus();
|
||||
|
||||
var editor = mouseHandler.editor;
|
||||
editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
|
||||
|
|
@ -69,14 +65,16 @@ function DefaultHandlers(mouseHandler) {
|
|||
|
||||
mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
|
||||
mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
|
||||
|
||||
mouseHandler.$focusWaitTimout = 250;
|
||||
}
|
||||
|
||||
(function() {
|
||||
|
||||
this.onMouseDown = function(ev) {
|
||||
this.mousedownEvent = ev;
|
||||
var inSelection = ev.inSelection();
|
||||
var pos = ev.getDocumentPosition();
|
||||
this.mousedownEvent = ev;
|
||||
var editor = this.editor;
|
||||
var _self = this;
|
||||
|
||||
|
|
@ -99,7 +97,10 @@ function DefaultHandlers(mouseHandler) {
|
|||
// selection
|
||||
if (inSelection && !editor.isFocused()) {
|
||||
editor.focus();
|
||||
return;
|
||||
if (this.$focusWaitTimout && !this.$clickSelection) {
|
||||
// todo start select after focusWaitTimout passes
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inSelection || this.$clickSelection || ev.getShiftKey()) {
|
||||
|
|
@ -116,7 +117,8 @@ function DefaultHandlers(mouseHandler) {
|
|||
}
|
||||
}
|
||||
|
||||
this.captureMouse(ev)
|
||||
this.captureMouse(ev);
|
||||
return ev.preventDefault();
|
||||
};
|
||||
|
||||
this.startSelect = function(pos) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ var Range = require("./range").Range;
|
|||
var Selection = require("./selection").Selection;
|
||||
var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
|
||||
var event = require("./lib/event");
|
||||
exports.commands = require("./commands/multi_select_commands");
|
||||
var commands = require("./commands/multi_select_commands");
|
||||
exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
|
||||
|
||||
// Todo: session.find or editor.findVolatile that returns range
|
||||
var Search = require("./search").Search;
|
||||
|
|
@ -397,7 +398,7 @@ var Editor = require("./editor").Editor;
|
|||
this.inMultiSelectMode = true;
|
||||
|
||||
this.setStyle("multiselect");
|
||||
this.keyBinding.addKeyboardHandler(exports.commands.keyboardHandler);
|
||||
this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
|
||||
this.commands.on("exec", this.$onMultiSelectExec);
|
||||
|
||||
this.renderer.updateCursor();
|
||||
|
|
@ -410,7 +411,7 @@ var Editor = require("./editor").Editor;
|
|||
this.inMultiSelectMode = false;
|
||||
|
||||
this.unsetStyle("multiselect");
|
||||
this.keyBinding.removeKeyboardHandler(exports.commands.keyboardHandler);
|
||||
this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
|
||||
|
||||
this.commands.removeEventListener("exec", this.$onMultiSelectExec);
|
||||
this.renderer.updateCursor();
|
||||
|
|
@ -420,6 +421,8 @@ var Editor = require("./editor").Editor;
|
|||
this.$onMultiSelectExec = function(e) {
|
||||
var command = e.command;
|
||||
var editor = e.editor;
|
||||
if (!editor.multiSelect)
|
||||
return;
|
||||
if (!command.multiSelectAction) {
|
||||
command.exec(editor, e.args || {});
|
||||
editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
|
||||
|
|
@ -724,7 +727,7 @@ function MultiSelect(editor) {
|
|||
editor.on("changeSession", exports.onSessionChange.bind(editor));
|
||||
|
||||
editor.on("mousedown", onMouseDown);
|
||||
editor.commands.addCommands(exports.commands.defaultCommands);
|
||||
editor.commands.addCommands(commands.defaultCommands);
|
||||
|
||||
addAltCursorListeners(editor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,8 +236,8 @@ var Selection = function(session) {
|
|||
**/
|
||||
this.selectAll = function() {
|
||||
var lastRow = this.doc.getLength() - 1;
|
||||
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
||||
this.moveCursorTo(0, 0);
|
||||
this.setSelectionAnchor(0, 0);
|
||||
this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -248,6 +248,7 @@ var Selection = function(session) {
|
|||
* Sets the selection to the provided range.
|
||||
*
|
||||
**/
|
||||
this.setRange =
|
||||
this.setSelectionRange = function(range, reverse) {
|
||||
if (reverse) {
|
||||
this.setSelectionAnchor(range.end.row, range.end.column);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,11 @@ if (location.search)
|
|||
testNames = location.search.substr(1).split(",")
|
||||
|
||||
require(testNames, function() {
|
||||
var tests = testNames.map(require);
|
||||
var tests = testNames.map(function(x) {
|
||||
var module = require(x);
|
||||
module.href = x;
|
||||
return module;
|
||||
});
|
||||
|
||||
async.list(tests)
|
||||
.expand(function(test) {
|
||||
|
|
@ -73,6 +77,12 @@ require(testNames, function() {
|
|||
}, AsyncTest.TestGenerator)
|
||||
.run()
|
||||
.each(function(test, next) {
|
||||
if (test.index == 1 && test.context.href) {
|
||||
var href = test.context.href;
|
||||
var node = document.createElement("div");
|
||||
node.innerHTML = "<a href='?" + href + "'>" + href.replace(/^ace\//, "") + "</a>";
|
||||
log.appendChild(node);
|
||||
}
|
||||
var node = document.createElement("div");
|
||||
node.className = test.passed ? "passed" : "failed";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue