forked from kofal.net/zmk
refactor: Improve keymap upgrader
Moved the keymap upgrader to a top-level page like the power profiler to make it more discoverable. It upgrades more things than key codes now, so putting it in the codes category doesn't make much sense. Converted the upgrader code to TypeScript and split it up into smaller files to make it easier to add new upgrade functions. Added upgrade functions to remove/replace "label" properties and rename matrix-transform.h to matrix_transform.h.
This commit is contained in:
27
docs/src/keymap-upgrade/behaviors.ts
Normal file
27
docs/src/keymap-upgrade/behaviors.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { Tree } from "web-tree-sitter";
|
||||
|
||||
import { Devicetree, findCapture } from "./parser";
|
||||
import { TextEdit, getUpgradeEdits } from "./textedit";
|
||||
|
||||
// Map of { "deprecated": "replacement" } behavior names (not including "&" prefixes).
|
||||
const BEHAVIORS = {
|
||||
cp: "kp",
|
||||
inc_dec_cp: "inc_dec_kp",
|
||||
reset: "sys_reset",
|
||||
};
|
||||
|
||||
export function upgradeBehaviors(tree: Tree) {
|
||||
const edits: TextEdit[] = [];
|
||||
|
||||
const query = Devicetree.query("(reference label: (identifier) @ref)");
|
||||
const matches = query.matches(tree.rootNode);
|
||||
|
||||
for (const { captures } of matches) {
|
||||
const node = findCapture("ref", captures);
|
||||
if (node) {
|
||||
edits.push(...getUpgradeEdits(node, BEHAVIORS));
|
||||
}
|
||||
}
|
||||
|
||||
return edits;
|
||||
}
|
||||
Reference in New Issue
Block a user