1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 10:37:59 +01:00

Re-enable Text Edit mode in non-Google editable windows.

This commit is contained in:
Kris Maglione
2011-08-06 15:56:16 -04:00
parent ff0c5af5db
commit 85dfd5becd
3 changed files with 35 additions and 27 deletions

View File

@@ -62,7 +62,7 @@ var Editor = Module("editor", {
// count is optional, defaults to 1 // count is optional, defaults to 1
executeCommand: function (cmd, count) { executeCommand: function (cmd, count) {
let editor = Editor.getEditor(null); let editor = Editor.getEditor(null);
let controller = Editor.getController(); let controller = Editor.getController(cmd);
dactyl.assert(callable(cmd) || dactyl.assert(callable(cmd) ||
controller && controller &&
controller.supportsCommand(cmd) && controller.supportsCommand(cmd) &&
@@ -355,12 +355,13 @@ var Editor = Module("editor", {
} }
}, },
getController: function () { getController: function (cmd) {
let ed = dactyl.focusedElement; let win = document.commandDispatcher.focusedWindow;
let ed = dactyl.focusedElement || Editor.getEditor(win) && win;
if (!ed || !ed.controllers) if (!ed || !ed.controllers)
return null; return null;
return ed.controllers.getControllerForCommand("cmd_beginLine"); return ed.controllers.getControllerForCommand(cmd || "cmd_beginLine");
} }
}, { }, {
mappings: function () { mappings: function () {
@@ -395,7 +396,7 @@ var Editor = Module("editor", {
true)); true));
} }
let controller = buffer.selectionController; let controller = util.selectionController(document.commandDispatcher.focusedWindow);
let sel = controller.getSelection(controller.SELECTION_NORMAL); let sel = controller.getSelection(controller.SELECTION_NORMAL);
if (!sel.rangeCount) // Hack. if (!sel.rangeCount) // Hack.
fixSelection(); fixSelection();
@@ -410,42 +411,38 @@ var Editor = Module("editor", {
} }
} }
mappings.add([modes.CARET], keys, description,
function ({ count }) {
if (!count)
count = 1;
while (count--)
caretExecute(false, true);
},
extraInfo);
mappings.add([modes.VISUAL], keys, description, mappings.add([modes.VISUAL], keys, description,
function ({ count }) { function ({ count }) {
if (!count) if (!count)
count = 1; count = 1;
let caret = !dactyl.focusedElement;
let editor_ = Editor.getEditor(null); let editor_ = Editor.getEditor(null);
let controller = buffer.selectionController; let controller = buffer.selectionController;
while (count-- && modes.main == modes.VISUAL) { while (count-- && modes.main == modes.VISUAL) {
if (editor.isTextEdit) { if (caret)
caretExecute(true, true);
else {
if (callable(visualTextEditCommand)) if (callable(visualTextEditCommand))
visualTextEditCommand(editor_); visualTextEditCommand(editor_);
else else
editor.executeCommand(visualTextEditCommand); editor.executeCommand(visualTextEditCommand);
} }
else
caretExecute(true, true);
} }
}, },
extraInfo); extraInfo);
mappings.add([modes.TEXT_EDIT, modes.OPERATOR], keys, description, mappings.add([modes.CARET, modes.TEXT_EDIT, modes.OPERATOR], keys, description,
function ({ count }) { function ({ count }) {
if (!count) if (!count)
count = 1; count = 1;
editor.executeCommand(textEditCommand, count); if (Editor.getEditor(null))
editor.executeCommand(textEditCommand, count);
else {
while (count--)
caretExecute(false, true);
}
}, },
extraInfo); extraInfo);
} }
@@ -618,8 +615,11 @@ var Editor = Module("editor", {
bind(["<C-t>"], "Edit text field in Vi mode", bind(["<C-t>"], "Edit text field in Vi mode",
function () { function () {
dactyl.assert(dactyl.focusedElement); dactyl.assert(!editor.isTextEdit && Editor.getEditor(null));
dactyl.assert(!editor.isTextEdit); dactyl.assert(dactyl.focusedElement ||
let (f = document.commandDispatcher.focusedWindow.frameElement)
f && Hints.isVisible(f, true));
modes.push(modes.TEXT_EDIT); modes.push(modes.TEXT_EDIT);
}); });

View File

@@ -1077,12 +1077,18 @@ var Hints = Module("hints", {
this.hintSession = HintSession(mode, opts); this.hintSession = HintSession(mode, opts);
} }
}, { }, {
isVisible: function isVisible(elem) { isVisible: function isVisible(elem, offScreen) {
let rect = elem.getBoundingClientRect(); let rect = elem.getBoundingClientRect();
if (!rect.width || !rect.height) if (!rect.width || !rect.height)
if (!Array.some(elem.childNodes, function (elem) elem instanceof Element && util.computedStyle(elem).float != "none" && isVisible(elem))) if (!Array.some(elem.childNodes, function (elem) elem instanceof Element && util.computedStyle(elem).float != "none" && isVisible(elem)))
return false; return false;
let win = elem.ownerDocument.defaultView;
if (offScreen && (rect.top + win.scrollY < 0 || rect.left + win.scrollX < 0 ||
rect.bottom + win.scrollY > win.scrolMaxY + win.innerHeight ||
rect.right + win.scrollX > win.scrolMaxX + win.innerWidth))
return false;
let computedStyle = util.computedStyle(elem, null); let computedStyle = util.computedStyle(elem, null);
if (computedStyle.visibility != "visible" || computedStyle.display == "none") if (computedStyle.visibility != "visible" || computedStyle.display == "none")
return false; return false;

View File

@@ -369,10 +369,12 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
prefToArg: function (pref) pref.replace(/.*\./, "").toLowerCase(), prefToArg: function (pref) pref.replace(/.*\./, "").toLowerCase(),
iterCookies: function iterCookies(host) { iterCookies: function iterCookies(host) {
let iterator = host ? services.cookies.getCookiesFromHost(host) for (let c in iter(services.cookies)) {
: services.cookies; c.QueryInterface(Ci.nsICookie2);
for (let c in iter(iterator)) if (!host || util.isSubdomain(c.rawHost, host) || c.host[0] == "." && c.host.length < host.length && host.indexOf(c.host) == host.length - c.host.length)
yield c.QueryInterface(Ci.nsICookie2); yield c;
}
}, },
iterPermissions: function iterPermissions(host) { iterPermissions: function iterPermissions(host) {
for (let p in iter(services.permissions)) { for (let p in iter(services.permissions)) {