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

enable vimperator.events.toString() to return keysyms for mouse events

This commit is contained in:
Doug Kearns
2007-09-17 05:37:29 +00:00
parent 6ca297c431
commit 28e15cb66c
3 changed files with 58 additions and 29 deletions

View File

@@ -317,6 +317,7 @@ function Events() //{{{
var key = null; var key = null;
var modifier = ""; var modifier = "";
if (event.ctrlKey) if (event.ctrlKey)
modifier += "C-"; modifier += "C-";
if (event.altKey) if (event.altKey)
@@ -324,33 +325,61 @@ function Events() //{{{
if (event.metaKey) if (event.metaKey)
modifier += "M-"; modifier += "M-";
if (event.charCode == 0) if (event.type == "keypress")
{ {
if (event.shiftKey) if (event.charCode == 0)
modifier += "S-";
for (var i in keyTable)
{ {
if (keyTable[i][0] == event.keyCode) if (event.shiftKey)
modifier += "S-";
for (var i in keyTable)
{ {
key = keyTable[i][1][0]; if (keyTable[i][0] == event.keyCode)
break; {
key = keyTable[i][1][0];
break;
}
} }
} }
// special handling of the Space key
else if (event.charCode == 32)
{
if (event.shiftKey)
modifier += "S-";
key = "Space";
}
// a normal key like a, b, c, 0, etc.
else if (event.charCode > 0)
{
key = String.fromCharCode(event.charCode);
if (modifier.length == 0)
return key;
}
if (key == null)
return null;
} }
// special handling of the Space key else if (event.type == "click" || event.type == "dblclick")
else if (event.charCode == 32)
{ {
if (event.shiftKey) if (event.shiftKey)
modifier += "S-"; modifier += "S-";
key = "Space"; if (event.type == "dblclick")
} modifier += "2-";
// a normal key like a, b, c, 0, etc. // TODO: triple and quadruple click
else if (event.charCode > 0)
{ switch (event.button)
key = String.fromCharCode(event.charCode); {
if (modifier.length == 0) case 0:
return key; key = "LeftMouse"
break;
case 1:
key = "MiddleMouse"
break;
case 2:
key = "RightMouse"
break;
}
} }
if (key == null) if (key == null)
@@ -358,6 +387,7 @@ function Events() //{{{
// a key like F1 is always enclosed in < and > // a key like F1 is always enclosed in < and >
return "<" + modifier + key + ">"; return "<" + modifier + key + ">";
} //}}} } //}}}
this.isAcceptKey = function(key) this.isAcceptKey = function(key)
@@ -432,13 +462,13 @@ function Events() //{{{
{ {
if (!vimperator.modes.passNextKey) if (!vimperator.modes.passNextKey)
{ {
if(vimperator.modes.passAllKeys) if (vimperator.modes.passAllKeys)
{ {
vimperator.modes.passAllKeys = false; vimperator.modes.passAllKeys = false;
return; return;
} }
switch(vimperator.mode) switch (vimperator.mode)
{ {
case vimperator.modes.VISUAL: case vimperator.modes.VISUAL:
if (vimperator.modes.extended & vimperator.modes.TEXTAREA) if (vimperator.modes.extended & vimperator.modes.TEXTAREA)
@@ -454,7 +484,7 @@ function Events() //{{{
break; break;
case vimperator.modes.INSERT: case vimperator.modes.INSERT:
if((vimperator.modes.extended & vimperator.modes.TEXTAREA) && !vimperator.options["insertmode"]) if ((vimperator.modes.extended & vimperator.modes.TEXTAREA) && !vimperator.options["insertmode"])
vimperator.mode = vimperator.modes.TEXTAREA; vimperator.mode = vimperator.modes.TEXTAREA;
else else
vimperator.modes.reset(); vimperator.modes.reset();
@@ -828,13 +858,13 @@ function Events() //{{{
unregister: function() unregister: function()
{ {
if(!this._branch) return; if (!this._branch) return;
this._branch.removeObserver("", this); this._branch.removeObserver("", this);
}, },
observe: function(aSubject, aTopic, aData) observe: function(aSubject, aTopic, aData)
{ {
if(aTopic != "nsPref:changed") return; if (aTopic != "nsPref:changed") return;
// aSubject is the nsIPrefBranch we're observing (after appropriate QI) // aSubject is the nsIPrefBranch we're observing (after appropriate QI)
// aData is the name of the pref that's been changed (relative to aSubject) // aData is the name of the pref that's been changed (relative to aSubject)
switch (aData) switch (aData)

View File

@@ -631,10 +631,6 @@ function CommandLine() //{{{
var key = vimperator.events.toString(event); var key = vimperator.events.toString(event);
// TODO: move to events.toString()
if (event.type == "click" && event.button == 0)
key = "<LeftMouse>"
switch (key) switch (key)
{ {
case ":": case ":":
@@ -680,6 +676,9 @@ function CommandLine() //{{{
break; break;
case "<LeftMouse>": case "<LeftMouse>":
case "<A-LeftMouse>":
case "<C-LeftMouse>":
case "<S-LeftMouse>":
if (/^(end|more(-help)?)-prompt$/.test(event.target.id)) if (/^(end|more(-help)?)-prompt$/.test(event.target.id))
; // fall through ; // fall through
else else

View File

@@ -94,8 +94,8 @@ the terms of any one of the MPL, the GPL or the LGPL.
</listcols> </listcols>
</listbox> </listbox>
<iframe id="vimperator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true" onclick="vimperator.commandline.onMultilineOutputEvent(event)"/> <iframe id="vimperator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
<!--onkeypress="vimperator.commandline.onMultilineOutputEvent(event)"/--> onclick="vimperator.commandline.onMultilineOutputEvent(event)"/>
<hbox id="vimperator-commandline" flex="1" hidden="false"> <hbox id="vimperator-commandline" flex="1" hidden="false">
<label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/> <label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>