mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 03:17:58 +01:00
Allow things like :noremap dd d<Nop>
This commit is contained in:
@@ -418,14 +418,14 @@ function Events() //{{{
|
|||||||
{
|
{
|
||||||
str = str.toLowerCase();
|
str = str.toLowerCase();
|
||||||
|
|
||||||
for (let i = 0; i < keyTable.length; i++)
|
for (let [,key] in Iterator(keyTable))
|
||||||
{
|
{
|
||||||
for (let j = 0; j < keyTable[i][1].length; j++)
|
for (let [,name] in Iterator(key[1]))
|
||||||
{
|
{
|
||||||
// we don't store lowercase keys in the keyTable, because we
|
// we don't store lowercase keys in the keyTable, because we
|
||||||
// also need to get good looking strings for the reverse action
|
// also need to get good looking strings for the reverse action
|
||||||
if (keyTable[i][1][j].toLowerCase() == str)
|
if (name.toLowerCase() == str)
|
||||||
return keyTable[i][0];
|
return key[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,35 +871,40 @@ function Events() //{{{
|
|||||||
{
|
{
|
||||||
noremap = !!noremap;
|
noremap = !!noremap;
|
||||||
|
|
||||||
for (var i = 0; i < keys.length; i++)
|
for (let i = 0; i < keys.length; i++)
|
||||||
{
|
{
|
||||||
var charCode = keys.charCodeAt(i);
|
let charCode = keys.charCodeAt(i);
|
||||||
var keyCode = 0;
|
let keyCode = 0;
|
||||||
var shift = false, ctrl = false, alt = false, meta = false;
|
let shift = false, ctrl = false, alt = false, meta = false;
|
||||||
|
let string = null;
|
||||||
|
|
||||||
//if (charCode == 92) // the '\' key FIXME: support the escape key
|
//if (charCode == 92) // the '\' key FIXME: support the escape key
|
||||||
if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
|
if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
|
||||||
{
|
{
|
||||||
var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
|
let [match, modifier, keyname] = keys.match(/<([CSMA]-)*(.+?)>/i) || [];
|
||||||
if (matches && matches[2])
|
if (keyname)
|
||||||
{
|
{
|
||||||
if (matches[1]) // check for modifiers
|
if (modifier) // check for modifiers
|
||||||
{
|
{
|
||||||
ctrl = /[cC]-/.test(matches[1]);
|
ctrl = /[C]-/i.test(matches[1]);
|
||||||
alt = /[aA]-/.test(matches[1]);
|
alt = /[A]-/i.test(matches[1]);
|
||||||
shift = /[sS]-/.test(matches[1]);
|
shift = /[S]-/i.test(matches[1]);
|
||||||
meta = /[mM]-/.test(matches[1]);
|
meta = /[M]-/i.test(matches[1]);
|
||||||
}
|
}
|
||||||
if (matches[2].length == 1)
|
if (keyname.length == 1)
|
||||||
{
|
{
|
||||||
if (!ctrl && !alt && !shift && !meta)
|
if (!ctrl && !alt && !shift && !meta)
|
||||||
return false; // an invalid key like <a>
|
return false; // an invalid key like <a>
|
||||||
charCode = matches[2].charCodeAt(0);
|
charCode = matches[2].charCodeAt(0);
|
||||||
}
|
}
|
||||||
else if (matches[2].toLowerCase() == "space")
|
else if (keyname.toLowerCase() == "space")
|
||||||
{
|
{
|
||||||
charCode = 32;
|
charCode = 32;
|
||||||
}
|
}
|
||||||
|
else if (keyname.toLowerCase() == "nop")
|
||||||
|
{
|
||||||
|
string = "<Nop>";
|
||||||
|
}
|
||||||
else if (keyCode = getKeyCode(matches[2]))
|
else if (keyCode = getKeyCode(matches[2]))
|
||||||
{
|
{
|
||||||
charCode = 0;
|
charCode = 0;
|
||||||
@@ -909,7 +914,7 @@ function Events() //{{{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i += matches[0].length + 1;
|
i += match.length - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // a simple key
|
else // a simple key
|
||||||
@@ -918,15 +923,23 @@ function Events() //{{{
|
|||||||
shift = (keys[i] >= "A" && keys[i] <= "Z");
|
shift = (keys[i] >= "A" && keys[i] <= "Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
var elem = window.document.commandDispatcher.focusedElement;
|
let elem = window.document.commandDispatcher.focusedElement;
|
||||||
if (!elem)
|
if (!elem)
|
||||||
elem = window.content;
|
elem = window.content;
|
||||||
|
|
||||||
var evt = doc.createEvent("KeyEvents");
|
let evt = doc.createEvent("KeyEvents");
|
||||||
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
|
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
|
||||||
evt.noremap = noremap;
|
evt.noremap = noremap;
|
||||||
evt.isMacro = true;
|
evt.isMacro = true;
|
||||||
elem.dispatchEvent(evt);
|
if (string)
|
||||||
|
{
|
||||||
|
evt.liberatorString = string;
|
||||||
|
events.onKeyPress(evt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elem.dispatchEvent(evt);
|
||||||
|
}
|
||||||
if (!this.feedingKeys)
|
if (!this.feedingKeys)
|
||||||
break;
|
break;
|
||||||
// stop feeding keys if page loading failed
|
// stop feeding keys if page loading failed
|
||||||
@@ -952,10 +965,13 @@ function Events() //{{{
|
|||||||
toString: function (event)
|
toString: function (event)
|
||||||
{
|
{
|
||||||
if (!event)
|
if (!event)
|
||||||
return;
|
return "[object Mappings]";
|
||||||
|
|
||||||
var key = null;
|
if (event.liberatorString)
|
||||||
var modifier = "";
|
return event.liberatorString;
|
||||||
|
|
||||||
|
let key = null;
|
||||||
|
let modifier = "";
|
||||||
|
|
||||||
if (event.ctrlKey)
|
if (event.ctrlKey)
|
||||||
modifier += "C-";
|
modifier += "C-";
|
||||||
@@ -1210,7 +1226,7 @@ function Events() //{{{
|
|||||||
// the commandline has focus
|
// the commandline has focus
|
||||||
onKeyPress: function (event)
|
onKeyPress: function (event)
|
||||||
{
|
{
|
||||||
var key = events.toString(event);
|
let key = events.toString(event);
|
||||||
if (!key)
|
if (!key)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -1253,9 +1269,9 @@ function Events() //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var stop = true; // set to false if we should NOT consume this event but let Firefox handle it
|
let stop = true; // set to false if we should NOT consume this event but let Firefox handle it
|
||||||
|
|
||||||
var win = document.commandDispatcher.focusedWindow;
|
let win = document.commandDispatcher.focusedWindow;
|
||||||
if (win && win.document.designMode == "on" && !config.isComposeWindow)
|
if (win && win.document.designMode == "on" && !config.isComposeWindow)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1362,14 +1378,21 @@ function Events() //{{{
|
|||||||
if (liberator.mode == modes.CUSTOM)
|
if (liberator.mode == modes.CUSTOM)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var countStr = input.buffer.match(/^[0-9]*/)[0];
|
let countStr = input.buffer.match(/^[0-9]*/)[0];
|
||||||
var candidateCommand = (input.buffer + key).replace(countStr, "");
|
let candidateCommand = (input.buffer + key).replace(countStr, "");
|
||||||
var map;
|
let map;
|
||||||
if (event.noremap)
|
if (event.noremap)
|
||||||
map = mappings.getDefault(liberator.mode, candidateCommand);
|
map = mappings.getDefault(liberator.mode, candidateCommand);
|
||||||
else
|
else
|
||||||
map = mappings.get(liberator.mode, candidateCommand);
|
map = mappings.get(liberator.mode, candidateCommand);
|
||||||
|
|
||||||
|
let candidates = mappings.getCandidates(liberator.mode, candidateCommand);
|
||||||
|
if (candidates.length == 0 && !map)
|
||||||
|
{
|
||||||
|
map = input.pendingMap;
|
||||||
|
input.pendingMap = null;
|
||||||
|
}
|
||||||
|
|
||||||
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
||||||
if (/^[1-9][0-9]*$/.test(input.buffer + key))
|
if (/^[1-9][0-9]*$/.test(input.buffer + key))
|
||||||
{
|
{
|
||||||
@@ -1386,7 +1409,7 @@ function Events() //{{{
|
|||||||
{
|
{
|
||||||
input.buffer = "";
|
input.buffer = "";
|
||||||
inputBufferLength = 0;
|
inputBufferLength = 0;
|
||||||
var tmp = input.pendingArgMap; // must be set to null before .execute; if not
|
let tmp = input.pendingArgMap; // must be set to null before .execute; if not
|
||||||
input.pendingArgMap = null; // v.input.pendingArgMap is still 'true' also for new feeded keys
|
input.pendingArgMap = null; // v.input.pendingArgMap is still 'true' also for new feeded keys
|
||||||
if (key != "<Esc>" && key != "<C-[>")
|
if (key != "<Esc>" && key != "<C-[>")
|
||||||
{
|
{
|
||||||
@@ -1399,8 +1422,7 @@ function Events() //{{{
|
|||||||
// only follow a map if there isn't a longer possible mapping
|
// only follow a map if there isn't a longer possible mapping
|
||||||
// (allows you to do :map z yy, when zz is a longer mapping than z)
|
// (allows you to do :map z yy, when zz is a longer mapping than z)
|
||||||
// TODO: map.rhs is only defined for user defined commands, should add a "isDefault" property
|
// TODO: map.rhs is only defined for user defined commands, should add a "isDefault" property
|
||||||
else if (map && !skipMap && (map.rhs ||
|
else if (map && !skipMap && (map.rhs || candidates.length == 0))
|
||||||
mappings.getCandidates(liberator.mode, candidateCommand).length == 0))
|
|
||||||
{
|
{
|
||||||
input.count = parseInt(countStr, 10);
|
input.count = parseInt(countStr, 10);
|
||||||
if (isNaN(input.count))
|
if (isNaN(input.count))
|
||||||
@@ -1436,13 +1458,14 @@ function Events() //{{{
|
|||||||
if (modes.isReplaying && !waitForPageLoaded())
|
if (modes.isReplaying && !waitForPageLoaded())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var ret = map.execute(null, input.count);
|
let ret = map.execute(null, input.count);
|
||||||
if (map.flags & Mappings.flags.ALLOW_EVENT_ROUTING && ret)
|
if (map.flags & Mappings.flags.ALLOW_EVENT_ROUTING && ret)
|
||||||
stop = false;
|
stop = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mappings.getCandidates(liberator.mode, candidateCommand).length > 0 && !skipMap)
|
else if (mappings.getCandidates(liberator.mode, candidateCommand).length > 0 && !skipMap)
|
||||||
{
|
{
|
||||||
|
input.pendingMap = map;
|
||||||
input.buffer += key;
|
input.buffer += key;
|
||||||
inputBufferLength++;
|
inputBufferLength++;
|
||||||
}
|
}
|
||||||
@@ -1465,6 +1488,7 @@ function Events() //{{{
|
|||||||
input.buffer = "";
|
input.buffer = "";
|
||||||
input.pendingArgMap = null;
|
input.pendingArgMap = null;
|
||||||
input.pendingMotionMap = null;
|
input.pendingMotionMap = null;
|
||||||
|
input.pendingMap = null;
|
||||||
|
|
||||||
if (key != "<Esc>" && key != "<C-[>")
|
if (key != "<Esc>" && key != "<C-[>")
|
||||||
{
|
{
|
||||||
@@ -1489,7 +1513,7 @@ function Events() //{{{
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
var motionMap = (input.pendingMotionMap && input.pendingMotionMap.names[0]) || "";
|
let motionMap = (input.pendingMotionMap && input.pendingMotionMap.names[0]) || "";
|
||||||
statusline.updateInputBuffer(motionMap + input.buffer);
|
statusline.updateInputBuffer(motionMap + input.buffer);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1369,9 +1369,9 @@ function ItemList(id) //{{{
|
|||||||
context.cache.nodes = [];
|
context.cache.nodes = [];
|
||||||
dom(<div key="root">
|
dom(<div key="root">
|
||||||
<div highlight="Completions">
|
<div highlight="Completions">
|
||||||
{context.createRow(context.title || [], "CompTitle")}
|
{ context.createRow(context.title || [], "CompTitle") }
|
||||||
</div>
|
</div>
|
||||||
<div key="message" highlight="CompMsg" style="display: none"/>
|
<div key="message" highlight="CompMsg"/>
|
||||||
<div key="up" highlight="CompLess"/>
|
<div key="up" highlight="CompLess"/>
|
||||||
<div key="items" highlight="Completions"/>
|
<div key="items" highlight="Completions"/>
|
||||||
<div key="waiting" highlight="CompMsg">Waiting...</div>
|
<div key="waiting" highlight="CompMsg">Waiting...</div>
|
||||||
@@ -1499,32 +1499,32 @@ function ItemList(id) //{{{
|
|||||||
|
|
||||||
//let now = Date.now();
|
//let now = Date.now();
|
||||||
|
|
||||||
|
let sel = selIndex;
|
||||||
let len = items.allItems.items.length;
|
let len = items.allItems.items.length;
|
||||||
|
let newOffset = startIndex;
|
||||||
|
|
||||||
if (index == -1 || index == len) // wrapped around
|
if (index == -1 || index == len) // wrapped around
|
||||||
{
|
{
|
||||||
if (selIndex >= 0)
|
if (selIndex < 0)
|
||||||
getCompletion(selIndex).removeAttribute("selected");
|
newOffset = 0;
|
||||||
else // list is shown the first time
|
|
||||||
fill(0);
|
|
||||||
selIndex = -1;
|
selIndex = -1;
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (index <= startIndex + CONTEXT_LINES)
|
||||||
|
newOffset = index - CONTEXT_LINES;
|
||||||
|
if (index >= endIndex - CONTEXT_LINES)
|
||||||
|
newOffset = index + CONTEXT_LINES - maxItems + 1;
|
||||||
|
|
||||||
|
newOffset = Math.min(newOffset, len - maxItems);
|
||||||
|
newOffset = Math.max(newOffset, 0);
|
||||||
|
|
||||||
|
selIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find start index
|
if (sel > -1)
|
||||||
let newOffset = startIndex;
|
|
||||||
if (index >= endIndex - CONTEXT_LINES)
|
|
||||||
newOffset = index + CONTEXT_LINES - maxItems + 1;
|
|
||||||
else if (index <= startIndex + CONTEXT_LINES)
|
|
||||||
newOffset = index - CONTEXT_LINES;
|
|
||||||
|
|
||||||
newOffset = Math.min(newOffset, len - maxItems);
|
|
||||||
newOffset = Math.max(newOffset, 0);
|
|
||||||
|
|
||||||
if (selIndex > -1)
|
|
||||||
getCompletion(selIndex).removeAttribute("selected");
|
getCompletion(selIndex).removeAttribute("selected");
|
||||||
|
fill(newOffset);
|
||||||
let res = fill(newOffset);
|
|
||||||
selIndex = index;
|
|
||||||
getCompletion(index).setAttribute("selected", "true");
|
getCompletion(index).setAttribute("selected", "true");
|
||||||
|
|
||||||
//if (index == 0)
|
//if (index == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user