mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-04 21:24:12 +01:00
- fixed generating artificial firefox commands with feedkeys()/:norm/:map
- home/end/etc. keys work again in the location bar - <c-v><c-k>, etc. work again to focus special form fields - small formatting improvements
This commit is contained in:
@@ -25,16 +25,19 @@ function Editor() //{{{
|
||||
|
||||
function editor()
|
||||
{
|
||||
return window.document.commandDispatcher.focusedElement;
|
||||
var editor = window.document.commandDispatcher.focusedElement;
|
||||
if (editor && editor.mInputField)
|
||||
editor = editor.mInputField;
|
||||
return editor;
|
||||
}
|
||||
|
||||
function getController()
|
||||
{
|
||||
var el = window.document.commandDispatcher.focusedElement;
|
||||
if (!el || !el.controllers)
|
||||
var editor = editor();
|
||||
if (!editor || !editor.controllers)
|
||||
return null;
|
||||
|
||||
return el.controllers.getControllerAt(0);
|
||||
return editor.controllers.getControllerAt(0);
|
||||
}
|
||||
|
||||
this.line = function()
|
||||
|
||||
@@ -231,10 +231,11 @@ function Events() //{{{
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
this.wantsModeReset = true; // used in onFocusChange since Firefox is so buggy here
|
||||
|
||||
this.destroy = function()
|
||||
{
|
||||
// BIG TODO: removeEventListeners() to avoid mem leaks
|
||||
// removeEventListeners() to avoid mem leaks
|
||||
window.dump("TODO: remove all eventlisteners\n");
|
||||
|
||||
getBrowser().removeProgressListener(this.progressListener);
|
||||
@@ -243,6 +244,9 @@ function Events() //{{{
|
||||
window.removeEventListener("popuphidden", exitPopupMode, true);
|
||||
window.removeEventListener("DOMMenuBarActive", enterMenuMode, true);
|
||||
window.removeEventListener("DOMMenuBarInactive", exitMenuMode, true);
|
||||
|
||||
window.removeEventListener("keypress", this.onKeyPress, true);
|
||||
window.removeEventListener("keydown", this.onKeyDown, true);
|
||||
}
|
||||
|
||||
// This method pushes keys into the event queue from vimperator
|
||||
@@ -253,7 +257,7 @@ function Events() //{{{
|
||||
// if you want < to be taken literally, prepend it with a \\
|
||||
this.feedkeys = function(keys)
|
||||
{
|
||||
var doc = window.content.document;
|
||||
var doc = window.document;
|
||||
var view = window.document.defaultView;
|
||||
var escapeKey = false; // \ to escape some special keys
|
||||
|
||||
@@ -295,13 +299,13 @@ function Events() //{{{
|
||||
i += matches[0].length + 1;
|
||||
}
|
||||
}
|
||||
var evt = doc.createEvent('KeyEvents');
|
||||
evt.initKeyEvent('keypress', true, true, view, ctrl, alt, shift, meta, keyCode, charCode );
|
||||
|
||||
var elem = window.document.commandDispatcher.focusedElement;
|
||||
if (!elem)
|
||||
elem = window;
|
||||
elem = window.content;
|
||||
|
||||
var evt = doc.createEvent("KeyEvents");
|
||||
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode );
|
||||
elem.dispatchEvent(evt);
|
||||
}
|
||||
}
|
||||
@@ -401,8 +405,12 @@ function Events() //{{{
|
||||
|
||||
// argument "event" is delibarately not used, as i don't seem to have
|
||||
// access to the real focus target
|
||||
//
|
||||
// the ugly wantsModeReset is needed, because firefox generates a massive
|
||||
// amount of focus changes for things like <C-v><C-k> (focusing the search field)
|
||||
this.onFocusChange = function(event)
|
||||
{
|
||||
// command line has it's own focus change handler
|
||||
if (vimperator.mode == vimperator.modes.COMMAND_LINE)
|
||||
return;
|
||||
|
||||
@@ -413,11 +421,13 @@ function Events() //{{{
|
||||
if (elem && elem instanceof HTMLInputElement &&
|
||||
(elem.type.toLowerCase() == "text" || elem.type.toLowerCase() == "password"))
|
||||
{
|
||||
this.wantsModeReset = false;
|
||||
vimperator.mode = vimperator.modes.INSERT;
|
||||
vimperator.buffer.lastInputField = elem;
|
||||
}
|
||||
else if (elem && elem instanceof HTMLTextAreaElement)
|
||||
{
|
||||
this.wantsModeReset = false;
|
||||
if (vimperator.options["insertmode"])
|
||||
vimperator.modes.set(vimperator.modes.INSERT, vimperator.modes.TEXTAREA);
|
||||
else if (elem.selectionEnd - elem.selectionStart > 0)
|
||||
@@ -429,7 +439,13 @@ function Events() //{{{
|
||||
else if (vimperator.mode == vimperator.modes.INSERT ||
|
||||
vimperator.mode == vimperator.modes.TEXTAREA ||
|
||||
vimperator.mode == vimperator.modes.VISUAL)
|
||||
vimperator.modes.reset();
|
||||
{
|
||||
this.wantsModeReset = true;
|
||||
setTimeout(function() {
|
||||
if (vimperator.events.wantsModeReset)
|
||||
vimperator.modes.reset();
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
this.onSelectionChange = function(event)
|
||||
@@ -512,7 +528,6 @@ function Events() //{{{
|
||||
|
||||
var stop = true; // set to false if we should NOT consume this event but let also firefox handle it
|
||||
|
||||
|
||||
// menus have their own command handlers
|
||||
if (vimperator.modes.extended & vimperator.modes.MENU)
|
||||
return true;
|
||||
@@ -740,7 +755,6 @@ function Events() //{{{
|
||||
if (vimperator.modes.passNextKey ^ vimperator.modes.passAllKeys || isFormElemFocused())
|
||||
return true;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,10 +51,13 @@ const vimperator = (function() //{{{
|
||||
if (WINDOWS)
|
||||
path = path.replace('/', '\\', 'g');
|
||||
|
||||
// expand "~" to HOME (USERPROFILE or HOMEDRIVE\HOMEPATH on Windows if HOME is not set)
|
||||
// expand "~" to VIMPERATOR_HOME or HOME (USERPROFILE or HOMEDRIVE\HOMEPATH on Windows if HOME is not set)
|
||||
if (/^~/.test(path))
|
||||
{
|
||||
var home = environment_service.get("HOME");
|
||||
var home = environment_service.get("VIMPERATOR_HOME");
|
||||
|
||||
if (!home)
|
||||
home = environment_service.get("HOME");
|
||||
|
||||
if (WINDOWS && !home)
|
||||
home = environment_service.get("USERPROFILE") ||
|
||||
@@ -250,56 +253,59 @@ const vimperator = (function() //{{{
|
||||
// partial sixth level expression evaluation
|
||||
eval: function(string)
|
||||
{
|
||||
string = string.toString().replace(/^\s*/, '').replace(/\s*$/, '');
|
||||
string = string.toString().replace(/^\s*/, "").replace(/\s*$/, "");
|
||||
var match = string.match(/^&(\w+)/);
|
||||
if (match)
|
||||
{
|
||||
var opt = this.options.get(match[1]);
|
||||
if (!opt)
|
||||
{
|
||||
this.echoerr('E113: Unknown option: ' + match[1]);
|
||||
this.echoerr("E113: Unknown option: " + match[1]);
|
||||
return;
|
||||
}
|
||||
var type = opt.type;
|
||||
var value = opt.getter();
|
||||
if (type != 'boolean' && type != 'number')
|
||||
if (type != "boolean" && type != "number")
|
||||
value = value.toString();
|
||||
return value;
|
||||
}
|
||||
|
||||
// String
|
||||
if (match = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
|
||||
else if (match = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
|
||||
{
|
||||
if (match)
|
||||
return match[2].toString();
|
||||
else
|
||||
{
|
||||
this.echoerr('E115: Missing quote: ' + string);
|
||||
this.echoerr("E115: Missing quote: " + string);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Number
|
||||
if (match = string.match(/^(\d+)$/))
|
||||
else if (match = string.match(/^(\d+)$/))
|
||||
{
|
||||
return parseInt(match[1]);
|
||||
}
|
||||
|
||||
var reference = this.variableReference(string);
|
||||
if (!reference[0])
|
||||
this.echoerr('E121: Undefined variable: ' + string);
|
||||
this.echoerr("E121: Undefined variable: " + string);
|
||||
else
|
||||
return reference[0][reference[1]];
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
variableReference: function(string)
|
||||
{
|
||||
if (!string) return [null, null, null];
|
||||
if (match = string.match(/^([bwtglsv]):(\w+)/)) // Variable
|
||||
if (!string)
|
||||
return [null, null, null];
|
||||
|
||||
if (match = string.match(/^([bwtglsv]):(\w+)/)) // Variable
|
||||
{
|
||||
// Other variables should be implemented
|
||||
if (match[1] == 'g')
|
||||
if (match[1] == "g")
|
||||
{
|
||||
if (match[2] in this.globalVariables)
|
||||
return [this.globalVariables, match[2], match[1]];
|
||||
@@ -307,12 +313,12 @@ const vimperator = (function() //{{{
|
||||
return [null, match[2], match[1]];
|
||||
}
|
||||
}
|
||||
else // Global variable
|
||||
else // Global variable
|
||||
{
|
||||
if (string in this.globalVariables)
|
||||
return [this.globalVariables, string, 'g'];
|
||||
return [this.globalVariables, string, "g"];
|
||||
else
|
||||
return [null, string, 'g'];
|
||||
return [null, string, "g"];
|
||||
}
|
||||
},
|
||||
|
||||
@@ -340,12 +346,13 @@ const vimperator = (function() //{{{
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
value = '';
|
||||
value = "";
|
||||
}
|
||||
|
||||
string += i + ': ' + value + '\n';
|
||||
string += i + ": " + value + "\n";
|
||||
}
|
||||
vimperator.log(string, level);
|
||||
return string;
|
||||
},
|
||||
|
||||
// open one or more URLs
|
||||
|
||||
Reference in New Issue
Block a user