small cleanups

This commit is contained in:
nightwing 2012-05-25 11:28:20 +04:00
commit 6e1215a45e
13 changed files with 172 additions and 136 deletions

View file

@ -51,16 +51,11 @@ oop.inherits(CommandManager, HashHandler);
if (editor && editor.$readOnly && !command.readOnly) if (editor && editor.$readOnly && !command.readOnly)
return false; return false;
try { var retvalue = this._emit("exec", {
var retvalue = this._emit("exec", { editor: editor,
editor: editor, command: command,
command: command, args: args
args: args });
});
} catch (e) {
window.console && window.console.log(e);
return true;
}
return retvalue === false ? false : true; return retvalue === false ? false : true;
}; };

View file

@ -79,12 +79,15 @@ exports.defaultCommands = [{
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"},
readonly: true readonly: true
}, { }, {
name: "splitIntoLines", name: "splitIntoLines",
exec: function(editor) { editor.multiSelect.splitIntoLines(); }, exec: function(editor) { editor.multiSelect.splitIntoLines(); },
bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"}, bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"},
readonly: true readonly: true
}, { }];
// commands active in multiselect mode
exports.multiSelectCommands = [{
name: "singleSelection", name: "singleSelection",
bindKey: "esc", bindKey: "esc",
exec: function(editor) { editor.exitMultiSelectMode(); }, exec: function(editor) { editor.exitMultiSelectMode(); },
@ -92,10 +95,7 @@ exports.defaultCommands = [{
isAvailable: function(editor) {return editor.inMultiSelectMode} isAvailable: function(editor) {return editor.inMultiSelectMode}
}]; }];
// commands active in multiselect mode
exports.multiEditCommands = {"singleSelection": "esc"};
var HashHandler = require("../keyboard/hash_handler").HashHandler; var HashHandler = require("../keyboard/hash_handler").HashHandler;
exports.keyboardHandler = new HashHandler(exports.multiEditCommands); exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
}); });

View file

@ -55,14 +55,14 @@ var options = {
exports.get = function(key) { exports.get = function(key) {
if (!options.hasOwnProperty(key)) if (!options.hasOwnProperty(key))
throw new Error("Unknown confik key: " + key); throw new Error("Unknown config key: " + key);
return options[key]; return options[key];
}; };
exports.set = function(key, value) { exports.set = function(key, value) {
if (!options.hasOwnProperty(key)) if (!options.hasOwnProperty(key))
throw new Error("Unknown confik key: " + key); throw new Error("Unknown config key: " + key);
options[key] = value; options[key] = value;
}; };

View file

@ -235,6 +235,35 @@ var Editor = function(renderer, session) {
return this.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 * Editor.getSelection() -> String
* *
@ -249,8 +278,8 @@ var Editor = function(renderer, session) {
* *
* {:VirtualRenderer.onResize} * {:VirtualRenderer.onResize}
**/ **/
this.resize = function() { this.resize = function(force) {
this.renderer.onResize(); this.renderer.onResize(force);
}; };
/** /**

View file

@ -57,9 +57,8 @@ function HashHandler(config, platform) {
this.commands[command.name] = command; this.commands[command.name] = command;
if (command.bindKey) { if (command.bindKey)
this._buildKeyHash(command); this._buildKeyHash(command);
}
}; };
this.removeCommand = function(command) { this.removeCommand = function(command) {
@ -81,6 +80,10 @@ function HashHandler(config, platform) {
this.bindKey = function(key, command) { this.bindKey = function(key, command) {
if(!key) if(!key)
return; return;
if (typeof command == "function") {
this.addCommand({exec: command, bindKey: key, name: key});
return;
}
var ckb = this.commmandKeyBinding; var ckb = this.commmandKeyBinding;
key.split("|").forEach(function(keyPart) { key.split("|").forEach(function(keyPart) {

View file

@ -119,7 +119,8 @@ var KeyBinding = function(editor) {
else else
success = toExecute.passEvent != true; success = toExecute.passEvent != true;
if (success && e) // do not stop input events to not break repeating
if (success && e && hashId != -1)
event.stopEvent(e); event.stopEvent(e);
return success; return success;

View file

@ -108,7 +108,9 @@ exports.handler = {
editor.removeListener("click", exports.onCursorMove); editor.removeListener("click", exports.onCursorMove);
util.noMode(editor); util.noMode(editor);
util.currentMode = "normal"; util.currentMode = "normal";
} },
actions: cmds.actions
}; };

View file

@ -52,18 +52,6 @@ var MOTION = 3;
var ACTION = 4; var ACTION = 4;
var HMARGIN = 8; // Minimum amount of line separation between margins; 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) { var repeat = function repeat(fn, count, args) {
while (0 < count--) while (0 < count--)
fn.apply(this, args); fn.apply(this, args);
@ -88,7 +76,7 @@ var ensureScrollMargin = function(editor) {
} }
}; };
var actions = { var actions = exports.actions = {
"z": { "z": {
param: true, param: true,
fn: function(editor, range, count, param) { fn: function(editor, range, count, param) {
@ -288,16 +276,17 @@ var actions = {
}, },
":": { ":": {
fn: function(editor, range, count, param) { fn: function(editor, range, count, param) {
editor.blur(); // not implemented
txtConsoleInput.focus();
txtConsoleInput.setValue(":");
} }
}, },
"/": { "/": {
fn: function(editor, range, count, param) { fn: function(editor, range, count, param) {
editor.blur(); // not implemented
txtConsoleInput.focus(); }
txtConsoleInput.setValue("/"); },
"?": {
fn: function(editor, range, count, param) {
// not implemented
} }
}, },
".": { ".": {

View file

@ -67,6 +67,7 @@ function GutterHandler(mouseHandler) {
} }
mouseHandler.captureMouse(e, "selectByLines"); mouseHandler.captureMouse(e, "selectByLines");
return e.preventDefault();
}); });
} }

View file

@ -42,16 +42,12 @@ define(function(require, exports, module) {
"use strict"; "use strict";
var dom = require("../lib/dom"); var dom = require("../lib/dom");
var BrowserFocus = require("../lib/browser_focus").BrowserFocus; var useragent = require("../lib/useragent");
var DRAG_OFFSET = 5; // pixels var DRAG_OFFSET = 5; // pixels
function DefaultHandlers(mouseHandler) { function DefaultHandlers(mouseHandler) {
mouseHandler.$clickSelection = null; mouseHandler.$clickSelection = null;
mouseHandler.browserFocus = new BrowserFocus();
var editor = mouseHandler.editor; var editor = mouseHandler.editor;
editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler)); editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
@ -69,14 +65,16 @@ function DefaultHandlers(mouseHandler) {
mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange"); mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
mouseHandler.$focusWaitTimout = 250;
} }
(function() { (function() {
this.onMouseDown = function(ev) { this.onMouseDown = function(ev) {
this.mousedownEvent = ev;
var inSelection = ev.inSelection(); var inSelection = ev.inSelection();
var pos = ev.getDocumentPosition(); var pos = ev.getDocumentPosition();
this.mousedownEvent = ev;
var editor = this.editor; var editor = this.editor;
var _self = this; var _self = this;
@ -99,7 +97,10 @@ function DefaultHandlers(mouseHandler) {
// selection // selection
if (inSelection && !editor.isFocused()) { if (inSelection && !editor.isFocused()) {
editor.focus(); editor.focus();
return; if (this.$focusWaitTimout && !this.$clickSelection) {
// todo start select after focusWaitTimout passes
return;
}
} }
if (!inSelection || this.$clickSelection || ev.getShiftKey()) { 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) { this.startSelect = function(pos) {

View file

@ -43,7 +43,8 @@ var Range = require("./range").Range;
var Selection = require("./selection").Selection; var Selection = require("./selection").Selection;
var onMouseDown = require("./mouse/multi_select_handler").onMouseDown; var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
var event = require("./lib/event"); 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 // Todo: session.find or editor.findVolatile that returns range
var Search = require("./search").Search; var Search = require("./search").Search;
@ -397,7 +398,7 @@ var Editor = require("./editor").Editor;
this.inMultiSelectMode = true; this.inMultiSelectMode = true;
this.setStyle("multiselect"); this.setStyle("multiselect");
this.keyBinding.addKeyboardHandler(exports.commands.keyboardHandler); this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
this.commands.on("exec", this.$onMultiSelectExec); this.commands.on("exec", this.$onMultiSelectExec);
this.renderer.updateCursor(); this.renderer.updateCursor();
@ -410,7 +411,7 @@ var Editor = require("./editor").Editor;
this.inMultiSelectMode = false; this.inMultiSelectMode = false;
this.unsetStyle("multiselect"); this.unsetStyle("multiselect");
this.keyBinding.removeKeyboardHandler(exports.commands.keyboardHandler); this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
this.commands.removeEventListener("exec", this.$onMultiSelectExec); this.commands.removeEventListener("exec", this.$onMultiSelectExec);
this.renderer.updateCursor(); this.renderer.updateCursor();
@ -420,6 +421,8 @@ var Editor = require("./editor").Editor;
this.$onMultiSelectExec = function(e) { this.$onMultiSelectExec = function(e) {
var command = e.command; var command = e.command;
var editor = e.editor; var editor = e.editor;
if (!editor.multiSelect)
return;
if (!command.multiSelectAction) { if (!command.multiSelectAction) {
command.exec(editor, e.args || {}); command.exec(editor, e.args || {});
editor.multiSelect.addRange(editor.multiSelect.toOrientedRange()); editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
@ -724,7 +727,7 @@ function MultiSelect(editor) {
editor.on("changeSession", exports.onSessionChange.bind(editor)); editor.on("changeSession", exports.onSessionChange.bind(editor));
editor.on("mousedown", onMouseDown); editor.on("mousedown", onMouseDown);
editor.commands.addCommands(exports.commands.defaultCommands); editor.commands.addCommands(commands.defaultCommands);
addAltCursorListeners(editor); addAltCursorListeners(editor);
} }

View file

@ -236,8 +236,8 @@ var Selection = function(session) {
**/ **/
this.selectAll = function() { this.selectAll = function() {
var lastRow = this.doc.getLength() - 1; var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length); this.setSelectionAnchor(0, 0);
this.moveCursorTo(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. * Sets the selection to the provided range.
* *
**/ **/
this.setRange =
this.setSelectionRange = function(range, reverse) { this.setSelectionRange = function(range, reverse) {
if (reverse) { if (reverse) {
this.setSelectionAnchor(range.end.row, range.end.column); this.setSelectionAnchor(range.end.row, range.end.column);

View file

@ -65,7 +65,11 @@ if (location.search)
testNames = location.search.substr(1).split(",") testNames = location.search.substr(1).split(",")
require(testNames, function() { 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) async.list(tests)
.expand(function(test) { .expand(function(test) {
@ -73,6 +77,12 @@ require(testNames, function() {
}, AsyncTest.TestGenerator) }, AsyncTest.TestGenerator)
.run() .run()
.each(function(test, next) { .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"); var node = document.createElement("div");
node.className = test.passed ? "passed" : "failed"; node.className = test.passed ? "passed" : "failed";