workaround for ApplePressAndHoldEnabled interfering with vim mode
This commit is contained in:
parent
ad9b656c14
commit
e6655172ef
1 changed files with 37 additions and 8 deletions
|
|
@ -43,6 +43,7 @@ var keyUtil = require("../lib/keys");
|
||||||
var cmds = require("./vim/commands");
|
var cmds = require("./vim/commands");
|
||||||
var coreCommands = cmds.coreCommands;
|
var coreCommands = cmds.coreCommands;
|
||||||
var util = require("./vim/maps/util");
|
var util = require("./vim/maps/util");
|
||||||
|
var useragent = require("../lib/useragent");
|
||||||
|
|
||||||
var startCommands = {
|
var startCommands = {
|
||||||
"i": {
|
"i": {
|
||||||
|
|
@ -66,6 +67,28 @@ var startCommands = {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handler = {
|
exports.handler = {
|
||||||
|
// workaround for j not repeating with `defaults write -g ApplePressAndHoldEnabled -bool true`
|
||||||
|
handleMacRepeat: function(data, hashId, key) {
|
||||||
|
if (hashId == -1) {
|
||||||
|
// record key
|
||||||
|
data.inputChar = key;
|
||||||
|
data.lastEvent = "input";
|
||||||
|
} else if (data.inputChar && data.$lastHash == hashId && data.$lastKey == key) {
|
||||||
|
// check for repeated keypress
|
||||||
|
if (data.lastEvent == "input") {
|
||||||
|
data.lastEvent = "input1";
|
||||||
|
} else if (data.lastEvent == "input1") {
|
||||||
|
// simulate textinput
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// reset
|
||||||
|
data.$lastHash = hashId;
|
||||||
|
data.$lastKey = key;
|
||||||
|
data.lastEvent = "keypress";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
handleKeyboard: function(data, hashId, key, keyCode, e) {
|
handleKeyboard: function(data, hashId, key, keyCode, e) {
|
||||||
// ignore command keys (shift, ctrl etc.)
|
// ignore command keys (shift, ctrl etc.)
|
||||||
if (hashId != 0 && (key == "" || key == "\x00"))
|
if (hashId != 0 && (key == "" || key == "\x00"))
|
||||||
|
|
@ -73,19 +96,25 @@ exports.handler = {
|
||||||
|
|
||||||
if (hashId == 1)
|
if (hashId == 1)
|
||||||
key = "ctrl-" + key;
|
key = "ctrl-" + key;
|
||||||
|
|
||||||
if (data.state == "start") {
|
if (data.state == "start") {
|
||||||
|
if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) {
|
||||||
|
hashId = -1;
|
||||||
|
key = data.inputChar;
|
||||||
|
}
|
||||||
|
|
||||||
if (hashId == -1 || hashId == 1) {
|
if (hashId == -1 || hashId == 1) {
|
||||||
if (cmds.inputBuffer.idle && startCommands[key])
|
if (cmds.inputBuffer.idle && startCommands[key])
|
||||||
return startCommands[key];
|
return startCommands[key];
|
||||||
|
return {
|
||||||
return { command: {
|
command: {
|
||||||
exec: function(editor) {cmds.inputBuffer.push(editor, key);}
|
exec: function(editor) {cmds.inputBuffer.push(editor, key);}
|
||||||
} };
|
}
|
||||||
} // wait for input
|
};
|
||||||
else if (key.length == 1 && (hashId == 0 || hashId == 4)) { //no modifier || shift
|
} // if no modifier || shift: wait for input.
|
||||||
|
else if (key.length == 1 && (hashId == 0 || hashId == 4)) {
|
||||||
return {command: "null", passEvent: true};
|
return {command: "null", passEvent: true};
|
||||||
} else if (key == "esc") {
|
} else if (key == "esc" && hashId == 0) {
|
||||||
return {command: coreCommands.stop};
|
return {command: coreCommands.stop};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue