karabiner.ts-greg-mods
Version:
Powerful mods for karabiner.ts.
89 lines (88 loc) • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShiftOsmBuilder = void 0;
exports.shiftOsmVarName = shiftOsmVarName;
exports.shiftOsm = shiftOsm;
// A shift one shot modifier layer.
const karabiner_ts_1 = require("karabiner.ts");
const karabiner_extra_1 = require("./karabiner-extra");
const shiftableKeys = [
...karabiner_ts_1.letterKeyCodes,
...karabiner_ts_1.numberKeyCodes,
"⎋",
"-",
"=",
"⌫",
"⇥",
"[",
"]",
"\\",
";",
"'",
",",
".",
"/",
"⏎",
"←",
"↑",
"↓",
"→",
];
/**
* Returns the variable that indicates shift OSM being active.
*/
function shiftOsmVarName() {
return "shift-osm";
}
class ShiftOsmBuilder {
ruleDescription = "⇧ OSM";
layerManipulators = [];
/**
* Sets the description for the rule.
*/
description(description) {
this.ruleDescription = description;
return this;
}
shiftedKey(key) {
const ifOsm = (0, karabiner_ts_1.ifVar)(shiftOsmVarName());
this.layerManipulators.push(...(0, karabiner_ts_1.map)(key, null, "any")
.condition(ifOsm)
.to(key, "l⇧")
.toUnsetVar(shiftOsmVarName())
.build());
return this;
}
manipulators(...manipulators) {
this.layerManipulators.push(...manipulators);
return this;
}
build() {
shiftableKeys.forEach(this.shiftedKey.bind(this));
const ifOsm = (0, karabiner_ts_1.ifVar)(shiftOsmVarName());
const unlessOsm = ifOsm.unless();
const unlessLayer = (0, karabiner_ts_1.ifVar)(karabiner_extra_1.layerVarName).unless();
const setOsm = (0, karabiner_ts_1.toSetVar)(shiftOsmVarName(), 1);
const unsetOsm = (0, karabiner_ts_1.toSetVar)(shiftOsmVarName(), 0);
for (const toggleKey of ["l⇧", "r⇧"]) {
this.manipulators(...(0, karabiner_ts_1.map)(toggleKey, null, "any")
.condition(unlessLayer)
.to(toggleKey)
.toIfAlone({ ...setOsm, conditions: [unlessOsm.build()] })
.toIfAlone({ ...unsetOsm, conditions: [ifOsm.build()] })
.build());
}
return (0, karabiner_ts_1.rule)(this.ruleDescription)
.manipulators(this.layerManipulators)
.build();
}
}
exports.ShiftOsmBuilder = ShiftOsmBuilder;
/**
* Returns a builder for a shift one shot modifier layer.
*
* The layer toggles on and off with a tap on the left or right shift key.
*/
function shiftOsm() {
return new ShiftOsmBuilder();
}