@cloudvoyant/helical-ui 0.20.1 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4688 -47
- package/dist/index.d.cts +376 -3
- package/dist/index.d.ts +376 -3
- package/dist/index.js +4614 -26
- package/package.json +6 -1
- package/src/components.css +40 -0
- package/src/theme.css +3 -0
package/dist/index.js
CHANGED
|
@@ -414,7 +414,7 @@ var navbarMenuRootBase = "group/nav-menu relative flex max-w-max flex-1 items-ce
|
|
|
414
414
|
var navbarMenuListBase = "group flex flex-1 list-none items-center justify-center gap-1";
|
|
415
415
|
var navbarMenuItemBase = "relative";
|
|
416
416
|
var navbarMenuTriggerStyle = cva8(
|
|
417
|
-
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-3 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent/50 data-[state=open]:text-accent-foreground data-[state=open]:hover:bg-accent data-[state=open]:focus:bg-accent",
|
|
417
|
+
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-3 text-sm font-medium outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent/50 data-[state=open]:text-accent-foreground data-[state=open]:hover:bg-accent data-[state=open]:focus:bg-accent",
|
|
418
418
|
{
|
|
419
419
|
variants: {
|
|
420
420
|
density: {
|
|
@@ -1207,6 +1207,3649 @@ var listboxItemIndicatorBase = "absolute inset-y-0 end-2 flex items-center justi
|
|
|
1207
1207
|
var listboxInputBase = "w-full border-b border-input bg-transparent px-2.5 py-1.5 text-sm outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/30";
|
|
1208
1208
|
var listboxEmptyBase = "px-2 py-6 text-center text-sm text-muted-foreground";
|
|
1209
1209
|
var listboxLabelBase = "px-2 py-1.5 text-xs font-semibold text-muted-foreground";
|
|
1210
|
+
var listboxItemGroupBase = "flex flex-col py-1 first:pt-0 last:pb-0";
|
|
1211
|
+
var listboxItemGroupLabelBase = "px-2 py-1 text-[11px] font-semibold tracking-wider text-muted-foreground uppercase select-none";
|
|
1212
|
+
|
|
1213
|
+
// src/kbd.ts
|
|
1214
|
+
import { cva as cva19 } from "class-variance-authority";
|
|
1215
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
1216
|
+
var kbdVariants = cva19(
|
|
1217
|
+
"inline-flex shrink-0 items-center justify-center gap-0.5 rounded border font-mono font-medium leading-none tracking-tight select-none",
|
|
1218
|
+
{
|
|
1219
|
+
variants: {
|
|
1220
|
+
variant: {
|
|
1221
|
+
outline: "border-border border-b-2 bg-muted/70 text-foreground shadow-2xs",
|
|
1222
|
+
subtle: "border-transparent bg-muted text-muted-foreground",
|
|
1223
|
+
solid: "border-transparent bg-primary text-primary-foreground shadow-2xs"
|
|
1224
|
+
},
|
|
1225
|
+
size: {
|
|
1226
|
+
sm: "min-h-4 min-w-4 px-1 py-0.5 text-[10px]",
|
|
1227
|
+
md: "min-h-5 min-w-5 px-1.5 py-0.5 text-xs",
|
|
1228
|
+
lg: "min-h-6 min-w-6 px-2 py-1 text-sm"
|
|
1229
|
+
}
|
|
1230
|
+
},
|
|
1231
|
+
defaultVariants: {
|
|
1232
|
+
variant: "outline",
|
|
1233
|
+
size: "md"
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
);
|
|
1237
|
+
var kbdGroupBase = "inline-flex items-center gap-1";
|
|
1238
|
+
var KEY_LABEL_OVERRIDES = {
|
|
1239
|
+
Space: "Space",
|
|
1240
|
+
" ": "Space",
|
|
1241
|
+
Escape: "Esc",
|
|
1242
|
+
Backspace: "\u232B",
|
|
1243
|
+
Enter: "\u21B5",
|
|
1244
|
+
ArrowUp: "\u2191",
|
|
1245
|
+
ArrowDown: "\u2193",
|
|
1246
|
+
ArrowLeft: "\u2190",
|
|
1247
|
+
ArrowRight: "\u2192"
|
|
1248
|
+
};
|
|
1249
|
+
function formatKeyChord(chord, options) {
|
|
1250
|
+
const trimmed = chord.trim();
|
|
1251
|
+
if (!trimmed) return "";
|
|
1252
|
+
if (KEY_LABEL_OVERRIDES[trimmed]) {
|
|
1253
|
+
return KEY_LABEL_OVERRIDES[trimmed];
|
|
1254
|
+
}
|
|
1255
|
+
if (trimmed.length === 1) {
|
|
1256
|
+
return trimmed;
|
|
1257
|
+
}
|
|
1258
|
+
if (/^Shift\+([a-zA-Z])$/.test(trimmed)) {
|
|
1259
|
+
return trimmed.slice(-1).toUpperCase();
|
|
1260
|
+
}
|
|
1261
|
+
try {
|
|
1262
|
+
const formatted = formatForDisplay(trimmed, {
|
|
1263
|
+
platform: options?.platform,
|
|
1264
|
+
useSymbols: options?.useSymbols ?? true
|
|
1265
|
+
});
|
|
1266
|
+
return formatted || trimmed;
|
|
1267
|
+
} catch {
|
|
1268
|
+
return trimmed;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function formatKeySequence(hotkey, options) {
|
|
1272
|
+
const steps = Array.isArray(hotkey) ? hotkey : hotkey.trim().split(/\s+/).filter(Boolean);
|
|
1273
|
+
return steps.map((step) => formatKeyChord(step, options));
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
// src/which-key/core.ts
|
|
1277
|
+
var DEFAULT_JUMP_ALPHABET = "asdfghjklqwertyuiopzxcvbnm";
|
|
1278
|
+
function nodeMatchesMode(node, mode) {
|
|
1279
|
+
if (!mode || !node.mode) return true;
|
|
1280
|
+
if (Array.isArray(node.mode)) {
|
|
1281
|
+
return node.mode.includes(mode);
|
|
1282
|
+
}
|
|
1283
|
+
return node.mode === mode;
|
|
1284
|
+
}
|
|
1285
|
+
function normalizeNodeModes(node) {
|
|
1286
|
+
if (!node.mode) return ["normal"];
|
|
1287
|
+
return Array.isArray(node.mode) ? node.mode : [node.mode];
|
|
1288
|
+
}
|
|
1289
|
+
function getNodeChildren(node, rootTrie, visitedProxies = /* @__PURE__ */ new Set()) {
|
|
1290
|
+
let proxyChildren = {};
|
|
1291
|
+
if (node.proxy && node.proxy.length > 0) {
|
|
1292
|
+
const proxyKey = node.proxy.join(">");
|
|
1293
|
+
if (!visitedProxies.has(proxyKey)) {
|
|
1294
|
+
const nextVisited = new Set(visitedProxies);
|
|
1295
|
+
nextVisited.add(proxyKey);
|
|
1296
|
+
const target = resolveNodeInternal(rootTrie, node.proxy, void 0, nextVisited);
|
|
1297
|
+
if (target) {
|
|
1298
|
+
proxyChildren = getNodeChildren(target, rootTrie, nextVisited);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
const expandedChildren = node.expand ? node.expand() : {};
|
|
1303
|
+
return {
|
|
1304
|
+
...proxyChildren,
|
|
1305
|
+
...expandedChildren,
|
|
1306
|
+
...node.children ?? {}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
function resolveNodeInternal(rootTrie, path, mode, visitedProxies) {
|
|
1310
|
+
if (path.length === 0) return null;
|
|
1311
|
+
let currentMap = rootTrie;
|
|
1312
|
+
let currentNode = null;
|
|
1313
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
1314
|
+
const step = path[i];
|
|
1315
|
+
if (!step) return null;
|
|
1316
|
+
const candidate = currentMap[step];
|
|
1317
|
+
if (!candidate) return null;
|
|
1318
|
+
if (mode && !nodeMatchesMode(candidate, mode)) return null;
|
|
1319
|
+
currentNode = candidate;
|
|
1320
|
+
if (i < path.length - 1) {
|
|
1321
|
+
currentMap = getNodeChildren(candidate, rootTrie, visitedProxies);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
return currentNode;
|
|
1325
|
+
}
|
|
1326
|
+
function resolveNode(rootTrie, path, mode) {
|
|
1327
|
+
return resolveNodeInternal(rootTrie, path, mode, /* @__PURE__ */ new Set());
|
|
1328
|
+
}
|
|
1329
|
+
function isGroupNode(node, rootTrie) {
|
|
1330
|
+
const children = getNodeChildren(node, rootTrie);
|
|
1331
|
+
return Object.keys(children).length > 0;
|
|
1332
|
+
}
|
|
1333
|
+
function buildWhichKeyTree(rootTrie, activePath, mode) {
|
|
1334
|
+
if (activePath.length === 0) {
|
|
1335
|
+
const items2 = Object.values(rootTrie).filter((item) => !item.hidden && nodeMatchesMode(item, mode));
|
|
1336
|
+
return {
|
|
1337
|
+
node: null,
|
|
1338
|
+
items: items2,
|
|
1339
|
+
title: "Commands",
|
|
1340
|
+
breadcrumb: [],
|
|
1341
|
+
sticky: false
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
const node = resolveNode(rootTrie, activePath, mode);
|
|
1345
|
+
if (!node) {
|
|
1346
|
+
return {
|
|
1347
|
+
node: null,
|
|
1348
|
+
items: [],
|
|
1349
|
+
title: "",
|
|
1350
|
+
breadcrumb: activePath,
|
|
1351
|
+
sticky: false
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
const childrenMap = getNodeChildren(node, rootTrie);
|
|
1355
|
+
const items = Object.values(childrenMap).filter((item) => !item.hidden && nodeMatchesMode(item, mode));
|
|
1356
|
+
let sticky = Boolean(node.sticky || node.loop);
|
|
1357
|
+
if (!sticky && node.proxy && node.proxy.length > 0) {
|
|
1358
|
+
const target = resolveNode(rootTrie, node.proxy, mode);
|
|
1359
|
+
if (target) {
|
|
1360
|
+
sticky = Boolean(target.sticky || target.loop);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
return {
|
|
1364
|
+
node,
|
|
1365
|
+
items,
|
|
1366
|
+
title: node.group ?? node.label,
|
|
1367
|
+
breadcrumb: [...activePath],
|
|
1368
|
+
sticky
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
function flattenKeymapEntries(rootTrie, mode) {
|
|
1372
|
+
const entries = [];
|
|
1373
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
1374
|
+
function walk(map, chords, groupPath, visitedProxies) {
|
|
1375
|
+
for (const [key, node] of Object.entries(map)) {
|
|
1376
|
+
if (node.hidden) continue;
|
|
1377
|
+
if (mode && !nodeMatchesMode(node, mode)) continue;
|
|
1378
|
+
const nextChords = [...chords, node.key || key];
|
|
1379
|
+
const children = getNodeChildren(node, rootTrie, visitedProxies);
|
|
1380
|
+
const childKeys = Object.keys(children);
|
|
1381
|
+
if (childKeys.length > 0) {
|
|
1382
|
+
const groupTitle = node.group ?? node.label.replace(/^\+/, "");
|
|
1383
|
+
const nextGroupPath = [...groupPath, groupTitle];
|
|
1384
|
+
const nextVisited = new Set(visitedProxies);
|
|
1385
|
+
if (node.proxy && node.proxy.length > 0) {
|
|
1386
|
+
nextVisited.add(node.proxy.join(">"));
|
|
1387
|
+
}
|
|
1388
|
+
walk(children, nextChords, nextGroupPath, nextVisited);
|
|
1389
|
+
}
|
|
1390
|
+
if (node.commandId || node.action || childKeys.length === 0) {
|
|
1391
|
+
if (childKeys.length > 0 && !node.commandId && !node.action) {
|
|
1392
|
+
continue;
|
|
1393
|
+
}
|
|
1394
|
+
const sequenceText = nextChords.join(" ");
|
|
1395
|
+
const category = node.category ?? (groupPath.length > 0 ? groupPath[0] : "General");
|
|
1396
|
+
const group = groupPath.length > 0 ? groupPath.join(" / ") : category;
|
|
1397
|
+
const id = `${sequenceText}::${node.commandId ?? node.label}`;
|
|
1398
|
+
if (seenIds.has(id)) continue;
|
|
1399
|
+
seenIds.add(id);
|
|
1400
|
+
entries.push({
|
|
1401
|
+
id,
|
|
1402
|
+
chords: nextChords,
|
|
1403
|
+
sequenceText,
|
|
1404
|
+
label: node.label,
|
|
1405
|
+
description: node.description ?? node.label,
|
|
1406
|
+
group,
|
|
1407
|
+
category,
|
|
1408
|
+
mode: normalizeNodeModes(node),
|
|
1409
|
+
commandId: node.commandId,
|
|
1410
|
+
action: node.action
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
walk(rootTrie, [], [], /* @__PURE__ */ new Set());
|
|
1416
|
+
return entries;
|
|
1417
|
+
}
|
|
1418
|
+
function findDirectionalPane(origin, candidates, direction) {
|
|
1419
|
+
const originCenterX = origin.x + origin.width / 2;
|
|
1420
|
+
const originCenterY = origin.y + origin.height / 2;
|
|
1421
|
+
let bestCandidate = null;
|
|
1422
|
+
let bestScore = Number.POSITIVE_INFINITY;
|
|
1423
|
+
for (const candidate of candidates) {
|
|
1424
|
+
if (candidate.disabled || candidate.id === origin.id) continue;
|
|
1425
|
+
if (candidate.width <= 0 || candidate.height <= 0) continue;
|
|
1426
|
+
const centerX = candidate.x + candidate.width / 2;
|
|
1427
|
+
const centerY = candidate.y + candidate.height / 2;
|
|
1428
|
+
const dx = centerX - originCenterX;
|
|
1429
|
+
const dy = centerY - originCenterY;
|
|
1430
|
+
const gapX = Math.max(
|
|
1431
|
+
0,
|
|
1432
|
+
Math.max(origin.x, candidate.x) - Math.min(origin.x + origin.width, candidate.x + candidate.width)
|
|
1433
|
+
);
|
|
1434
|
+
const gapY = Math.max(
|
|
1435
|
+
0,
|
|
1436
|
+
Math.max(origin.y, candidate.y) - Math.min(origin.y + origin.height, candidate.y + candidate.height)
|
|
1437
|
+
);
|
|
1438
|
+
let primaryDist = 0;
|
|
1439
|
+
let orthogonalDist = 0;
|
|
1440
|
+
switch (direction) {
|
|
1441
|
+
case "left":
|
|
1442
|
+
if (dx >= -1) continue;
|
|
1443
|
+
primaryDist = -dx;
|
|
1444
|
+
orthogonalDist = gapY;
|
|
1445
|
+
break;
|
|
1446
|
+
case "right":
|
|
1447
|
+
if (dx <= 1) continue;
|
|
1448
|
+
primaryDist = dx;
|
|
1449
|
+
orthogonalDist = gapY;
|
|
1450
|
+
break;
|
|
1451
|
+
case "up":
|
|
1452
|
+
if (dy >= -1) continue;
|
|
1453
|
+
primaryDist = -dy;
|
|
1454
|
+
orthogonalDist = gapX;
|
|
1455
|
+
break;
|
|
1456
|
+
case "down":
|
|
1457
|
+
if (dy <= 1) continue;
|
|
1458
|
+
primaryDist = dy;
|
|
1459
|
+
orthogonalDist = gapX;
|
|
1460
|
+
break;
|
|
1461
|
+
}
|
|
1462
|
+
const euclidean = Math.hypot(dx, dy);
|
|
1463
|
+
const score = primaryDist + orthogonalDist * 2 + euclidean * 0.01;
|
|
1464
|
+
if (score < bestScore) {
|
|
1465
|
+
bestScore = score;
|
|
1466
|
+
bestCandidate = candidate;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return bestCandidate;
|
|
1470
|
+
}
|
|
1471
|
+
function generateJumpLabels(count, alphabet = DEFAULT_JUMP_ALPHABET) {
|
|
1472
|
+
if (count <= 0) return [];
|
|
1473
|
+
const chars = Array.from(new Set(alphabet.split("").filter(Boolean)));
|
|
1474
|
+
const n = chars.length;
|
|
1475
|
+
if (n === 0) return [];
|
|
1476
|
+
if (n === 1) {
|
|
1477
|
+
return Array.from({ length: count }, (_, idx) => chars[0].repeat(idx + 1));
|
|
1478
|
+
}
|
|
1479
|
+
if (count <= n) {
|
|
1480
|
+
return chars.slice(0, count);
|
|
1481
|
+
}
|
|
1482
|
+
const queue = [...chars];
|
|
1483
|
+
while (queue.length < count) {
|
|
1484
|
+
const prefix = queue.shift();
|
|
1485
|
+
for (const ch of chars) {
|
|
1486
|
+
queue.push(prefix + ch);
|
|
1487
|
+
if (queue.length + (chars.length - 1) >= count && queue.length >= count) {
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return queue.slice(0, count);
|
|
1493
|
+
}
|
|
1494
|
+
var Jumplist = class {
|
|
1495
|
+
stack = [];
|
|
1496
|
+
index = -1;
|
|
1497
|
+
maxSize;
|
|
1498
|
+
constructor(maxSize = 50) {
|
|
1499
|
+
this.maxSize = Math.max(2, maxSize);
|
|
1500
|
+
}
|
|
1501
|
+
push(entry) {
|
|
1502
|
+
const current = this.stack[this.index];
|
|
1503
|
+
if (current && current.paneId === entry.paneId && current.element === entry.element && current.elementSelector === entry.elementSelector) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (this.index < this.stack.length - 1) {
|
|
1507
|
+
this.stack = this.stack.slice(0, this.index + 1);
|
|
1508
|
+
}
|
|
1509
|
+
this.stack.push({
|
|
1510
|
+
...entry,
|
|
1511
|
+
timestamp: entry.timestamp ?? Date.now()
|
|
1512
|
+
});
|
|
1513
|
+
if (this.stack.length > this.maxSize) {
|
|
1514
|
+
this.stack.shift();
|
|
1515
|
+
}
|
|
1516
|
+
this.index = this.stack.length - 1;
|
|
1517
|
+
}
|
|
1518
|
+
back(current) {
|
|
1519
|
+
if (this.stack.length === 0) return null;
|
|
1520
|
+
if (current && this.index === this.stack.length - 1) {
|
|
1521
|
+
const tip = this.stack[this.index];
|
|
1522
|
+
if (!tip || tip.paneId !== current.paneId || tip.element !== current.element || tip.elementSelector !== current.elementSelector) {
|
|
1523
|
+
this.push(current);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
if (this.index <= 0) {
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
this.index -= 1;
|
|
1530
|
+
return this.stack[this.index] ?? null;
|
|
1531
|
+
}
|
|
1532
|
+
forward() {
|
|
1533
|
+
if (this.index < 0 || this.index >= this.stack.length - 1) {
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
this.index += 1;
|
|
1537
|
+
return this.stack[this.index] ?? null;
|
|
1538
|
+
}
|
|
1539
|
+
entries() {
|
|
1540
|
+
return this.stack;
|
|
1541
|
+
}
|
|
1542
|
+
currentIndex() {
|
|
1543
|
+
return this.index;
|
|
1544
|
+
}
|
|
1545
|
+
clear() {
|
|
1546
|
+
this.stack = [];
|
|
1547
|
+
this.index = -1;
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
function createJumplist(maxSize = 50) {
|
|
1551
|
+
return new Jumplist(maxSize);
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// src/which-key/types.ts
|
|
1555
|
+
var globalModalState = globalThis;
|
|
1556
|
+
var modalEditorRegistry = globalModalState.__helicalModalEditorRegistry__ ??= /* @__PURE__ */ new WeakMap();
|
|
1557
|
+
var activeModalEditors = globalModalState.__helicalActiveModalEditors__ ??= /* @__PURE__ */ new Set();
|
|
1558
|
+
function registerModalEditor(element, target) {
|
|
1559
|
+
modalEditorRegistry.set(element, target);
|
|
1560
|
+
activeModalEditors.add(target);
|
|
1561
|
+
return () => {
|
|
1562
|
+
if (modalEditorRegistry.get(element) === target) {
|
|
1563
|
+
modalEditorRegistry.delete(element);
|
|
1564
|
+
}
|
|
1565
|
+
activeModalEditors.delete(target);
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
function getModalEditor(element) {
|
|
1569
|
+
let curr = element;
|
|
1570
|
+
while (curr) {
|
|
1571
|
+
const found = modalEditorRegistry.get(curr);
|
|
1572
|
+
if (found) return found;
|
|
1573
|
+
curr = curr.parentElement;
|
|
1574
|
+
}
|
|
1575
|
+
return void 0;
|
|
1576
|
+
}
|
|
1577
|
+
function notifyAllModalEditors(state) {
|
|
1578
|
+
for (const target of activeModalEditors) {
|
|
1579
|
+
target.setModalState(state);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// src/which-key/presets.ts
|
|
1584
|
+
function createTextObjectChildren() {
|
|
1585
|
+
return {
|
|
1586
|
+
i: {
|
|
1587
|
+
key: "i",
|
|
1588
|
+
label: "+inner",
|
|
1589
|
+
group: "Inner Text Object",
|
|
1590
|
+
category: "Match / Text Objects",
|
|
1591
|
+
mode: ["normal", "select"],
|
|
1592
|
+
children: {
|
|
1593
|
+
w: {
|
|
1594
|
+
key: "w",
|
|
1595
|
+
label: "Inner Word",
|
|
1596
|
+
description: "Select inner word (iw)",
|
|
1597
|
+
category: "Match / Text Objects",
|
|
1598
|
+
commandId: "textObject.iw"
|
|
1599
|
+
},
|
|
1600
|
+
p: {
|
|
1601
|
+
key: "p",
|
|
1602
|
+
label: "Inner Paragraph",
|
|
1603
|
+
description: "Select inner paragraph (ip)",
|
|
1604
|
+
category: "Match / Text Objects",
|
|
1605
|
+
commandId: "textObject.ip"
|
|
1606
|
+
},
|
|
1607
|
+
c: {
|
|
1608
|
+
key: "c",
|
|
1609
|
+
label: "Inner Code Block",
|
|
1610
|
+
description: "Select inner code block (ic)",
|
|
1611
|
+
category: "Match / Text Objects",
|
|
1612
|
+
commandId: "textObject.ic"
|
|
1613
|
+
},
|
|
1614
|
+
n: {
|
|
1615
|
+
key: "n",
|
|
1616
|
+
label: "Inner Notice / Callout",
|
|
1617
|
+
description: "Select inner notice or blockquote (in)",
|
|
1618
|
+
category: "Match / Text Objects",
|
|
1619
|
+
commandId: "textObject.in"
|
|
1620
|
+
},
|
|
1621
|
+
l: {
|
|
1622
|
+
key: "l",
|
|
1623
|
+
label: "Inner List Item",
|
|
1624
|
+
description: "Select inner list item (il)",
|
|
1625
|
+
category: "Match / Text Objects",
|
|
1626
|
+
commandId: "textObject.il"
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
},
|
|
1630
|
+
a: {
|
|
1631
|
+
key: "a",
|
|
1632
|
+
label: "+around",
|
|
1633
|
+
group: "Around Text Object",
|
|
1634
|
+
category: "Match / Text Objects",
|
|
1635
|
+
mode: ["normal", "select"],
|
|
1636
|
+
children: {
|
|
1637
|
+
w: {
|
|
1638
|
+
key: "w",
|
|
1639
|
+
label: "Around Word",
|
|
1640
|
+
description: "Select word and surrounding whitespace (aw)",
|
|
1641
|
+
category: "Match / Text Objects",
|
|
1642
|
+
commandId: "textObject.aw"
|
|
1643
|
+
},
|
|
1644
|
+
p: {
|
|
1645
|
+
key: "p",
|
|
1646
|
+
label: "Around Paragraph",
|
|
1647
|
+
description: "Select entire paragraph block (ap)",
|
|
1648
|
+
category: "Match / Text Objects",
|
|
1649
|
+
commandId: "textObject.ap"
|
|
1650
|
+
},
|
|
1651
|
+
c: {
|
|
1652
|
+
key: "c",
|
|
1653
|
+
label: "Around Code Block",
|
|
1654
|
+
description: "Select entire code block (ac)",
|
|
1655
|
+
category: "Match / Text Objects",
|
|
1656
|
+
commandId: "textObject.ac"
|
|
1657
|
+
},
|
|
1658
|
+
n: {
|
|
1659
|
+
key: "n",
|
|
1660
|
+
label: "Around Notice / Callout",
|
|
1661
|
+
description: "Select entire notice or blockquote (an)",
|
|
1662
|
+
category: "Match / Text Objects",
|
|
1663
|
+
commandId: "textObject.an"
|
|
1664
|
+
},
|
|
1665
|
+
l: {
|
|
1666
|
+
key: "l",
|
|
1667
|
+
label: "Around List Item",
|
|
1668
|
+
description: "Select entire list item (al)",
|
|
1669
|
+
category: "Match / Text Objects",
|
|
1670
|
+
commandId: "textObject.al"
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
function createWindowMenu() {
|
|
1677
|
+
return {
|
|
1678
|
+
key: "Control+w",
|
|
1679
|
+
label: "+window",
|
|
1680
|
+
group: "Window / Pane",
|
|
1681
|
+
category: "Window / Pane",
|
|
1682
|
+
mode: ["normal", "select"],
|
|
1683
|
+
children: {
|
|
1684
|
+
h: {
|
|
1685
|
+
key: "h",
|
|
1686
|
+
label: "Focus Pane Left",
|
|
1687
|
+
description: "Move focus to the pane on the left",
|
|
1688
|
+
category: "Window / Pane",
|
|
1689
|
+
commandId: "pane.left"
|
|
1690
|
+
},
|
|
1691
|
+
j: {
|
|
1692
|
+
key: "j",
|
|
1693
|
+
label: "Focus Pane Down",
|
|
1694
|
+
description: "Move focus to the pane below",
|
|
1695
|
+
category: "Window / Pane",
|
|
1696
|
+
commandId: "pane.down"
|
|
1697
|
+
},
|
|
1698
|
+
k: {
|
|
1699
|
+
key: "k",
|
|
1700
|
+
label: "Focus Pane Up",
|
|
1701
|
+
description: "Move focus to the pane above",
|
|
1702
|
+
category: "Window / Pane",
|
|
1703
|
+
commandId: "pane.up"
|
|
1704
|
+
},
|
|
1705
|
+
l: {
|
|
1706
|
+
key: "l",
|
|
1707
|
+
label: "Focus Pane Right",
|
|
1708
|
+
description: "Move focus to the pane on the right",
|
|
1709
|
+
category: "Window / Pane",
|
|
1710
|
+
commandId: "pane.right"
|
|
1711
|
+
},
|
|
1712
|
+
ArrowLeft: {
|
|
1713
|
+
key: "ArrowLeft",
|
|
1714
|
+
label: "Focus Pane Left",
|
|
1715
|
+
category: "Window / Pane",
|
|
1716
|
+
commandId: "pane.left",
|
|
1717
|
+
hidden: true
|
|
1718
|
+
},
|
|
1719
|
+
ArrowDown: {
|
|
1720
|
+
key: "ArrowDown",
|
|
1721
|
+
label: "Focus Pane Down",
|
|
1722
|
+
category: "Window / Pane",
|
|
1723
|
+
commandId: "pane.down",
|
|
1724
|
+
hidden: true
|
|
1725
|
+
},
|
|
1726
|
+
ArrowUp: {
|
|
1727
|
+
key: "ArrowUp",
|
|
1728
|
+
label: "Focus Pane Up",
|
|
1729
|
+
category: "Window / Pane",
|
|
1730
|
+
commandId: "pane.up",
|
|
1731
|
+
hidden: true
|
|
1732
|
+
},
|
|
1733
|
+
ArrowRight: {
|
|
1734
|
+
key: "ArrowRight",
|
|
1735
|
+
label: "Focus Pane Right",
|
|
1736
|
+
category: "Window / Pane",
|
|
1737
|
+
commandId: "pane.right",
|
|
1738
|
+
hidden: true
|
|
1739
|
+
},
|
|
1740
|
+
w: {
|
|
1741
|
+
key: "w",
|
|
1742
|
+
label: "Cycle Next Pane",
|
|
1743
|
+
description: "Cycle focus to the next registered pane",
|
|
1744
|
+
category: "Window / Pane",
|
|
1745
|
+
commandId: "pane.next"
|
|
1746
|
+
},
|
|
1747
|
+
W: {
|
|
1748
|
+
key: "W",
|
|
1749
|
+
label: "Cycle Previous Pane",
|
|
1750
|
+
description: "Cycle focus to the previous registered pane",
|
|
1751
|
+
category: "Window / Pane",
|
|
1752
|
+
commandId: "pane.prev"
|
|
1753
|
+
},
|
|
1754
|
+
s: {
|
|
1755
|
+
key: "s",
|
|
1756
|
+
label: "+sticky window",
|
|
1757
|
+
group: "Sticky Window Mode",
|
|
1758
|
+
description: "Keep Window menu open until Escape",
|
|
1759
|
+
category: "Window / Pane",
|
|
1760
|
+
sticky: true,
|
|
1761
|
+
loop: true,
|
|
1762
|
+
proxy: ["Control+w"]
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
1768
|
+
const paneSlots = {};
|
|
1769
|
+
for (let i = 1; i <= 9; i += 1) {
|
|
1770
|
+
paneSlots[String(i)] = {
|
|
1771
|
+
key: String(i),
|
|
1772
|
+
label: `Focus Pane ${i}`,
|
|
1773
|
+
description: `Switch focus directly to pane #${i}`,
|
|
1774
|
+
category: "Window / Pane",
|
|
1775
|
+
commandId: `pane.focus.${i}`,
|
|
1776
|
+
hidden: i > 4
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
return {
|
|
1780
|
+
key: leaderKey,
|
|
1781
|
+
label: "+leader",
|
|
1782
|
+
group: "Leader",
|
|
1783
|
+
category: "Leader",
|
|
1784
|
+
mode: ["normal", "select"],
|
|
1785
|
+
children: {
|
|
1786
|
+
"?": {
|
|
1787
|
+
key: "?",
|
|
1788
|
+
label: "Explore Keybindings",
|
|
1789
|
+
description: "Open searchable keybinding exploration menu (<leader>?)",
|
|
1790
|
+
category: "Space",
|
|
1791
|
+
commandId: "whichKey.openExplorer"
|
|
1792
|
+
},
|
|
1793
|
+
w: {
|
|
1794
|
+
key: "w",
|
|
1795
|
+
label: "+window",
|
|
1796
|
+
group: "Window / Pane",
|
|
1797
|
+
description: "Spatial and indexed pane navigation",
|
|
1798
|
+
category: "Window / Pane",
|
|
1799
|
+
proxy: ["Control+w"]
|
|
1800
|
+
},
|
|
1801
|
+
j: {
|
|
1802
|
+
key: "j",
|
|
1803
|
+
label: "Jump to Element",
|
|
1804
|
+
description: "Show 2D home-row jump labels over visible controls",
|
|
1805
|
+
category: "Navigation",
|
|
1806
|
+
commandId: "jump.start"
|
|
1807
|
+
},
|
|
1808
|
+
g: {
|
|
1809
|
+
key: "g",
|
|
1810
|
+
label: "+goto",
|
|
1811
|
+
group: "Goto",
|
|
1812
|
+
description: "Go to locations and boundaries",
|
|
1813
|
+
category: "Goto",
|
|
1814
|
+
proxy: ["g"]
|
|
1815
|
+
},
|
|
1816
|
+
v: {
|
|
1817
|
+
key: "v",
|
|
1818
|
+
label: "+view",
|
|
1819
|
+
group: "View / Scroll",
|
|
1820
|
+
description: "Scroll and align viewport",
|
|
1821
|
+
category: "View",
|
|
1822
|
+
proxy: [viewKey]
|
|
1823
|
+
},
|
|
1824
|
+
k: {
|
|
1825
|
+
key: "k",
|
|
1826
|
+
label: "+preset",
|
|
1827
|
+
group: "Keybinding Preset",
|
|
1828
|
+
description: "Switch modal grammar (Helix / Vim / Kakoune)",
|
|
1829
|
+
category: "Space",
|
|
1830
|
+
children: {
|
|
1831
|
+
h: {
|
|
1832
|
+
key: "h",
|
|
1833
|
+
label: "Helix Preset",
|
|
1834
|
+
description: "Switch to Helix selection-first grammar (default)",
|
|
1835
|
+
category: "Preset",
|
|
1836
|
+
commandId: "preset.helix"
|
|
1837
|
+
},
|
|
1838
|
+
v: {
|
|
1839
|
+
key: "v",
|
|
1840
|
+
label: "Vim Preset",
|
|
1841
|
+
description: "Switch to Vim operator-motion grammar",
|
|
1842
|
+
category: "Preset",
|
|
1843
|
+
commandId: "preset.vim"
|
|
1844
|
+
},
|
|
1845
|
+
k: {
|
|
1846
|
+
key: "k",
|
|
1847
|
+
label: "Kakoune Preset",
|
|
1848
|
+
description: "Switch to Kakoune object-verb grammar",
|
|
1849
|
+
category: "Preset",
|
|
1850
|
+
commandId: "preset.kakoune"
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
},
|
|
1854
|
+
...paneSlots
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
function createViewMenu(key, centerKey) {
|
|
1859
|
+
return {
|
|
1860
|
+
key,
|
|
1861
|
+
label: "+view",
|
|
1862
|
+
group: "View",
|
|
1863
|
+
category: "View",
|
|
1864
|
+
mode: ["normal", "select"],
|
|
1865
|
+
children: {
|
|
1866
|
+
[centerKey]: {
|
|
1867
|
+
key: centerKey,
|
|
1868
|
+
label: "Center Viewport",
|
|
1869
|
+
description: "Center the focused item in the viewport",
|
|
1870
|
+
category: "View",
|
|
1871
|
+
commandId: "view.center"
|
|
1872
|
+
},
|
|
1873
|
+
c: {
|
|
1874
|
+
key: "c",
|
|
1875
|
+
label: "Center Viewport",
|
|
1876
|
+
description: "Center the focused item in the viewport",
|
|
1877
|
+
category: "View",
|
|
1878
|
+
commandId: "view.center"
|
|
1879
|
+
},
|
|
1880
|
+
t: {
|
|
1881
|
+
key: "t",
|
|
1882
|
+
label: "Align Top",
|
|
1883
|
+
description: "Align focused item to top of viewport",
|
|
1884
|
+
category: "View",
|
|
1885
|
+
commandId: "view.top"
|
|
1886
|
+
},
|
|
1887
|
+
b: {
|
|
1888
|
+
key: "b",
|
|
1889
|
+
label: "Align Bottom",
|
|
1890
|
+
description: "Align focused item to bottom of viewport",
|
|
1891
|
+
category: "View",
|
|
1892
|
+
commandId: "view.bottom"
|
|
1893
|
+
},
|
|
1894
|
+
j: {
|
|
1895
|
+
key: "j",
|
|
1896
|
+
label: "Scroll Down",
|
|
1897
|
+
description: "Scroll active pane down",
|
|
1898
|
+
category: "View",
|
|
1899
|
+
commandId: "view.scrollDown"
|
|
1900
|
+
},
|
|
1901
|
+
k: {
|
|
1902
|
+
key: "k",
|
|
1903
|
+
label: "Scroll Up",
|
|
1904
|
+
description: "Scroll active pane up",
|
|
1905
|
+
category: "View",
|
|
1906
|
+
commandId: "view.scrollUp"
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
function createUnimpairedMenus() {
|
|
1912
|
+
return {
|
|
1913
|
+
"[": {
|
|
1914
|
+
key: "[",
|
|
1915
|
+
label: "+prev",
|
|
1916
|
+
group: "Previous (Unimpaired)",
|
|
1917
|
+
category: "Unimpaired",
|
|
1918
|
+
mode: ["normal", "select"],
|
|
1919
|
+
children: {
|
|
1920
|
+
s: {
|
|
1921
|
+
key: "s",
|
|
1922
|
+
label: "Previous Section",
|
|
1923
|
+
description: "Jump to previous heading or PageSection",
|
|
1924
|
+
category: "Unimpaired",
|
|
1925
|
+
commandId: "section.prev"
|
|
1926
|
+
},
|
|
1927
|
+
t: {
|
|
1928
|
+
key: "t",
|
|
1929
|
+
label: "Previous Tab",
|
|
1930
|
+
description: "Switch to previous tab in active tablist ([t)",
|
|
1931
|
+
category: "Unimpaired",
|
|
1932
|
+
commandId: "tab.prev"
|
|
1933
|
+
},
|
|
1934
|
+
p: {
|
|
1935
|
+
key: "p",
|
|
1936
|
+
label: "Previous Paragraph / Section",
|
|
1937
|
+
description: "Jump to previous paragraph or section",
|
|
1938
|
+
category: "Unimpaired",
|
|
1939
|
+
commandId: "motion.paragraphBackward"
|
|
1940
|
+
},
|
|
1941
|
+
f: {
|
|
1942
|
+
key: "f",
|
|
1943
|
+
label: "Previous Focusable Block",
|
|
1944
|
+
description: "Move focus to previous interactive control",
|
|
1945
|
+
category: "Unimpaired",
|
|
1946
|
+
commandId: "focus.prevBlock"
|
|
1947
|
+
},
|
|
1948
|
+
Space: {
|
|
1949
|
+
key: "Space",
|
|
1950
|
+
label: "Blank Line Above",
|
|
1951
|
+
description: "Insert blank line above current block",
|
|
1952
|
+
category: "Unimpaired",
|
|
1953
|
+
commandId: "operator.openAbove"
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
"]": {
|
|
1958
|
+
key: "]",
|
|
1959
|
+
label: "+next",
|
|
1960
|
+
group: "Next (Unimpaired)",
|
|
1961
|
+
category: "Unimpaired",
|
|
1962
|
+
mode: ["normal", "select"],
|
|
1963
|
+
children: {
|
|
1964
|
+
s: {
|
|
1965
|
+
key: "s",
|
|
1966
|
+
label: "Next Section",
|
|
1967
|
+
description: "Jump to next heading or PageSection",
|
|
1968
|
+
category: "Unimpaired",
|
|
1969
|
+
commandId: "section.next"
|
|
1970
|
+
},
|
|
1971
|
+
t: {
|
|
1972
|
+
key: "t",
|
|
1973
|
+
label: "Next Tab",
|
|
1974
|
+
description: "Switch to next tab in active tablist (]t)",
|
|
1975
|
+
category: "Unimpaired",
|
|
1976
|
+
commandId: "tab.next"
|
|
1977
|
+
},
|
|
1978
|
+
p: {
|
|
1979
|
+
key: "p",
|
|
1980
|
+
label: "Next Paragraph / Section",
|
|
1981
|
+
description: "Jump to next paragraph or section",
|
|
1982
|
+
category: "Unimpaired",
|
|
1983
|
+
commandId: "motion.paragraphForward"
|
|
1984
|
+
},
|
|
1985
|
+
f: {
|
|
1986
|
+
key: "f",
|
|
1987
|
+
label: "Next Focusable Block",
|
|
1988
|
+
description: "Move focus to next interactive control",
|
|
1989
|
+
category: "Unimpaired",
|
|
1990
|
+
commandId: "focus.nextBlock"
|
|
1991
|
+
},
|
|
1992
|
+
Space: {
|
|
1993
|
+
key: "Space",
|
|
1994
|
+
label: "Blank Line Below",
|
|
1995
|
+
description: "Insert blank line below current block",
|
|
1996
|
+
category: "Unimpaired",
|
|
1997
|
+
commandId: "operator.openBelow"
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
function createSharedMotionsAndOperators() {
|
|
2004
|
+
return {
|
|
2005
|
+
h: {
|
|
2006
|
+
key: "h",
|
|
2007
|
+
label: "Move Left",
|
|
2008
|
+
description: "Move cursor or focus left",
|
|
2009
|
+
category: "Motion",
|
|
2010
|
+
mode: ["normal", "select"],
|
|
2011
|
+
commandId: "motion.left",
|
|
2012
|
+
hidden: true
|
|
2013
|
+
},
|
|
2014
|
+
j: {
|
|
2015
|
+
key: "j",
|
|
2016
|
+
label: "Move Down / Next Item",
|
|
2017
|
+
description: "Step focus to next item or line down",
|
|
2018
|
+
category: "Motion",
|
|
2019
|
+
mode: ["normal", "select"],
|
|
2020
|
+
commandId: "motion.down",
|
|
2021
|
+
hidden: true
|
|
2022
|
+
},
|
|
2023
|
+
k: {
|
|
2024
|
+
key: "k",
|
|
2025
|
+
label: "Move Up / Previous Item",
|
|
2026
|
+
description: "Step focus to previous item or line up",
|
|
2027
|
+
category: "Motion",
|
|
2028
|
+
mode: ["normal", "select"],
|
|
2029
|
+
commandId: "motion.up",
|
|
2030
|
+
hidden: true
|
|
2031
|
+
},
|
|
2032
|
+
l: {
|
|
2033
|
+
key: "l",
|
|
2034
|
+
label: "Move Right",
|
|
2035
|
+
description: "Move cursor or focus right",
|
|
2036
|
+
category: "Motion",
|
|
2037
|
+
mode: ["normal", "select"],
|
|
2038
|
+
commandId: "motion.right",
|
|
2039
|
+
hidden: true
|
|
2040
|
+
},
|
|
2041
|
+
w: {
|
|
2042
|
+
key: "w",
|
|
2043
|
+
label: "Next Word",
|
|
2044
|
+
description: "Select or move to next word (w)",
|
|
2045
|
+
category: "Motion",
|
|
2046
|
+
mode: ["normal", "select"],
|
|
2047
|
+
commandId: "motion.wordForward"
|
|
2048
|
+
},
|
|
2049
|
+
b: {
|
|
2050
|
+
key: "b",
|
|
2051
|
+
label: "Previous Word",
|
|
2052
|
+
description: "Select or move to previous word (b)",
|
|
2053
|
+
category: "Motion",
|
|
2054
|
+
mode: ["normal", "select"],
|
|
2055
|
+
commandId: "motion.wordBackward"
|
|
2056
|
+
},
|
|
2057
|
+
e: {
|
|
2058
|
+
key: "e",
|
|
2059
|
+
label: "Word End",
|
|
2060
|
+
description: "Select or move to end of word (e)",
|
|
2061
|
+
category: "Motion",
|
|
2062
|
+
mode: ["normal", "select"],
|
|
2063
|
+
commandId: "motion.wordEnd"
|
|
2064
|
+
},
|
|
2065
|
+
"{": {
|
|
2066
|
+
key: "{",
|
|
2067
|
+
label: "Previous Paragraph / Section",
|
|
2068
|
+
description: "Jump to previous paragraph or section ({)",
|
|
2069
|
+
category: "Motion",
|
|
2070
|
+
mode: ["normal", "select"],
|
|
2071
|
+
commandId: "motion.paragraphBackward"
|
|
2072
|
+
},
|
|
2073
|
+
"}": {
|
|
2074
|
+
key: "}",
|
|
2075
|
+
label: "Next Paragraph / Section",
|
|
2076
|
+
description: "Jump to next paragraph or section (})",
|
|
2077
|
+
category: "Motion",
|
|
2078
|
+
mode: ["normal", "select"],
|
|
2079
|
+
commandId: "motion.paragraphForward"
|
|
2080
|
+
},
|
|
2081
|
+
"0": {
|
|
2082
|
+
key: "0",
|
|
2083
|
+
label: "Start of Line / Group",
|
|
2084
|
+
description: "Move to beginning of line or group (0)",
|
|
2085
|
+
category: "Motion",
|
|
2086
|
+
mode: ["normal", "select"],
|
|
2087
|
+
commandId: "motion.lineStart"
|
|
2088
|
+
},
|
|
2089
|
+
$: {
|
|
2090
|
+
key: "$",
|
|
2091
|
+
label: "End of Line / Group",
|
|
2092
|
+
description: "Move to end of line or group ($)",
|
|
2093
|
+
category: "Motion",
|
|
2094
|
+
mode: ["normal", "select"],
|
|
2095
|
+
commandId: "motion.lineEnd"
|
|
2096
|
+
},
|
|
2097
|
+
i: {
|
|
2098
|
+
key: "i",
|
|
2099
|
+
label: "Insert Mode",
|
|
2100
|
+
description: "Enter insert mode at start of selection or control",
|
|
2101
|
+
category: "Mode / Operator",
|
|
2102
|
+
mode: ["normal", "select"],
|
|
2103
|
+
commandId: "operator.insertStart"
|
|
2104
|
+
},
|
|
2105
|
+
a: {
|
|
2106
|
+
key: "a",
|
|
2107
|
+
label: "Append / Insert After",
|
|
2108
|
+
description: "Enter insert mode at end of selection or control",
|
|
2109
|
+
category: "Mode / Operator",
|
|
2110
|
+
mode: ["normal"],
|
|
2111
|
+
commandId: "operator.appendEnd"
|
|
2112
|
+
},
|
|
2113
|
+
o: {
|
|
2114
|
+
key: "o",
|
|
2115
|
+
label: "Open Line Below",
|
|
2116
|
+
description: "Open new paragraph below and enter insert mode",
|
|
2117
|
+
category: "Mode / Operator",
|
|
2118
|
+
mode: ["normal", "select"],
|
|
2119
|
+
commandId: "operator.openBelow"
|
|
2120
|
+
},
|
|
2121
|
+
O: {
|
|
2122
|
+
key: "O",
|
|
2123
|
+
label: "Open Line Above",
|
|
2124
|
+
description: "Open new paragraph above and enter insert mode",
|
|
2125
|
+
category: "Mode / Operator",
|
|
2126
|
+
mode: ["normal", "select"],
|
|
2127
|
+
commandId: "operator.openAbove"
|
|
2128
|
+
},
|
|
2129
|
+
d: {
|
|
2130
|
+
key: "d",
|
|
2131
|
+
label: "Delete Selection",
|
|
2132
|
+
description: "Delete active selection and store in register",
|
|
2133
|
+
category: "Operator",
|
|
2134
|
+
mode: ["normal", "select"],
|
|
2135
|
+
commandId: "operator.delete"
|
|
2136
|
+
},
|
|
2137
|
+
c: {
|
|
2138
|
+
key: "c",
|
|
2139
|
+
label: "Change Selection",
|
|
2140
|
+
description: "Delete selection and enter insert mode",
|
|
2141
|
+
category: "Operator",
|
|
2142
|
+
mode: ["normal", "select"],
|
|
2143
|
+
commandId: "operator.change"
|
|
2144
|
+
},
|
|
2145
|
+
y: {
|
|
2146
|
+
key: "y",
|
|
2147
|
+
label: "Yank Selection",
|
|
2148
|
+
description: "Copy selection slice into register",
|
|
2149
|
+
category: "Operator",
|
|
2150
|
+
mode: ["normal", "select"],
|
|
2151
|
+
commandId: "operator.yank"
|
|
2152
|
+
},
|
|
2153
|
+
p: {
|
|
2154
|
+
key: "p",
|
|
2155
|
+
label: "Paste After",
|
|
2156
|
+
description: "Paste yanked slice after selection",
|
|
2157
|
+
category: "Operator",
|
|
2158
|
+
mode: ["normal", "select"],
|
|
2159
|
+
commandId: "operator.pasteAfter"
|
|
2160
|
+
},
|
|
2161
|
+
P: {
|
|
2162
|
+
key: "P",
|
|
2163
|
+
label: "Paste Before",
|
|
2164
|
+
description: "Paste yanked slice before selection",
|
|
2165
|
+
category: "Operator",
|
|
2166
|
+
mode: ["normal", "select"],
|
|
2167
|
+
commandId: "operator.pasteBefore"
|
|
2168
|
+
},
|
|
2169
|
+
u: {
|
|
2170
|
+
key: "u",
|
|
2171
|
+
label: "Undo",
|
|
2172
|
+
description: "Undo last editor transaction",
|
|
2173
|
+
category: "Operator",
|
|
2174
|
+
mode: ["normal", "select"],
|
|
2175
|
+
commandId: "operator.undo"
|
|
2176
|
+
},
|
|
2177
|
+
"Control+o": {
|
|
2178
|
+
key: "Control+o",
|
|
2179
|
+
label: "Jump Back",
|
|
2180
|
+
description: "Navigate backward in Jumplist history",
|
|
2181
|
+
category: "Navigation",
|
|
2182
|
+
mode: ["normal", "select"],
|
|
2183
|
+
commandId: "jumplist.back"
|
|
2184
|
+
},
|
|
2185
|
+
"Control+i": {
|
|
2186
|
+
key: "Control+i",
|
|
2187
|
+
label: "Jump Forward",
|
|
2188
|
+
description: "Navigate forward in Jumplist history",
|
|
2189
|
+
category: "Navigation",
|
|
2190
|
+
mode: ["normal", "select"],
|
|
2191
|
+
commandId: "jumplist.forward"
|
|
2192
|
+
},
|
|
2193
|
+
"?": {
|
|
2194
|
+
key: "?",
|
|
2195
|
+
label: "Explore Keybindings",
|
|
2196
|
+
description: "Open searchable keybinding exploration menu (?)",
|
|
2197
|
+
category: "Navigation",
|
|
2198
|
+
mode: ["normal", "select"],
|
|
2199
|
+
commandId: "whichKey.openExplorer"
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
function createHelixPreset(leaderKey = "Space") {
|
|
2204
|
+
const textObjects = createTextObjectChildren();
|
|
2205
|
+
const unimpaired = createUnimpairedMenus();
|
|
2206
|
+
return {
|
|
2207
|
+
...createSharedMotionsAndOperators(),
|
|
2208
|
+
[leaderKey]: createSpaceMenu(leaderKey, "z"),
|
|
2209
|
+
"Control+w": createWindowMenu(),
|
|
2210
|
+
g: {
|
|
2211
|
+
key: "g",
|
|
2212
|
+
label: "+goto",
|
|
2213
|
+
group: "Goto",
|
|
2214
|
+
category: "Goto",
|
|
2215
|
+
mode: ["normal", "select"],
|
|
2216
|
+
children: {
|
|
2217
|
+
g: {
|
|
2218
|
+
key: "g",
|
|
2219
|
+
label: "Go to Top",
|
|
2220
|
+
description: "Jump to first item or top of document (gg)",
|
|
2221
|
+
category: "Goto",
|
|
2222
|
+
commandId: "motion.docStart"
|
|
2223
|
+
},
|
|
2224
|
+
e: {
|
|
2225
|
+
key: "e",
|
|
2226
|
+
label: "Go to End",
|
|
2227
|
+
description: "Jump to last item or bottom of document (ge)",
|
|
2228
|
+
category: "Goto",
|
|
2229
|
+
commandId: "motion.docEnd"
|
|
2230
|
+
},
|
|
2231
|
+
h: {
|
|
2232
|
+
key: "h",
|
|
2233
|
+
label: "Line / Group Start",
|
|
2234
|
+
description: "Move to start of line or control group (gh)",
|
|
2235
|
+
category: "Goto",
|
|
2236
|
+
commandId: "motion.lineStart"
|
|
2237
|
+
},
|
|
2238
|
+
l: {
|
|
2239
|
+
key: "l",
|
|
2240
|
+
label: "Line / Group End",
|
|
2241
|
+
description: "Move to end of line or control group (gl)",
|
|
2242
|
+
category: "Goto",
|
|
2243
|
+
commandId: "motion.lineEnd"
|
|
2244
|
+
},
|
|
2245
|
+
c: {
|
|
2246
|
+
key: "c",
|
|
2247
|
+
label: "Window Center",
|
|
2248
|
+
description: "Jump to center of visible viewport (gc)",
|
|
2249
|
+
category: "Goto",
|
|
2250
|
+
commandId: "view.center"
|
|
2251
|
+
},
|
|
2252
|
+
b: {
|
|
2253
|
+
key: "b",
|
|
2254
|
+
label: "Go to Bottom",
|
|
2255
|
+
description: "Jump to last item or bottom of document (gb)",
|
|
2256
|
+
category: "Goto",
|
|
2257
|
+
commandId: "motion.docEnd"
|
|
2258
|
+
},
|
|
2259
|
+
n: {
|
|
2260
|
+
key: "n",
|
|
2261
|
+
label: "Next Tab / Section",
|
|
2262
|
+
description: "Switch to next tab or section (gn)",
|
|
2263
|
+
category: "Goto",
|
|
2264
|
+
commandId: "tab.next"
|
|
2265
|
+
},
|
|
2266
|
+
p: {
|
|
2267
|
+
key: "p",
|
|
2268
|
+
label: "Previous Tab / Section",
|
|
2269
|
+
description: "Switch to previous tab or section (gp)",
|
|
2270
|
+
category: "Goto",
|
|
2271
|
+
commandId: "tab.prev"
|
|
2272
|
+
},
|
|
2273
|
+
t: {
|
|
2274
|
+
key: "t",
|
|
2275
|
+
label: "Next Tab",
|
|
2276
|
+
description: "Switch to next tab or section (gt)",
|
|
2277
|
+
category: "Goto",
|
|
2278
|
+
commandId: "tab.next"
|
|
2279
|
+
},
|
|
2280
|
+
T: {
|
|
2281
|
+
key: "T",
|
|
2282
|
+
label: "Previous Tab",
|
|
2283
|
+
description: "Switch to previous tab or section (gT)",
|
|
2284
|
+
category: "Goto",
|
|
2285
|
+
commandId: "tab.prev"
|
|
2286
|
+
},
|
|
2287
|
+
w: {
|
|
2288
|
+
key: "w",
|
|
2289
|
+
label: "Jump Label (2D)",
|
|
2290
|
+
description: "Overlay 2D home-row jump labels (gw)",
|
|
2291
|
+
category: "Goto",
|
|
2292
|
+
commandId: "jump.start"
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
},
|
|
2296
|
+
z: createViewMenu("z", "z"),
|
|
2297
|
+
Z: {
|
|
2298
|
+
key: "Z",
|
|
2299
|
+
label: "+sticky view",
|
|
2300
|
+
group: "View (Sticky)",
|
|
2301
|
+
description: "Lock View menu open until Escape",
|
|
2302
|
+
category: "View",
|
|
2303
|
+
mode: ["normal", "select"],
|
|
2304
|
+
sticky: true,
|
|
2305
|
+
loop: true,
|
|
2306
|
+
proxy: ["z"]
|
|
2307
|
+
},
|
|
2308
|
+
m: {
|
|
2309
|
+
key: "m",
|
|
2310
|
+
label: "+match",
|
|
2311
|
+
group: "Match / Text Objects",
|
|
2312
|
+
category: "Match / Text Objects",
|
|
2313
|
+
mode: ["normal", "select"],
|
|
2314
|
+
children: {
|
|
2315
|
+
m: {
|
|
2316
|
+
key: "m",
|
|
2317
|
+
label: "Goto Matching Bracket / Flip",
|
|
2318
|
+
description: "Flip selection anchor and head (mm)",
|
|
2319
|
+
category: "Match / Text Objects",
|
|
2320
|
+
commandId: "selection.flip"
|
|
2321
|
+
},
|
|
2322
|
+
...textObjects
|
|
2323
|
+
}
|
|
2324
|
+
},
|
|
2325
|
+
v: {
|
|
2326
|
+
key: "v",
|
|
2327
|
+
label: "Select / Extend Mode",
|
|
2328
|
+
description: "Toggle Helix select/extend mode (v)",
|
|
2329
|
+
category: "Selection",
|
|
2330
|
+
mode: ["normal", "select"],
|
|
2331
|
+
commandId: "mode.toggleSelect"
|
|
2332
|
+
},
|
|
2333
|
+
x: {
|
|
2334
|
+
key: "x",
|
|
2335
|
+
label: "Select Line",
|
|
2336
|
+
description: "Select current line or extend to next line (x)",
|
|
2337
|
+
category: "Selection",
|
|
2338
|
+
mode: ["normal", "select"],
|
|
2339
|
+
commandId: "motion.lineSelect"
|
|
2340
|
+
},
|
|
2341
|
+
";": {
|
|
2342
|
+
key: ";",
|
|
2343
|
+
label: "Collapse Selection",
|
|
2344
|
+
description: "Collapse selection to cursor head (;)",
|
|
2345
|
+
category: "Selection",
|
|
2346
|
+
mode: ["normal", "select"],
|
|
2347
|
+
commandId: "selection.collapse"
|
|
2348
|
+
},
|
|
2349
|
+
"Alt+;": {
|
|
2350
|
+
key: "Alt+;",
|
|
2351
|
+
label: "Flip Selection Direction",
|
|
2352
|
+
description: "Swap selection anchor and head (Alt-;)",
|
|
2353
|
+
category: "Selection",
|
|
2354
|
+
mode: ["normal", "select"],
|
|
2355
|
+
commandId: "selection.flip"
|
|
2356
|
+
},
|
|
2357
|
+
C: {
|
|
2358
|
+
key: "C",
|
|
2359
|
+
label: "Copy Selection Below",
|
|
2360
|
+
description: "Add secondary cursor on next line/block (C)",
|
|
2361
|
+
category: "Selection",
|
|
2362
|
+
mode: ["normal", "select"],
|
|
2363
|
+
commandId: "selection.addCursorBelow"
|
|
2364
|
+
},
|
|
2365
|
+
",": {
|
|
2366
|
+
key: ",",
|
|
2367
|
+
label: "Keep Primary Selection",
|
|
2368
|
+
description: "Clear secondary cursors and keep primary selection (,)",
|
|
2369
|
+
category: "Selection",
|
|
2370
|
+
mode: ["normal", "select"],
|
|
2371
|
+
commandId: "selection.keepPrimary"
|
|
2372
|
+
},
|
|
2373
|
+
U: {
|
|
2374
|
+
key: "U",
|
|
2375
|
+
label: "Redo",
|
|
2376
|
+
description: "Redo last undone editor transaction (U)",
|
|
2377
|
+
category: "Operator",
|
|
2378
|
+
mode: ["normal", "select"],
|
|
2379
|
+
commandId: "operator.redo"
|
|
2380
|
+
},
|
|
2381
|
+
...unimpaired
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
function createVimPreset(leaderKey = "Space") {
|
|
2385
|
+
const textObjects = createTextObjectChildren();
|
|
2386
|
+
const unimpaired = createUnimpairedMenus();
|
|
2387
|
+
return {
|
|
2388
|
+
...createSharedMotionsAndOperators(),
|
|
2389
|
+
[leaderKey]: createSpaceMenu(leaderKey, "z"),
|
|
2390
|
+
"Control+w": createWindowMenu(),
|
|
2391
|
+
g: {
|
|
2392
|
+
key: "g",
|
|
2393
|
+
label: "+goto",
|
|
2394
|
+
group: "Goto",
|
|
2395
|
+
category: "Goto",
|
|
2396
|
+
mode: ["normal", "select"],
|
|
2397
|
+
children: {
|
|
2398
|
+
g: {
|
|
2399
|
+
key: "g",
|
|
2400
|
+
label: "First Line / Top",
|
|
2401
|
+
description: "Jump to first item or top of document (gg)",
|
|
2402
|
+
category: "Goto",
|
|
2403
|
+
commandId: "motion.docStart"
|
|
2404
|
+
},
|
|
2405
|
+
e: {
|
|
2406
|
+
key: "e",
|
|
2407
|
+
label: "Backward Word End / Bottom",
|
|
2408
|
+
description: "Jump to bottom of pane or document (ge)",
|
|
2409
|
+
category: "Goto",
|
|
2410
|
+
commandId: "motion.docEnd"
|
|
2411
|
+
},
|
|
2412
|
+
b: {
|
|
2413
|
+
key: "b",
|
|
2414
|
+
label: "Last Line / Bottom",
|
|
2415
|
+
description: "Jump to last item or bottom of document (gb)",
|
|
2416
|
+
category: "Goto",
|
|
2417
|
+
commandId: "motion.docEnd"
|
|
2418
|
+
},
|
|
2419
|
+
h: {
|
|
2420
|
+
key: "h",
|
|
2421
|
+
label: "Start of Line",
|
|
2422
|
+
description: "Move to start of line or group (gh)",
|
|
2423
|
+
category: "Goto",
|
|
2424
|
+
commandId: "motion.lineStart"
|
|
2425
|
+
},
|
|
2426
|
+
l: {
|
|
2427
|
+
key: "l",
|
|
2428
|
+
label: "End of Line",
|
|
2429
|
+
description: "Move to end of line or group (gl)",
|
|
2430
|
+
category: "Goto",
|
|
2431
|
+
commandId: "motion.lineEnd"
|
|
2432
|
+
},
|
|
2433
|
+
t: {
|
|
2434
|
+
key: "t",
|
|
2435
|
+
label: "Next Tab / Section",
|
|
2436
|
+
description: "Go to next tab or section (gt)",
|
|
2437
|
+
category: "Goto",
|
|
2438
|
+
commandId: "tab.next"
|
|
2439
|
+
},
|
|
2440
|
+
T: {
|
|
2441
|
+
key: "T",
|
|
2442
|
+
label: "Previous Tab / Section",
|
|
2443
|
+
description: "Go to previous tab or section (gT)",
|
|
2444
|
+
category: "Goto",
|
|
2445
|
+
commandId: "tab.prev"
|
|
2446
|
+
},
|
|
2447
|
+
n: {
|
|
2448
|
+
key: "n",
|
|
2449
|
+
label: "Next Tab / Section",
|
|
2450
|
+
description: "Go to next tab or section (gn)",
|
|
2451
|
+
category: "Goto",
|
|
2452
|
+
commandId: "tab.next"
|
|
2453
|
+
},
|
|
2454
|
+
p: {
|
|
2455
|
+
key: "p",
|
|
2456
|
+
label: "Previous Tab / Section",
|
|
2457
|
+
description: "Go to previous tab or section (gp)",
|
|
2458
|
+
category: "Goto",
|
|
2459
|
+
commandId: "tab.prev"
|
|
2460
|
+
},
|
|
2461
|
+
w: {
|
|
2462
|
+
key: "w",
|
|
2463
|
+
label: "Jump Label (2D)",
|
|
2464
|
+
description: "Overlay 2D home-row jump labels (gw)",
|
|
2465
|
+
category: "Goto",
|
|
2466
|
+
commandId: "jump.start"
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
},
|
|
2470
|
+
G: {
|
|
2471
|
+
key: "G",
|
|
2472
|
+
label: "Last Line / Bottom",
|
|
2473
|
+
description: "Jump immediately to bottom of pane or document (G)",
|
|
2474
|
+
category: "Motion",
|
|
2475
|
+
mode: ["normal", "select"],
|
|
2476
|
+
commandId: "motion.docEnd"
|
|
2477
|
+
},
|
|
2478
|
+
s: {
|
|
2479
|
+
key: "s",
|
|
2480
|
+
label: "Flash / Sneak Jump",
|
|
2481
|
+
description: "Trigger 2D forward jump labels (s)",
|
|
2482
|
+
category: "Navigation",
|
|
2483
|
+
mode: ["normal", "select"],
|
|
2484
|
+
commandId: "jump.start"
|
|
2485
|
+
},
|
|
2486
|
+
v: {
|
|
2487
|
+
key: "v",
|
|
2488
|
+
label: "Visual Mode",
|
|
2489
|
+
description: "Toggle characterwise Visual selection mode (v)",
|
|
2490
|
+
category: "Mode",
|
|
2491
|
+
mode: ["normal", "select"],
|
|
2492
|
+
commandId: "mode.toggleSelect"
|
|
2493
|
+
},
|
|
2494
|
+
V: {
|
|
2495
|
+
key: "V",
|
|
2496
|
+
label: "Visual Line Mode",
|
|
2497
|
+
description: "Select entire line in Visual Line mode (V)",
|
|
2498
|
+
category: "Mode",
|
|
2499
|
+
mode: ["normal", "select"],
|
|
2500
|
+
commandId: "motion.lineSelect"
|
|
2501
|
+
},
|
|
2502
|
+
z: createViewMenu("z", "z"),
|
|
2503
|
+
m: {
|
|
2504
|
+
key: "m",
|
|
2505
|
+
label: "+text-objects",
|
|
2506
|
+
group: "Text Objects",
|
|
2507
|
+
category: "Match / Text Objects",
|
|
2508
|
+
mode: ["normal", "select"],
|
|
2509
|
+
children: textObjects
|
|
2510
|
+
},
|
|
2511
|
+
"Control+r": {
|
|
2512
|
+
key: "Control+r",
|
|
2513
|
+
label: "Redo",
|
|
2514
|
+
description: "Redo last undone editor transaction (Ctrl-r)",
|
|
2515
|
+
category: "Operator",
|
|
2516
|
+
mode: ["normal", "select"],
|
|
2517
|
+
commandId: "operator.redo"
|
|
2518
|
+
},
|
|
2519
|
+
...unimpaired
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
function createKakounePreset(leaderKey = "Space") {
|
|
2523
|
+
const textObjects = createTextObjectChildren();
|
|
2524
|
+
const unimpaired = createUnimpairedMenus();
|
|
2525
|
+
return {
|
|
2526
|
+
...createSharedMotionsAndOperators(),
|
|
2527
|
+
[leaderKey]: createSpaceMenu(leaderKey, "v"),
|
|
2528
|
+
"Control+w": createWindowMenu(),
|
|
2529
|
+
g: {
|
|
2530
|
+
key: "g",
|
|
2531
|
+
label: "+goto",
|
|
2532
|
+
group: "Goto",
|
|
2533
|
+
category: "Goto",
|
|
2534
|
+
mode: ["normal", "select"],
|
|
2535
|
+
children: {
|
|
2536
|
+
g: {
|
|
2537
|
+
key: "g",
|
|
2538
|
+
label: "Buffer Top",
|
|
2539
|
+
description: "Go to top of buffer or first item (gg)",
|
|
2540
|
+
category: "Goto",
|
|
2541
|
+
commandId: "motion.docStart"
|
|
2542
|
+
},
|
|
2543
|
+
k: {
|
|
2544
|
+
key: "k",
|
|
2545
|
+
label: "Buffer Top",
|
|
2546
|
+
description: "Go to top of buffer (gk)",
|
|
2547
|
+
category: "Goto",
|
|
2548
|
+
commandId: "motion.docStart"
|
|
2549
|
+
},
|
|
2550
|
+
j: {
|
|
2551
|
+
key: "j",
|
|
2552
|
+
label: "Buffer Bottom",
|
|
2553
|
+
description: "Go to bottom of buffer (gj)",
|
|
2554
|
+
category: "Goto",
|
|
2555
|
+
commandId: "motion.docEnd"
|
|
2556
|
+
},
|
|
2557
|
+
e: {
|
|
2558
|
+
key: "e",
|
|
2559
|
+
label: "Buffer End",
|
|
2560
|
+
description: "Go to end of buffer (ge)",
|
|
2561
|
+
category: "Goto",
|
|
2562
|
+
commandId: "motion.docEnd"
|
|
2563
|
+
},
|
|
2564
|
+
h: {
|
|
2565
|
+
key: "h",
|
|
2566
|
+
label: "Line Start",
|
|
2567
|
+
description: "Go to start of line or group (gh)",
|
|
2568
|
+
category: "Goto",
|
|
2569
|
+
commandId: "motion.lineStart"
|
|
2570
|
+
},
|
|
2571
|
+
l: {
|
|
2572
|
+
key: "l",
|
|
2573
|
+
label: "Line End",
|
|
2574
|
+
description: "Go to end of line or group (gl)",
|
|
2575
|
+
category: "Goto",
|
|
2576
|
+
commandId: "motion.lineEnd"
|
|
2577
|
+
},
|
|
2578
|
+
c: {
|
|
2579
|
+
key: "c",
|
|
2580
|
+
label: "Window Center",
|
|
2581
|
+
description: "Go to center of visible window (gc)",
|
|
2582
|
+
category: "Goto",
|
|
2583
|
+
commandId: "view.center"
|
|
2584
|
+
},
|
|
2585
|
+
b: {
|
|
2586
|
+
key: "b",
|
|
2587
|
+
label: "Buffer Bottom",
|
|
2588
|
+
description: "Go to bottom of buffer or last item (gb)",
|
|
2589
|
+
category: "Goto",
|
|
2590
|
+
commandId: "motion.docEnd"
|
|
2591
|
+
},
|
|
2592
|
+
a: {
|
|
2593
|
+
key: "a",
|
|
2594
|
+
label: "Previous Location",
|
|
2595
|
+
description: "Jump to alternate / previous location (ga)",
|
|
2596
|
+
category: "Goto",
|
|
2597
|
+
commandId: "jumplist.back"
|
|
2598
|
+
},
|
|
2599
|
+
n: {
|
|
2600
|
+
key: "n",
|
|
2601
|
+
label: "Next Tab / Section",
|
|
2602
|
+
description: "Switch to next tab or section (gn)",
|
|
2603
|
+
category: "Goto",
|
|
2604
|
+
commandId: "tab.next"
|
|
2605
|
+
},
|
|
2606
|
+
p: {
|
|
2607
|
+
key: "p",
|
|
2608
|
+
label: "Previous Tab / Section",
|
|
2609
|
+
description: "Switch to previous tab or section (gp)",
|
|
2610
|
+
category: "Goto",
|
|
2611
|
+
commandId: "tab.prev"
|
|
2612
|
+
},
|
|
2613
|
+
t: {
|
|
2614
|
+
key: "t",
|
|
2615
|
+
label: "Next Tab",
|
|
2616
|
+
description: "Switch to next tab or section (gt)",
|
|
2617
|
+
category: "Goto",
|
|
2618
|
+
commandId: "tab.next"
|
|
2619
|
+
},
|
|
2620
|
+
T: {
|
|
2621
|
+
key: "T",
|
|
2622
|
+
label: "Previous Tab",
|
|
2623
|
+
description: "Switch to previous tab or section (gT)",
|
|
2624
|
+
category: "Goto",
|
|
2625
|
+
commandId: "tab.prev"
|
|
2626
|
+
},
|
|
2627
|
+
w: {
|
|
2628
|
+
key: "w",
|
|
2629
|
+
label: "Jump Label (2D)",
|
|
2630
|
+
description: "Overlay 2D home-row jump labels (gw)",
|
|
2631
|
+
category: "Goto",
|
|
2632
|
+
commandId: "jump.start"
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
},
|
|
2636
|
+
v: createViewMenu("v", "v"),
|
|
2637
|
+
V: {
|
|
2638
|
+
key: "V",
|
|
2639
|
+
label: "+lock view",
|
|
2640
|
+
group: "View (Lock)",
|
|
2641
|
+
description: "Lock Kakoune View mode open until Escape (V)",
|
|
2642
|
+
category: "View",
|
|
2643
|
+
mode: ["normal", "select"],
|
|
2644
|
+
sticky: true,
|
|
2645
|
+
loop: true,
|
|
2646
|
+
proxy: ["v"]
|
|
2647
|
+
},
|
|
2648
|
+
m: {
|
|
2649
|
+
key: "m",
|
|
2650
|
+
label: "+object",
|
|
2651
|
+
group: "Object / Match",
|
|
2652
|
+
category: "Match / Text Objects",
|
|
2653
|
+
mode: ["normal", "select"],
|
|
2654
|
+
children: textObjects
|
|
2655
|
+
},
|
|
2656
|
+
x: {
|
|
2657
|
+
key: "x",
|
|
2658
|
+
label: "Select Line",
|
|
2659
|
+
description: "Select current line (x)",
|
|
2660
|
+
category: "Selection",
|
|
2661
|
+
mode: ["normal", "select"],
|
|
2662
|
+
commandId: "motion.lineSelect"
|
|
2663
|
+
},
|
|
2664
|
+
";": {
|
|
2665
|
+
key: ";",
|
|
2666
|
+
label: "Reduce Selection to Cursor",
|
|
2667
|
+
description: "Collapse selection to single cursor (;)",
|
|
2668
|
+
category: "Selection",
|
|
2669
|
+
mode: ["normal", "select"],
|
|
2670
|
+
commandId: "selection.collapse"
|
|
2671
|
+
},
|
|
2672
|
+
"Alt+;": {
|
|
2673
|
+
key: "Alt+;",
|
|
2674
|
+
label: "Flip Selection Direction",
|
|
2675
|
+
description: "Swap anchor and cursor (Alt-;)",
|
|
2676
|
+
category: "Selection",
|
|
2677
|
+
mode: ["normal", "select"],
|
|
2678
|
+
commandId: "selection.flip"
|
|
2679
|
+
},
|
|
2680
|
+
C: {
|
|
2681
|
+
key: "C",
|
|
2682
|
+
label: "Copy Selection on Next Line",
|
|
2683
|
+
description: "Add secondary selection on next line (C)",
|
|
2684
|
+
category: "Selection",
|
|
2685
|
+
mode: ["normal", "select"],
|
|
2686
|
+
commandId: "selection.addCursorBelow"
|
|
2687
|
+
},
|
|
2688
|
+
",": {
|
|
2689
|
+
key: ",",
|
|
2690
|
+
label: "Keep Main Selection",
|
|
2691
|
+
description: "Clear secondary selections (,)",
|
|
2692
|
+
category: "Selection",
|
|
2693
|
+
mode: ["normal", "select"],
|
|
2694
|
+
commandId: "selection.keepPrimary"
|
|
2695
|
+
},
|
|
2696
|
+
U: {
|
|
2697
|
+
key: "U",
|
|
2698
|
+
label: "Redo",
|
|
2699
|
+
description: "Redo last undone change (U)",
|
|
2700
|
+
category: "Operator",
|
|
2701
|
+
mode: ["normal", "select"],
|
|
2702
|
+
commandId: "operator.redo"
|
|
2703
|
+
},
|
|
2704
|
+
...unimpaired
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
function getPresetKeymap(preset, leaderKey = "Space") {
|
|
2708
|
+
switch (preset) {
|
|
2709
|
+
case "vim":
|
|
2710
|
+
return createVimPreset(leaderKey);
|
|
2711
|
+
case "kakoune":
|
|
2712
|
+
return createKakounePreset(leaderKey);
|
|
2713
|
+
case "helix":
|
|
2714
|
+
default:
|
|
2715
|
+
return createHelixPreset(leaderKey);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
// src/which-key/controller.ts
|
|
2720
|
+
import { isModifierKey, normalizeKeyName, parseKeyboardEvent } from "@tanstack/hotkeys";
|
|
2721
|
+
import { trackDismissableBranch } from "@zag-js/dismissable";
|
|
2722
|
+
import { getFirstFocusable, getFocusables, isEditableElement, isInView } from "@zag-js/dom-query";
|
|
2723
|
+
import { setInteractionModality, trackInteractionModality } from "@zag-js/focus-visible";
|
|
2724
|
+
import { createLiveRegion } from "@zag-js/live-region";
|
|
2725
|
+
function mergeKeymapTrees(base, overlay) {
|
|
2726
|
+
const result = { ...base };
|
|
2727
|
+
for (const [key, node] of Object.entries(overlay)) {
|
|
2728
|
+
const existing = result[key];
|
|
2729
|
+
if (existing && existing.children && node.children) {
|
|
2730
|
+
result[key] = {
|
|
2731
|
+
...existing,
|
|
2732
|
+
...node,
|
|
2733
|
+
children: mergeKeymapTrees(existing.children, node.children)
|
|
2734
|
+
};
|
|
2735
|
+
} else {
|
|
2736
|
+
result[key] = node;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
return result;
|
|
2740
|
+
}
|
|
2741
|
+
function isElementLike(value) {
|
|
2742
|
+
if (!value || typeof value !== "object") return false;
|
|
2743
|
+
if (typeof Element !== "undefined" && value instanceof Element) return true;
|
|
2744
|
+
return "parentElement" in value || "tagName" in value;
|
|
2745
|
+
}
|
|
2746
|
+
function isHTMLElementLike(value) {
|
|
2747
|
+
if (!value || typeof value !== "object") return false;
|
|
2748
|
+
if (typeof HTMLElement !== "undefined" && value instanceof HTMLElement) {
|
|
2749
|
+
return true;
|
|
2750
|
+
}
|
|
2751
|
+
return "parentElement" in value || "tagName" in value;
|
|
2752
|
+
}
|
|
2753
|
+
function isTextEntryElement(el) {
|
|
2754
|
+
if (!el || !isHTMLElementLike(el)) return false;
|
|
2755
|
+
if (getModalEditor(el)) return true;
|
|
2756
|
+
if (el.isContentEditable || el.getAttribute?.("contenteditable") === "true") {
|
|
2757
|
+
return true;
|
|
2758
|
+
}
|
|
2759
|
+
const tag = typeof el.tagName === "string" ? el.tagName.toLowerCase() : "";
|
|
2760
|
+
if (tag === "textarea") {
|
|
2761
|
+
return !el.disabled && !el.readOnly;
|
|
2762
|
+
}
|
|
2763
|
+
if (tag === "input") {
|
|
2764
|
+
const input = el;
|
|
2765
|
+
if (input.disabled || input.readOnly) return false;
|
|
2766
|
+
const nonTextTypes = /* @__PURE__ */ new Set([
|
|
2767
|
+
"button",
|
|
2768
|
+
"checkbox",
|
|
2769
|
+
"color",
|
|
2770
|
+
"file",
|
|
2771
|
+
"hidden",
|
|
2772
|
+
"image",
|
|
2773
|
+
"radio",
|
|
2774
|
+
"range",
|
|
2775
|
+
"reset",
|
|
2776
|
+
"submit"
|
|
2777
|
+
]);
|
|
2778
|
+
return !nonTextTypes.has((input.type || "text").toLowerCase());
|
|
2779
|
+
}
|
|
2780
|
+
try {
|
|
2781
|
+
return isEditableElement(el);
|
|
2782
|
+
} catch {
|
|
2783
|
+
return false;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
function eventToChordKeys(event) {
|
|
2787
|
+
const rawKey = event.key;
|
|
2788
|
+
if (!rawKey) return [];
|
|
2789
|
+
const normalizedName = normalizeKeyName(rawKey);
|
|
2790
|
+
if (isModifierKey(normalizedName) || rawKey === "Shift" || rawKey === "Control" || rawKey === "Alt" || rawKey === "Meta") {
|
|
2791
|
+
return [];
|
|
2792
|
+
}
|
|
2793
|
+
const hasCtrl = event.ctrlKey;
|
|
2794
|
+
const hasAlt = event.altKey;
|
|
2795
|
+
const hasMeta = event.metaKey;
|
|
2796
|
+
const hasShift = event.shiftKey;
|
|
2797
|
+
const baseKey = rawKey === " " || event.code === "Space" ? "Space" : rawKey;
|
|
2798
|
+
if (hasCtrl || hasAlt || hasMeta) {
|
|
2799
|
+
const mods = [];
|
|
2800
|
+
if (hasCtrl) mods.push("Control");
|
|
2801
|
+
if (hasAlt) mods.push("Alt");
|
|
2802
|
+
if (hasShift && baseKey.length > 1) mods.push("Shift");
|
|
2803
|
+
if (hasMeta) mods.push("Meta");
|
|
2804
|
+
const candidates2 = [];
|
|
2805
|
+
const primaryKey = baseKey.length === 1 ? baseKey : normalizedName;
|
|
2806
|
+
candidates2.push([...mods, primaryKey].join("+"));
|
|
2807
|
+
if (baseKey.length === 1 && baseKey.toLowerCase() !== baseKey) {
|
|
2808
|
+
candidates2.push([...mods, baseKey.toLowerCase()].join("+"));
|
|
2809
|
+
}
|
|
2810
|
+
try {
|
|
2811
|
+
const parsed = parseKeyboardEvent(event);
|
|
2812
|
+
if (parsed?.key) {
|
|
2813
|
+
const parsedMods = [];
|
|
2814
|
+
if (parsed.ctrl) parsedMods.push("Control");
|
|
2815
|
+
if (parsed.alt) parsedMods.push("Alt");
|
|
2816
|
+
if (parsed.shift) parsedMods.push("Shift");
|
|
2817
|
+
if (parsed.meta) parsedMods.push("Meta");
|
|
2818
|
+
const fromTanstack = [...parsedMods, parsed.key].join("+");
|
|
2819
|
+
if (!candidates2.includes(fromTanstack)) {
|
|
2820
|
+
candidates2.push(fromTanstack);
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
} catch {
|
|
2824
|
+
}
|
|
2825
|
+
return candidates2;
|
|
2826
|
+
}
|
|
2827
|
+
const candidates = [baseKey];
|
|
2828
|
+
if (hasShift && baseKey.length === 1) {
|
|
2829
|
+
candidates.push(`Shift+${baseKey.toUpperCase()}`);
|
|
2830
|
+
candidates.push(`Shift+${baseKey}`);
|
|
2831
|
+
} else if (baseKey.length > 1 && normalizedName !== baseKey) {
|
|
2832
|
+
candidates.push(normalizedName);
|
|
2833
|
+
}
|
|
2834
|
+
return candidates;
|
|
2835
|
+
}
|
|
2836
|
+
function getTopMostModalDialog(doc) {
|
|
2837
|
+
const dialogs = Array.from(
|
|
2838
|
+
doc.querySelectorAll(
|
|
2839
|
+
'[data-scope="dialog"][data-part="content"][data-state="open"], [role="dialog"][aria-modal="true"]:not([data-state="closed"]), [role="alertdialog"][aria-modal="true"]:not([data-state="closed"])'
|
|
2840
|
+
)
|
|
2841
|
+
).filter((el) => !el.hasAttribute("data-which-key-explorer"));
|
|
2842
|
+
if (dialogs.length === 0) return null;
|
|
2843
|
+
for (let i = dialogs.length - 1; i >= 0; i -= 1) {
|
|
2844
|
+
const candidate = dialogs[i];
|
|
2845
|
+
if (candidate.style.pointerEvents !== "none") {
|
|
2846
|
+
return candidate;
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
return dialogs[dialogs.length - 1] ?? null;
|
|
2850
|
+
}
|
|
2851
|
+
function getPaneFocusableItems(container, ownScope) {
|
|
2852
|
+
const doc = container.ownerDocument;
|
|
2853
|
+
const activeEl = doc?.activeElement instanceof HTMLElement ? doc.activeElement : null;
|
|
2854
|
+
const enteredExample = !ownScope && activeEl && !activeEl.hasAttribute("data-example") ? activeEl.closest("[data-example]") : null;
|
|
2855
|
+
const searchRoot = enteredExample && container.contains(enteredExample) ? enteredExample.querySelector("[data-example-preview]") ?? enteredExample : container;
|
|
2856
|
+
const raw = getFocusables(searchRoot, { includeContainer: false });
|
|
2857
|
+
return raw.filter((el) => {
|
|
2858
|
+
if (!(el instanceof HTMLElement)) return false;
|
|
2859
|
+
if (el.closest("[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay]")) {
|
|
2860
|
+
return false;
|
|
2861
|
+
}
|
|
2862
|
+
const fwEl = el.closest("[data-fw]");
|
|
2863
|
+
const activeFw = doc?.documentElement?.getAttribute("data-framework");
|
|
2864
|
+
if (fwEl && activeFw && fwEl.getAttribute("data-fw") !== activeFw) {
|
|
2865
|
+
return false;
|
|
2866
|
+
}
|
|
2867
|
+
if (!ownScope) {
|
|
2868
|
+
if (!enteredExample) {
|
|
2869
|
+
const parentExample = el.parentElement?.closest("[data-example]");
|
|
2870
|
+
if (parentExample) return false;
|
|
2871
|
+
}
|
|
2872
|
+
const nestedScope = el.closest("[data-which-key-scope]");
|
|
2873
|
+
if (nestedScope) return false;
|
|
2874
|
+
}
|
|
2875
|
+
if (el.getAttribute("aria-hidden") === "true" || el.hasAttribute("inert")) {
|
|
2876
|
+
return false;
|
|
2877
|
+
}
|
|
2878
|
+
return true;
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
function getJumpableItems(container, ownScope) {
|
|
2882
|
+
const doc = container.ownerDocument;
|
|
2883
|
+
const rawFocusables = getFocusables(container, { includeContainer: false });
|
|
2884
|
+
const rawTabs = Array.from(
|
|
2885
|
+
container.querySelectorAll(
|
|
2886
|
+
'[role="tab"]:not([disabled]):not([data-disabled]):not([aria-disabled="true"])'
|
|
2887
|
+
)
|
|
2888
|
+
);
|
|
2889
|
+
const combined = [];
|
|
2890
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2891
|
+
for (const el of [...rawFocusables, ...rawTabs]) {
|
|
2892
|
+
if (!(el instanceof HTMLElement) || seen.has(el)) continue;
|
|
2893
|
+
seen.add(el);
|
|
2894
|
+
if (el.closest("[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay]")) {
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
2897
|
+
const fwEl = el.closest("[data-fw]");
|
|
2898
|
+
const activeFw = doc?.documentElement?.getAttribute("data-framework");
|
|
2899
|
+
if (fwEl && activeFw && fwEl.getAttribute("data-fw") !== activeFw) {
|
|
2900
|
+
continue;
|
|
2901
|
+
}
|
|
2902
|
+
if (!ownScope) {
|
|
2903
|
+
const nestedScope = el.closest("[data-which-key-scope]");
|
|
2904
|
+
if (nestedScope) continue;
|
|
2905
|
+
}
|
|
2906
|
+
if (el.getAttribute("aria-hidden") === "true" || el.hasAttribute("inert")) {
|
|
2907
|
+
continue;
|
|
2908
|
+
}
|
|
2909
|
+
combined.push(el);
|
|
2910
|
+
}
|
|
2911
|
+
return combined;
|
|
2912
|
+
}
|
|
2913
|
+
var globalWhichKeyState = globalThis;
|
|
2914
|
+
var attachedEntriesByDoc = globalWhichKeyState.__helicalAttachedEntriesByDoc__ ??= /* @__PURE__ */ new WeakMap();
|
|
2915
|
+
var lastInteractedScopeByDoc = globalWhichKeyState.__helicalLastInteractedScopeByDoc__ ??= /* @__PURE__ */ new WeakMap();
|
|
2916
|
+
var rootControllerByDoc = globalWhichKeyState.__helicalRootControllerByDoc__ ??= /* @__PURE__ */ new WeakMap();
|
|
2917
|
+
var rootControllerListenersByDoc = globalWhichKeyState.__helicalRootControllerListenersByDoc__ ??= /* @__PURE__ */ new WeakMap();
|
|
2918
|
+
function notifyRootControllerListeners(doc) {
|
|
2919
|
+
const set = rootControllerListenersByDoc.get(doc);
|
|
2920
|
+
if (!set) return;
|
|
2921
|
+
for (const fn of set) {
|
|
2922
|
+
fn();
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
function getDocumentWhichKeyController(doc) {
|
|
2926
|
+
const resolved = doc ?? (typeof document !== "undefined" ? document : void 0);
|
|
2927
|
+
if (!resolved) return null;
|
|
2928
|
+
return rootControllerByDoc.get(resolved) ?? null;
|
|
2929
|
+
}
|
|
2930
|
+
function subscribeDocumentWhichKeyController(doc, listener) {
|
|
2931
|
+
const resolved = doc ?? (typeof document !== "undefined" ? document : void 0);
|
|
2932
|
+
if (!resolved) return () => {
|
|
2933
|
+
};
|
|
2934
|
+
let set = rootControllerListenersByDoc.get(resolved);
|
|
2935
|
+
if (!set) {
|
|
2936
|
+
set = /* @__PURE__ */ new Set();
|
|
2937
|
+
rootControllerListenersByDoc.set(resolved, set);
|
|
2938
|
+
}
|
|
2939
|
+
set.add(listener);
|
|
2940
|
+
return () => {
|
|
2941
|
+
set?.delete(listener);
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2944
|
+
function isScopeElementActive(scopeEl, doc) {
|
|
2945
|
+
if (!scopeEl) return true;
|
|
2946
|
+
if (!scopeEl.isConnected) return false;
|
|
2947
|
+
const fwEl = scopeEl.closest?.("[data-fw]");
|
|
2948
|
+
const activeFw = doc.documentElement?.getAttribute("data-framework");
|
|
2949
|
+
if (fwEl && activeFw && fwEl.getAttribute("data-fw") !== activeFw) {
|
|
2950
|
+
return false;
|
|
2951
|
+
}
|
|
2952
|
+
return true;
|
|
2953
|
+
}
|
|
2954
|
+
function shouldEntryHandleEvent(entry, doc) {
|
|
2955
|
+
const ownScope = entry.getScopeElement();
|
|
2956
|
+
if (!isScopeElementActive(ownScope, doc)) {
|
|
2957
|
+
return false;
|
|
2958
|
+
}
|
|
2959
|
+
const allEntries = attachedEntriesByDoc.get(doc);
|
|
2960
|
+
if (!allEntries || allEntries.size <= 1) {
|
|
2961
|
+
return true;
|
|
2962
|
+
}
|
|
2963
|
+
const visibleEntries = Array.from(allEntries).filter((e) => isScopeElementActive(e.getScopeElement(), doc));
|
|
2964
|
+
if (visibleEntries.length <= 1) {
|
|
2965
|
+
return visibleEntries[0] === entry;
|
|
2966
|
+
}
|
|
2967
|
+
const busyEntry = visibleEntries.find((e) => e.isBusy());
|
|
2968
|
+
if (busyEntry) {
|
|
2969
|
+
return busyEntry === entry;
|
|
2970
|
+
}
|
|
2971
|
+
const activeEl = doc.activeElement && doc.activeElement !== doc.body && doc.activeElement !== doc.documentElement && isElementLike(doc.activeElement) ? doc.activeElement : null;
|
|
2972
|
+
const focusedScope = activeEl ? activeEl.closest?.("[data-which-key-scope]") ?? null : null;
|
|
2973
|
+
const rememberedScope = lastInteractedScopeByDoc.get(doc) ?? null;
|
|
2974
|
+
const targetScope = focusedScope && isScopeElementActive(focusedScope, doc) ? focusedScope : rememberedScope && isScopeElementActive(rememberedScope, doc) ? rememberedScope : null;
|
|
2975
|
+
if (targetScope) {
|
|
2976
|
+
const scopedMatch = visibleEntries.find((e) => e.getScopeElement() === targetScope);
|
|
2977
|
+
if (scopedMatch) {
|
|
2978
|
+
return scopedMatch === entry;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
const rootEntry = visibleEntries.find((e) => e.getScopeElement() === null);
|
|
2982
|
+
if (rootEntry) {
|
|
2983
|
+
return rootEntry === entry;
|
|
2984
|
+
}
|
|
2985
|
+
return visibleEntries[0] === entry;
|
|
2986
|
+
}
|
|
2987
|
+
function createWhichKeyController(options = {}) {
|
|
2988
|
+
const storageKey = options.storageKey;
|
|
2989
|
+
function isMobileViewport() {
|
|
2990
|
+
if (options.disableOnMobile === false) return false;
|
|
2991
|
+
const doc = resolveDoc();
|
|
2992
|
+
const win = doc?.defaultView ?? (typeof window !== "undefined" ? window : null);
|
|
2993
|
+
if (!win || typeof win.matchMedia !== "function") return false;
|
|
2994
|
+
try {
|
|
2995
|
+
return win.matchMedia("(pointer: coarse) and (hover: none)").matches || win.matchMedia("(max-width: 767px) and (pointer: coarse)").matches;
|
|
2996
|
+
} catch {
|
|
2997
|
+
return false;
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
function isControllerEnabled() {
|
|
3001
|
+
if (options.enabled === false) return false;
|
|
3002
|
+
if (isMobileViewport()) return false;
|
|
3003
|
+
return true;
|
|
3004
|
+
}
|
|
3005
|
+
function readStoredPreset() {
|
|
3006
|
+
if (!storageKey || typeof window === "undefined") return null;
|
|
3007
|
+
try {
|
|
3008
|
+
const raw = window.localStorage.getItem(`${storageKey}:keymap-preset`);
|
|
3009
|
+
if (raw === "helix" || raw === "vim" || raw === "kakoune") return raw;
|
|
3010
|
+
} catch {
|
|
3011
|
+
}
|
|
3012
|
+
return null;
|
|
3013
|
+
}
|
|
3014
|
+
function writeStoredPreset(next) {
|
|
3015
|
+
const doc = resolveDoc();
|
|
3016
|
+
if (doc?.documentElement && !options.getScopeElement?.()) {
|
|
3017
|
+
doc.documentElement.dataset.keymapPreset = next;
|
|
3018
|
+
}
|
|
3019
|
+
if (!storageKey || typeof window === "undefined") return;
|
|
3020
|
+
try {
|
|
3021
|
+
window.localStorage.setItem(`${storageKey}:keymap-preset`, next);
|
|
3022
|
+
} catch {
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
function readStoredJumpAction() {
|
|
3026
|
+
if (!storageKey || typeof window === "undefined") return null;
|
|
3027
|
+
try {
|
|
3028
|
+
const raw = window.localStorage.getItem(`${storageKey}:jump-action`);
|
|
3029
|
+
if (raw === "activate" || raw === "focus") return raw;
|
|
3030
|
+
} catch {
|
|
3031
|
+
}
|
|
3032
|
+
return null;
|
|
3033
|
+
}
|
|
3034
|
+
function writeStoredJumpAction(next) {
|
|
3035
|
+
const doc = resolveDoc();
|
|
3036
|
+
if (doc?.documentElement && !options.getScopeElement?.()) {
|
|
3037
|
+
doc.documentElement.dataset.jumpAction = next;
|
|
3038
|
+
}
|
|
3039
|
+
if (!storageKey || typeof window === "undefined") return;
|
|
3040
|
+
try {
|
|
3041
|
+
window.localStorage.setItem(`${storageKey}:jump-action`, next);
|
|
3042
|
+
} catch {
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
let preset = options.preset ?? readStoredPreset() ?? "helix";
|
|
3046
|
+
let mode = options.defaultMode ?? "normal";
|
|
3047
|
+
const leaderKey = options.leaderKey ?? "Space";
|
|
3048
|
+
let jumpAction = options.jumpAction ?? readStoredJumpAction() ?? "activate";
|
|
3049
|
+
const jumpAlphabet = options.jumpAlphabet ?? DEFAULT_JUMP_ALPHABET;
|
|
3050
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3051
|
+
const keymapLayers = /* @__PURE__ */ new Map();
|
|
3052
|
+
const commandHandlers = /* @__PURE__ */ new Map();
|
|
3053
|
+
const panes = /* @__PURE__ */ new Map();
|
|
3054
|
+
const jumplist = createJumplist(50);
|
|
3055
|
+
if (options.keymap) {
|
|
3056
|
+
keymapLayers.set("__initial__", {
|
|
3057
|
+
id: "__initial__",
|
|
3058
|
+
nodes: options.keymap,
|
|
3059
|
+
enabled: true
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
if (options.commands) {
|
|
3063
|
+
for (const [cmdId, handler] of Object.entries(options.commands)) {
|
|
3064
|
+
commandHandlers.set(cmdId, handler);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
let activePath = [];
|
|
3068
|
+
let sticky = false;
|
|
3069
|
+
let countBuffer = "";
|
|
3070
|
+
let explorerOpen = false;
|
|
3071
|
+
let explorerQuery = "";
|
|
3072
|
+
let activePaneId = null;
|
|
3073
|
+
let jumpQuery = "";
|
|
3074
|
+
let rawJumpTargets = [];
|
|
3075
|
+
let statusMessage = "";
|
|
3076
|
+
let programmaticFocusDepth = 0;
|
|
3077
|
+
let liveRegion = null;
|
|
3078
|
+
let detachCleanups = [];
|
|
3079
|
+
function resolveDoc() {
|
|
3080
|
+
if (options.getDocument) {
|
|
3081
|
+
try {
|
|
3082
|
+
return options.getDocument();
|
|
3083
|
+
} catch {
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
return typeof document !== "undefined" ? document : null;
|
|
3087
|
+
}
|
|
3088
|
+
function announce(message) {
|
|
3089
|
+
statusMessage = message;
|
|
3090
|
+
try {
|
|
3091
|
+
liveRegion?.announce(message);
|
|
3092
|
+
} catch {
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
function buildMergedTrie() {
|
|
3096
|
+
let trie = getPresetKeymap(preset, leaderKey);
|
|
3097
|
+
for (const layer of keymapLayers.values()) {
|
|
3098
|
+
if (!layer.enabled) continue;
|
|
3099
|
+
if (layer.scope && layer.scope !== activePaneId) continue;
|
|
3100
|
+
trie = mergeKeymapTrees(trie, layer.nodes);
|
|
3101
|
+
}
|
|
3102
|
+
return trie;
|
|
3103
|
+
}
|
|
3104
|
+
function syncPaneActiveAttributes() {
|
|
3105
|
+
for (const pane of panes.values()) {
|
|
3106
|
+
if (pane.element && typeof pane.element.setAttribute === "function") {
|
|
3107
|
+
pane.element.setAttribute("data-pane-active", pane.id === activePaneId ? "true" : "false");
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
function syncDomPanes(docOverride) {
|
|
3112
|
+
const doc = docOverride ?? resolveDoc();
|
|
3113
|
+
if (!doc || typeof doc.querySelectorAll !== "function") return;
|
|
3114
|
+
const ownScope = options.getScopeElement?.() ?? null;
|
|
3115
|
+
const root = ownScope ?? doc.body;
|
|
3116
|
+
if (!root || typeof root.querySelectorAll !== "function") return;
|
|
3117
|
+
const elements = Array.from(root.querySelectorAll("[data-pane-id]"));
|
|
3118
|
+
for (const el of elements) {
|
|
3119
|
+
if (!ownScope && el.closest("[data-which-key-scope]")) continue;
|
|
3120
|
+
const id = el.getAttribute("data-pane-id");
|
|
3121
|
+
if (!id) continue;
|
|
3122
|
+
const existing = panes.get(id);
|
|
3123
|
+
if (existing && existing.element === el) continue;
|
|
3124
|
+
const title = el.getAttribute("data-pane-title") || existing?.title || id;
|
|
3125
|
+
const orderAttr = el.getAttribute("data-pane-order");
|
|
3126
|
+
const parsedOrder = orderAttr ? Number.parseInt(orderAttr, 10) : Number.NaN;
|
|
3127
|
+
const order = !Number.isNaN(parsedOrder) ? parsedOrder : existing?.order ?? panes.size + 1;
|
|
3128
|
+
const disabled = el.getAttribute("data-pane-disabled") === "true";
|
|
3129
|
+
panes.set(id, {
|
|
3130
|
+
id,
|
|
3131
|
+
title,
|
|
3132
|
+
element: el,
|
|
3133
|
+
disabled,
|
|
3134
|
+
order,
|
|
3135
|
+
lastFocusedElement: existing?.lastFocusedElement ?? null
|
|
3136
|
+
});
|
|
3137
|
+
if (!activePaneId && !disabled) {
|
|
3138
|
+
activePaneId = id;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
syncPaneActiveAttributes();
|
|
3142
|
+
}
|
|
3143
|
+
function getOrderedPanes() {
|
|
3144
|
+
return Array.from(panes.values()).filter((p) => !p.disabled).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
3145
|
+
}
|
|
3146
|
+
function computeFilteredJumpTargets() {
|
|
3147
|
+
if (mode !== "jump") return [];
|
|
3148
|
+
return rawJumpTargets.filter((t) => t.label.startsWith(jumpQuery)).map((t) => ({
|
|
3149
|
+
...t,
|
|
3150
|
+
matchedPrefix: jumpQuery,
|
|
3151
|
+
remainingLabel: t.label.slice(jumpQuery.length)
|
|
3152
|
+
}));
|
|
3153
|
+
}
|
|
3154
|
+
function computeState() {
|
|
3155
|
+
const rootTrie = buildMergedTrie();
|
|
3156
|
+
const effectiveMode = mode === "jump" ? "normal" : mode;
|
|
3157
|
+
const tree = buildWhichKeyTree(rootTrie, activePath, effectiveMode);
|
|
3158
|
+
const allEntries = flattenKeymapEntries(rootTrie);
|
|
3159
|
+
const q = explorerQuery.trim().toLowerCase();
|
|
3160
|
+
const filteredEntries = q ? allEntries.filter(
|
|
3161
|
+
(entry) => entry.label.toLowerCase().includes(q) || (entry.description?.toLowerCase().includes(q) ?? false) || entry.group.toLowerCase().includes(q) || entry.sequenceText.toLowerCase().includes(q)
|
|
3162
|
+
) : allEntries;
|
|
3163
|
+
return {
|
|
3164
|
+
preset,
|
|
3165
|
+
mode,
|
|
3166
|
+
leaderKey,
|
|
3167
|
+
activePath: [...activePath],
|
|
3168
|
+
breadcrumb: tree.breadcrumb,
|
|
3169
|
+
title: tree.title,
|
|
3170
|
+
items: tree.items,
|
|
3171
|
+
isOpen: activePath.length > 0 && tree.items.length > 0,
|
|
3172
|
+
sticky: sticky || tree.sticky,
|
|
3173
|
+
countBuffer,
|
|
3174
|
+
explorerOpen,
|
|
3175
|
+
explorerQuery,
|
|
3176
|
+
explorerEntries: filteredEntries,
|
|
3177
|
+
activePaneId,
|
|
3178
|
+
panes: getOrderedPanes(),
|
|
3179
|
+
jumpQuery,
|
|
3180
|
+
jumpAction,
|
|
3181
|
+
jumpTargets: computeFilteredJumpTargets(),
|
|
3182
|
+
statusMessage
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
let cachedState = computeState();
|
|
3186
|
+
function emit() {
|
|
3187
|
+
syncPaneActiveAttributes();
|
|
3188
|
+
cachedState = computeState();
|
|
3189
|
+
for (const listener of listeners) {
|
|
3190
|
+
listener(cachedState);
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
function runProgrammaticFocus(fn) {
|
|
3194
|
+
programmaticFocusDepth += 1;
|
|
3195
|
+
try {
|
|
3196
|
+
setInteractionModality("keyboard");
|
|
3197
|
+
} catch {
|
|
3198
|
+
}
|
|
3199
|
+
try {
|
|
3200
|
+
fn();
|
|
3201
|
+
} finally {
|
|
3202
|
+
programmaticFocusDepth = Math.max(0, programmaticFocusDepth - 1);
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
function getActiveContainer() {
|
|
3206
|
+
const doc = resolveDoc();
|
|
3207
|
+
if (!doc) return null;
|
|
3208
|
+
const topModal = getTopMostModalDialog(doc);
|
|
3209
|
+
if (topModal) return topModal;
|
|
3210
|
+
if (activePaneId) {
|
|
3211
|
+
const activePane = panes.get(activePaneId);
|
|
3212
|
+
if (activePane?.element) return activePane.element;
|
|
3213
|
+
}
|
|
3214
|
+
const firstPane = getOrderedPanes().find((p) => p.element);
|
|
3215
|
+
if (firstPane?.element) {
|
|
3216
|
+
activePaneId = firstPane.id;
|
|
3217
|
+
return firstPane.element;
|
|
3218
|
+
}
|
|
3219
|
+
return options.getScopeElement?.() ?? doc.body;
|
|
3220
|
+
}
|
|
3221
|
+
function recordCurrentLocation() {
|
|
3222
|
+
const doc = resolveDoc();
|
|
3223
|
+
const activeEl = doc?.activeElement ?? null;
|
|
3224
|
+
const paneId = activePaneId ?? getOrderedPanes()[0]?.id ?? "root";
|
|
3225
|
+
jumplist.push({
|
|
3226
|
+
paneId,
|
|
3227
|
+
element: activeEl,
|
|
3228
|
+
scrollTop: getActiveContainer()?.scrollTop ?? 0
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
function setMode(nextMode) {
|
|
3232
|
+
if (mode === nextMode) return;
|
|
3233
|
+
mode = nextMode;
|
|
3234
|
+
if (nextMode !== "jump") {
|
|
3235
|
+
jumpQuery = "";
|
|
3236
|
+
rawJumpTargets = [];
|
|
3237
|
+
}
|
|
3238
|
+
if (nextMode === "insert") {
|
|
3239
|
+
activePath = [];
|
|
3240
|
+
sticky = false;
|
|
3241
|
+
countBuffer = "";
|
|
3242
|
+
}
|
|
3243
|
+
notifyAllModalEditors({ mode: nextMode, preset });
|
|
3244
|
+
options.onModeChange?.(nextMode);
|
|
3245
|
+
announce(`${nextMode.charAt(0).toUpperCase()}${nextMode.slice(1)} mode`);
|
|
3246
|
+
emit();
|
|
3247
|
+
}
|
|
3248
|
+
function setPreset(nextPreset) {
|
|
3249
|
+
if (preset === nextPreset) return;
|
|
3250
|
+
preset = nextPreset;
|
|
3251
|
+
activePath = [];
|
|
3252
|
+
sticky = false;
|
|
3253
|
+
countBuffer = "";
|
|
3254
|
+
writeStoredPreset(nextPreset);
|
|
3255
|
+
notifyAllModalEditors({ mode, preset: nextPreset });
|
|
3256
|
+
options.onPresetChange?.(nextPreset);
|
|
3257
|
+
announce(`Switched to ${nextPreset} preset`);
|
|
3258
|
+
emit();
|
|
3259
|
+
}
|
|
3260
|
+
function setJumpAction(action) {
|
|
3261
|
+
if (jumpAction === action) return;
|
|
3262
|
+
jumpAction = action;
|
|
3263
|
+
writeStoredJumpAction(action);
|
|
3264
|
+
options.onJumpActionChange?.(action);
|
|
3265
|
+
emit();
|
|
3266
|
+
}
|
|
3267
|
+
function openPrefix(path, opts) {
|
|
3268
|
+
activePath = [...path];
|
|
3269
|
+
sticky = Boolean(opts?.sticky);
|
|
3270
|
+
emit();
|
|
3271
|
+
}
|
|
3272
|
+
function closePrefix() {
|
|
3273
|
+
if (activePath.length === 0 && !sticky && !countBuffer) return;
|
|
3274
|
+
activePath = [];
|
|
3275
|
+
sticky = false;
|
|
3276
|
+
countBuffer = "";
|
|
3277
|
+
emit();
|
|
3278
|
+
}
|
|
3279
|
+
function stepBackPrefix() {
|
|
3280
|
+
if (activePath.length === 0) return false;
|
|
3281
|
+
activePath = activePath.slice(0, -1);
|
|
3282
|
+
if (activePath.length === 0) {
|
|
3283
|
+
sticky = false;
|
|
3284
|
+
}
|
|
3285
|
+
emit();
|
|
3286
|
+
return true;
|
|
3287
|
+
}
|
|
3288
|
+
function openExplorer() {
|
|
3289
|
+
activePath = [];
|
|
3290
|
+
sticky = false;
|
|
3291
|
+
countBuffer = "";
|
|
3292
|
+
explorerQuery = "";
|
|
3293
|
+
explorerOpen = true;
|
|
3294
|
+
announce("Keybinding explorer opened");
|
|
3295
|
+
emit();
|
|
3296
|
+
}
|
|
3297
|
+
function closeExplorer() {
|
|
3298
|
+
if (!explorerOpen) return;
|
|
3299
|
+
explorerOpen = false;
|
|
3300
|
+
explorerQuery = "";
|
|
3301
|
+
emit();
|
|
3302
|
+
}
|
|
3303
|
+
function setExplorerQuery(query) {
|
|
3304
|
+
explorerQuery = query;
|
|
3305
|
+
emit();
|
|
3306
|
+
}
|
|
3307
|
+
function enterExampleContainer(exampleEl) {
|
|
3308
|
+
const doc = resolveDoc();
|
|
3309
|
+
const activeFw = doc?.documentElement?.getAttribute("data-framework");
|
|
3310
|
+
const preview = exampleEl.querySelector("[data-example-preview]") ?? exampleEl;
|
|
3311
|
+
const scopes = Array.from(preview.querySelectorAll("[data-which-key-scope]"));
|
|
3312
|
+
const activeScope = doc ? scopes.find((s) => isScopeElementActive(s, doc)) ?? null : null;
|
|
3313
|
+
if (activeScope && doc) {
|
|
3314
|
+
lastInteractedScopeByDoc.set(doc, activeScope);
|
|
3315
|
+
const scopeFocusables = getPaneFocusableItems(activeScope, activeScope);
|
|
3316
|
+
const target = scopeFocusables[0] ?? preview;
|
|
3317
|
+
recordCurrentLocation();
|
|
3318
|
+
focusElementInActivePane(target);
|
|
3319
|
+
announce("Entered example preview");
|
|
3320
|
+
emit();
|
|
3321
|
+
return true;
|
|
3322
|
+
}
|
|
3323
|
+
const rawFocusables = getFocusables(preview, { includeContainer: false }).filter((el) => {
|
|
3324
|
+
if (!(el instanceof HTMLElement)) return false;
|
|
3325
|
+
const fwEl = el.closest("[data-fw]");
|
|
3326
|
+
if (fwEl && activeFw && fwEl.getAttribute("data-fw") !== activeFw) return false;
|
|
3327
|
+
if (el.getAttribute("aria-hidden") === "true" || el.hasAttribute("inert")) return false;
|
|
3328
|
+
return true;
|
|
3329
|
+
});
|
|
3330
|
+
if (rawFocusables.length > 0) {
|
|
3331
|
+
recordCurrentLocation();
|
|
3332
|
+
focusElementInActivePane(rawFocusables[0]);
|
|
3333
|
+
announce("Entered example preview");
|
|
3334
|
+
emit();
|
|
3335
|
+
return true;
|
|
3336
|
+
}
|
|
3337
|
+
const codeToggle = exampleEl.querySelector("[data-example-toggle]");
|
|
3338
|
+
if (codeToggle) {
|
|
3339
|
+
codeToggle.click();
|
|
3340
|
+
announce("Toggled example code");
|
|
3341
|
+
return true;
|
|
3342
|
+
}
|
|
3343
|
+
return false;
|
|
3344
|
+
}
|
|
3345
|
+
function focusElementInActivePane(target) {
|
|
3346
|
+
runProgrammaticFocus(() => {
|
|
3347
|
+
target.focus({ preventScroll: true });
|
|
3348
|
+
if (typeof target.scrollIntoView === "function") {
|
|
3349
|
+
try {
|
|
3350
|
+
target.scrollIntoView({
|
|
3351
|
+
block: "nearest",
|
|
3352
|
+
inline: "nearest",
|
|
3353
|
+
behavior: "instant"
|
|
3354
|
+
});
|
|
3355
|
+
} catch {
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
});
|
|
3359
|
+
if (activePaneId) {
|
|
3360
|
+
const pane = panes.get(activePaneId);
|
|
3361
|
+
if (pane) {
|
|
3362
|
+
pane.lastFocusedElement = target;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
function stepFocusInPane(delta) {
|
|
3367
|
+
const container = getActiveContainer();
|
|
3368
|
+
if (!container) return false;
|
|
3369
|
+
const items = getPaneFocusableItems(container, options.getScopeElement?.());
|
|
3370
|
+
if (items.length === 0) return false;
|
|
3371
|
+
const doc = resolveDoc();
|
|
3372
|
+
const activeEl = doc?.activeElement;
|
|
3373
|
+
const currentIndex = activeEl ? items.indexOf(activeEl) : -1;
|
|
3374
|
+
let nextIndex = 0;
|
|
3375
|
+
if (currentIndex === -1) {
|
|
3376
|
+
const activePane = activePaneId ? panes.get(activePaneId) : void 0;
|
|
3377
|
+
if (activePane?.lastFocusedElement) {
|
|
3378
|
+
const rememberedIdx = items.indexOf(activePane.lastFocusedElement);
|
|
3379
|
+
if (rememberedIdx !== -1) {
|
|
3380
|
+
nextIndex = delta > 0 ? Math.min(items.length - 1, rememberedIdx + delta) : Math.max(0, rememberedIdx + delta);
|
|
3381
|
+
} else {
|
|
3382
|
+
nextIndex = delta >= 0 ? 0 : items.length - 1;
|
|
3383
|
+
}
|
|
3384
|
+
} else {
|
|
3385
|
+
nextIndex = delta >= 0 ? 0 : items.length - 1;
|
|
3386
|
+
}
|
|
3387
|
+
} else {
|
|
3388
|
+
nextIndex = Math.max(0, Math.min(items.length - 1, currentIndex + delta));
|
|
3389
|
+
}
|
|
3390
|
+
const target = items[nextIndex];
|
|
3391
|
+
if (!target) return false;
|
|
3392
|
+
focusElementInActivePane(target);
|
|
3393
|
+
emit();
|
|
3394
|
+
return true;
|
|
3395
|
+
}
|
|
3396
|
+
function isScrollableContainer(el, doc) {
|
|
3397
|
+
if (!doc || el === doc.body || el === doc.documentElement) return false;
|
|
3398
|
+
if (el.scrollHeight <= el.clientHeight + 2) return false;
|
|
3399
|
+
const win = doc.defaultView;
|
|
3400
|
+
if (!win || typeof win.getComputedStyle !== "function") return true;
|
|
3401
|
+
const overflowY = win.getComputedStyle(el).overflowY;
|
|
3402
|
+
return overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay";
|
|
3403
|
+
}
|
|
3404
|
+
function jumpToBoundary(boundary) {
|
|
3405
|
+
const container = getActiveContainer();
|
|
3406
|
+
if (!container) return false;
|
|
3407
|
+
const items = getPaneFocusableItems(container, options.getScopeElement?.());
|
|
3408
|
+
if (items.length === 0) return false;
|
|
3409
|
+
const doc = resolveDoc();
|
|
3410
|
+
const win = doc?.defaultView ?? null;
|
|
3411
|
+
recordCurrentLocation();
|
|
3412
|
+
if (boundary === "start" || boundary === "first-in-group") {
|
|
3413
|
+
const target2 = items[0];
|
|
3414
|
+
focusElementInActivePane(target2);
|
|
3415
|
+
if (boundary === "start") {
|
|
3416
|
+
container.scrollTop = 0;
|
|
3417
|
+
if (win && !isScrollableContainer(container, doc)) {
|
|
3418
|
+
try {
|
|
3419
|
+
win.scrollTo({ top: 0, behavior: "instant" });
|
|
3420
|
+
} catch {
|
|
3421
|
+
win.scrollTo(0, 0);
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
recordCurrentLocation();
|
|
3426
|
+
emit();
|
|
3427
|
+
return true;
|
|
3428
|
+
}
|
|
3429
|
+
const target = items[items.length - 1];
|
|
3430
|
+
focusElementInActivePane(target);
|
|
3431
|
+
if (boundary === "end") {
|
|
3432
|
+
container.scrollTop = container.scrollHeight;
|
|
3433
|
+
if (win && !isScrollableContainer(container, doc)) {
|
|
3434
|
+
const scrollMax = Math.max(
|
|
3435
|
+
doc?.documentElement?.scrollHeight ?? 0,
|
|
3436
|
+
doc?.body?.scrollHeight ?? 0,
|
|
3437
|
+
container.scrollHeight
|
|
3438
|
+
);
|
|
3439
|
+
try {
|
|
3440
|
+
win.scrollTo({ top: scrollMax, behavior: "instant" });
|
|
3441
|
+
} catch {
|
|
3442
|
+
win.scrollTo(0, scrollMax);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
recordCurrentLocation();
|
|
3447
|
+
emit();
|
|
3448
|
+
return true;
|
|
3449
|
+
}
|
|
3450
|
+
function scrollActivePane(action, count = 1) {
|
|
3451
|
+
const container = getActiveContainer();
|
|
3452
|
+
if (!container) return false;
|
|
3453
|
+
const doc = resolveDoc();
|
|
3454
|
+
const activeEl = doc?.activeElement;
|
|
3455
|
+
if (action === "center" && activeEl && typeof activeEl.scrollIntoView === "function") {
|
|
3456
|
+
try {
|
|
3457
|
+
activeEl.scrollIntoView({ block: "center", behavior: "instant" });
|
|
3458
|
+
} catch {
|
|
3459
|
+
}
|
|
3460
|
+
return true;
|
|
3461
|
+
}
|
|
3462
|
+
if (action === "top" && activeEl && typeof activeEl.scrollIntoView === "function") {
|
|
3463
|
+
try {
|
|
3464
|
+
activeEl.scrollIntoView({ block: "start", behavior: "instant" });
|
|
3465
|
+
} catch {
|
|
3466
|
+
}
|
|
3467
|
+
return true;
|
|
3468
|
+
}
|
|
3469
|
+
if (action === "bottom" && activeEl && typeof activeEl.scrollIntoView === "function") {
|
|
3470
|
+
try {
|
|
3471
|
+
activeEl.scrollIntoView({ block: "end", behavior: "instant" });
|
|
3472
|
+
} catch {
|
|
3473
|
+
}
|
|
3474
|
+
return true;
|
|
3475
|
+
}
|
|
3476
|
+
const stepPx = 120 * Math.max(1, count);
|
|
3477
|
+
const deltaY = action === "down" ? stepPx : action === "up" ? -stepPx : 0;
|
|
3478
|
+
if (deltaY !== 0) {
|
|
3479
|
+
if (typeof container.scrollBy === "function") {
|
|
3480
|
+
container.scrollBy({ top: deltaY, behavior: "instant" });
|
|
3481
|
+
} else {
|
|
3482
|
+
container.scrollTop += deltaY;
|
|
3483
|
+
}
|
|
3484
|
+
return true;
|
|
3485
|
+
}
|
|
3486
|
+
return false;
|
|
3487
|
+
}
|
|
3488
|
+
function focusPane(paneIdOrIndex) {
|
|
3489
|
+
const ordered = getOrderedPanes();
|
|
3490
|
+
if (ordered.length === 0) return false;
|
|
3491
|
+
let targetPane;
|
|
3492
|
+
if (typeof paneIdOrIndex === "number") {
|
|
3493
|
+
targetPane = ordered[paneIdOrIndex - 1];
|
|
3494
|
+
} else {
|
|
3495
|
+
targetPane = panes.get(paneIdOrIndex);
|
|
3496
|
+
if (!targetPane || targetPane.disabled) {
|
|
3497
|
+
const numeric = Number.parseInt(paneIdOrIndex, 10);
|
|
3498
|
+
if (!Number.isNaN(numeric) && numeric >= 1) {
|
|
3499
|
+
targetPane = ordered[numeric - 1];
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
if (!targetPane || !targetPane.element) return false;
|
|
3504
|
+
recordCurrentLocation();
|
|
3505
|
+
activePaneId = targetPane.id;
|
|
3506
|
+
const ownScope = options.getScopeElement?.() ?? null;
|
|
3507
|
+
const remembered = targetPane.lastFocusedElement && targetPane.element.contains(targetPane.lastFocusedElement) && (ownScope || !targetPane.lastFocusedElement.closest("[data-which-key-scope]")) ? targetPane.lastFocusedElement : null;
|
|
3508
|
+
const firstFocusable = remembered ?? getPaneFocusableItems(targetPane.element, ownScope)[0] ?? null;
|
|
3509
|
+
if (firstFocusable instanceof HTMLElement) {
|
|
3510
|
+
focusElementInActivePane(firstFocusable);
|
|
3511
|
+
} else {
|
|
3512
|
+
runProgrammaticFocus(() => {
|
|
3513
|
+
if (targetPane.element.tabIndex < 0) {
|
|
3514
|
+
targetPane.element.tabIndex = -1;
|
|
3515
|
+
}
|
|
3516
|
+
targetPane.element.focus({ preventScroll: false });
|
|
3517
|
+
});
|
|
3518
|
+
}
|
|
3519
|
+
if (mode === "insert") {
|
|
3520
|
+
mode = "normal";
|
|
3521
|
+
notifyAllModalEditors({ mode: "normal", preset });
|
|
3522
|
+
}
|
|
3523
|
+
recordCurrentLocation();
|
|
3524
|
+
announce(`Focused pane ${targetPane.title}`);
|
|
3525
|
+
emit();
|
|
3526
|
+
return true;
|
|
3527
|
+
}
|
|
3528
|
+
function focusPaneDirection(direction) {
|
|
3529
|
+
const ordered = getOrderedPanes().filter((p) => p.element);
|
|
3530
|
+
if (ordered.length === 0) return false;
|
|
3531
|
+
const currentPane = (activePaneId ? panes.get(activePaneId) : void 0) ?? ordered[0];
|
|
3532
|
+
if (!currentPane?.element) return false;
|
|
3533
|
+
const toRect = (p) => {
|
|
3534
|
+
const r = p.element.getBoundingClientRect();
|
|
3535
|
+
return {
|
|
3536
|
+
id: p.id,
|
|
3537
|
+
x: r.left,
|
|
3538
|
+
y: r.top,
|
|
3539
|
+
width: r.width || p.element.offsetWidth || 100,
|
|
3540
|
+
height: r.height || p.element.offsetHeight || 100,
|
|
3541
|
+
disabled: p.disabled,
|
|
3542
|
+
order: p.order
|
|
3543
|
+
};
|
|
3544
|
+
};
|
|
3545
|
+
const originRect = toRect(currentPane);
|
|
3546
|
+
const candidateRects = ordered.map(toRect);
|
|
3547
|
+
const matched = findDirectionalPane(originRect, candidateRects, direction);
|
|
3548
|
+
if (matched) {
|
|
3549
|
+
return focusPane(matched.id);
|
|
3550
|
+
}
|
|
3551
|
+
if (originRect.x === 0 && originRect.y === 0 && ordered.length > 1) {
|
|
3552
|
+
return cyclePane(direction === "left" || direction === "up");
|
|
3553
|
+
}
|
|
3554
|
+
return false;
|
|
3555
|
+
}
|
|
3556
|
+
function cyclePane(reverse = false) {
|
|
3557
|
+
const ordered = getOrderedPanes().filter((p) => p.element);
|
|
3558
|
+
if (ordered.length === 0) return false;
|
|
3559
|
+
const currentIndex = ordered.findIndex((p) => p.id === activePaneId);
|
|
3560
|
+
const nextIndex = currentIndex === -1 ? 0 : (currentIndex + (reverse ? -1 : 1) + ordered.length) % ordered.length;
|
|
3561
|
+
const target = ordered[nextIndex];
|
|
3562
|
+
return target ? focusPane(target.id) : false;
|
|
3563
|
+
}
|
|
3564
|
+
function startJumpMode(customAction) {
|
|
3565
|
+
const doc = resolveDoc();
|
|
3566
|
+
if (!doc) return;
|
|
3567
|
+
if (customAction) {
|
|
3568
|
+
jumpAction = customAction;
|
|
3569
|
+
}
|
|
3570
|
+
const ownScope = options.getScopeElement?.() ?? null;
|
|
3571
|
+
const scopeRoot = getTopMostModalDialog(doc) ?? ownScope ?? doc.body;
|
|
3572
|
+
const allFocusable = getJumpableItems(scopeRoot, ownScope);
|
|
3573
|
+
const visible = allFocusable.filter((el) => {
|
|
3574
|
+
const rect = el.getBoundingClientRect();
|
|
3575
|
+
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
3576
|
+
if (ownScope) {
|
|
3577
|
+
return true;
|
|
3578
|
+
}
|
|
3579
|
+
const intersectsViewport = rect.bottom > 0 && rect.right > 0 && rect.top < (doc.defaultView?.innerHeight ?? 1080) && rect.left < (doc.defaultView?.innerWidth ?? 1920);
|
|
3580
|
+
try {
|
|
3581
|
+
return isInView(el, doc.defaultView ?? scopeRoot) || intersectsViewport;
|
|
3582
|
+
} catch {
|
|
3583
|
+
return intersectsViewport;
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
if (visible.length === 0) return;
|
|
3587
|
+
const labels = generateJumpLabels(visible.length, jumpAlphabet);
|
|
3588
|
+
rawJumpTargets = visible.map((el, idx) => {
|
|
3589
|
+
const r = el.getBoundingClientRect();
|
|
3590
|
+
return {
|
|
3591
|
+
id: `jump-${idx}-${labels[idx]}`,
|
|
3592
|
+
label: labels[idx],
|
|
3593
|
+
element: el,
|
|
3594
|
+
rect: {
|
|
3595
|
+
top: r.top,
|
|
3596
|
+
left: r.left,
|
|
3597
|
+
width: r.width,
|
|
3598
|
+
height: r.height
|
|
3599
|
+
}
|
|
3600
|
+
};
|
|
3601
|
+
});
|
|
3602
|
+
jumpQuery = "";
|
|
3603
|
+
activePath = [];
|
|
3604
|
+
sticky = false;
|
|
3605
|
+
countBuffer = "";
|
|
3606
|
+
mode = "jump";
|
|
3607
|
+
announce(`Jump mode (${rawJumpTargets.length} targets)`);
|
|
3608
|
+
emit();
|
|
3609
|
+
}
|
|
3610
|
+
function cancelJumpMode() {
|
|
3611
|
+
if (mode !== "jump") return;
|
|
3612
|
+
jumpQuery = "";
|
|
3613
|
+
rawJumpTargets = [];
|
|
3614
|
+
mode = "normal";
|
|
3615
|
+
emit();
|
|
3616
|
+
}
|
|
3617
|
+
function jumpBack() {
|
|
3618
|
+
const doc = resolveDoc();
|
|
3619
|
+
const activeEl = doc?.activeElement ?? null;
|
|
3620
|
+
const currentPaneId = activePaneId ?? getOrderedPanes()[0]?.id ?? "root";
|
|
3621
|
+
const target = jumplist.back({
|
|
3622
|
+
paneId: currentPaneId,
|
|
3623
|
+
element: activeEl
|
|
3624
|
+
});
|
|
3625
|
+
if (!target) return false;
|
|
3626
|
+
if (target.paneId && panes.has(target.paneId)) {
|
|
3627
|
+
activePaneId = target.paneId;
|
|
3628
|
+
}
|
|
3629
|
+
if (target.element && target.element.isConnected) {
|
|
3630
|
+
focusElementInActivePane(target.element);
|
|
3631
|
+
} else if (target.paneId) {
|
|
3632
|
+
focusPane(target.paneId);
|
|
3633
|
+
}
|
|
3634
|
+
emit();
|
|
3635
|
+
return true;
|
|
3636
|
+
}
|
|
3637
|
+
function jumpForward() {
|
|
3638
|
+
const target = jumplist.forward();
|
|
3639
|
+
if (!target) return false;
|
|
3640
|
+
if (target.paneId && panes.has(target.paneId)) {
|
|
3641
|
+
activePaneId = target.paneId;
|
|
3642
|
+
}
|
|
3643
|
+
if (target.element && target.element.isConnected) {
|
|
3644
|
+
focusElementInActivePane(target.element);
|
|
3645
|
+
} else if (target.paneId) {
|
|
3646
|
+
focusPane(target.paneId);
|
|
3647
|
+
}
|
|
3648
|
+
emit();
|
|
3649
|
+
return true;
|
|
3650
|
+
}
|
|
3651
|
+
function stepFocusVerticalInPane(delta) {
|
|
3652
|
+
const container = getActiveContainer();
|
|
3653
|
+
if (!container) return false;
|
|
3654
|
+
const items = getPaneFocusableItems(container, options.getScopeElement?.());
|
|
3655
|
+
if (items.length === 0) return false;
|
|
3656
|
+
const doc = resolveDoc();
|
|
3657
|
+
const activeEl = doc?.activeElement;
|
|
3658
|
+
const currentIndex = activeEl ? items.indexOf(activeEl) : -1;
|
|
3659
|
+
if (currentIndex === -1) {
|
|
3660
|
+
return stepFocusInPane(delta);
|
|
3661
|
+
}
|
|
3662
|
+
const initialRect = items[currentIndex].getBoundingClientRect();
|
|
3663
|
+
if (initialRect.width <= 0 || initialRect.height <= 0) {
|
|
3664
|
+
return stepFocusInPane(delta);
|
|
3665
|
+
}
|
|
3666
|
+
const initialCenterX = initialRect.left + initialRect.width / 2;
|
|
3667
|
+
const initialCenterY = initialRect.top + initialRect.height / 2;
|
|
3668
|
+
const rowTolerance = Math.max(8, initialRect.height * 0.5);
|
|
3669
|
+
const hasSiblingInSameRow = items.some((el, idx) => {
|
|
3670
|
+
if (idx === currentIndex) return false;
|
|
3671
|
+
const r = el.getBoundingClientRect();
|
|
3672
|
+
if (r.width <= 0 || r.height <= 0) return false;
|
|
3673
|
+
const cy = r.top + r.height / 2;
|
|
3674
|
+
const cx = r.left + r.width / 2;
|
|
3675
|
+
return Math.abs(cy - initialCenterY) <= rowTolerance && Math.abs(cx - initialCenterX) > 8;
|
|
3676
|
+
});
|
|
3677
|
+
if (!hasSiblingInSameRow) {
|
|
3678
|
+
return stepFocusInPane(delta);
|
|
3679
|
+
}
|
|
3680
|
+
const dir = delta >= 0 ? 1 : -1;
|
|
3681
|
+
const steps = Math.max(1, Math.abs(delta));
|
|
3682
|
+
let currentEl = items[currentIndex];
|
|
3683
|
+
for (let s = 0; s < steps; s += 1) {
|
|
3684
|
+
const curRect = currentEl.getBoundingClientRect();
|
|
3685
|
+
const curCenterY = curRect.top + curRect.height / 2;
|
|
3686
|
+
const curTol = Math.max(8, curRect.height * 0.5);
|
|
3687
|
+
const candidates = items.map((el) => {
|
|
3688
|
+
const r = el.getBoundingClientRect();
|
|
3689
|
+
return {
|
|
3690
|
+
el,
|
|
3691
|
+
cx: r.left + r.width / 2,
|
|
3692
|
+
cy: r.top + r.height / 2,
|
|
3693
|
+
h: r.height,
|
|
3694
|
+
w: r.width
|
|
3695
|
+
};
|
|
3696
|
+
}).filter((c) => {
|
|
3697
|
+
if (c.w <= 0 || c.h <= 0) return false;
|
|
3698
|
+
return dir > 0 ? c.cy > curCenterY + curTol : c.cy < curCenterY - curTol;
|
|
3699
|
+
});
|
|
3700
|
+
if (candidates.length === 0) {
|
|
3701
|
+
if (s === 0) {
|
|
3702
|
+
return stepFocusInPane(delta);
|
|
3703
|
+
}
|
|
3704
|
+
break;
|
|
3705
|
+
}
|
|
3706
|
+
let closestRowY = candidates[0].cy;
|
|
3707
|
+
for (const c of candidates) {
|
|
3708
|
+
if (Math.abs(c.cy - curCenterY) < Math.abs(closestRowY - curCenterY)) {
|
|
3709
|
+
closestRowY = c.cy;
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
const rowCandidates = candidates.filter((c) => Math.abs(c.cy - closestRowY) <= curTol);
|
|
3713
|
+
let best = rowCandidates[0];
|
|
3714
|
+
for (const c of rowCandidates) {
|
|
3715
|
+
if (Math.abs(c.cx - initialCenterX) < Math.abs(best.cx - initialCenterX)) {
|
|
3716
|
+
best = c;
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
currentEl = best.el;
|
|
3720
|
+
}
|
|
3721
|
+
focusElementInActivePane(currentEl);
|
|
3722
|
+
emit();
|
|
3723
|
+
return true;
|
|
3724
|
+
}
|
|
3725
|
+
function isElementInActiveFramework(el, doc) {
|
|
3726
|
+
const fwEl = el.closest("[data-fw]");
|
|
3727
|
+
const activeFw = doc?.documentElement?.getAttribute("data-framework");
|
|
3728
|
+
if (fwEl && activeFw && fwEl.getAttribute("data-fw") !== activeFw) {
|
|
3729
|
+
return false;
|
|
3730
|
+
}
|
|
3731
|
+
if (el.getAttribute("aria-hidden") === "true" || el.hasAttribute("inert")) {
|
|
3732
|
+
return false;
|
|
3733
|
+
}
|
|
3734
|
+
return true;
|
|
3735
|
+
}
|
|
3736
|
+
function findActiveTablist(activeEl, container) {
|
|
3737
|
+
const doc = resolveDoc();
|
|
3738
|
+
if (activeEl) {
|
|
3739
|
+
const directTablist = activeEl.closest('[role="tablist"]');
|
|
3740
|
+
if (directTablist && isElementInActiveFramework(directTablist, doc)) {
|
|
3741
|
+
return directTablist;
|
|
3742
|
+
}
|
|
3743
|
+
const tabsScope = activeEl.closest('[data-scope="tabs"]');
|
|
3744
|
+
if (tabsScope) {
|
|
3745
|
+
const list = Array.from(tabsScope.querySelectorAll('[role="tablist"]')).find(
|
|
3746
|
+
(el) => isElementInActiveFramework(el, doc)
|
|
3747
|
+
);
|
|
3748
|
+
if (list) return list;
|
|
3749
|
+
}
|
|
3750
|
+
const tabPanel = activeEl.closest('[role="tabpanel"]');
|
|
3751
|
+
if (tabPanel?.parentElement) {
|
|
3752
|
+
const list = Array.from(tabPanel.parentElement.querySelectorAll('[role="tablist"]')).find(
|
|
3753
|
+
(el) => isElementInActiveFramework(el, doc)
|
|
3754
|
+
);
|
|
3755
|
+
if (list) return list;
|
|
3756
|
+
}
|
|
3757
|
+
const exampleContainer = activeEl.hasAttribute("data-example") ? activeEl : activeEl.closest("[data-example]");
|
|
3758
|
+
if (exampleContainer) {
|
|
3759
|
+
const list = Array.from(exampleContainer.querySelectorAll('[role="tablist"]')).find(
|
|
3760
|
+
(el) => isElementInActiveFramework(el, doc)
|
|
3761
|
+
);
|
|
3762
|
+
if (list) return list;
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
const searchRoot = container ?? doc?.body ?? null;
|
|
3766
|
+
if (!searchRoot) return null;
|
|
3767
|
+
const allLists = Array.from(searchRoot.querySelectorAll('[role="tablist"]')).filter(
|
|
3768
|
+
(el) => isElementInActiveFramework(el, doc)
|
|
3769
|
+
);
|
|
3770
|
+
return allLists[0] ?? null;
|
|
3771
|
+
}
|
|
3772
|
+
function stepTab(delta, boundary) {
|
|
3773
|
+
const doc = resolveDoc();
|
|
3774
|
+
const activeEl = doc?.activeElement ?? null;
|
|
3775
|
+
const container = getActiveContainer();
|
|
3776
|
+
const tablist = findActiveTablist(activeEl, container);
|
|
3777
|
+
if (!tablist) return false;
|
|
3778
|
+
const tabs = Array.from(
|
|
3779
|
+
tablist.querySelectorAll(
|
|
3780
|
+
'[role="tab"]:not([disabled]):not([data-disabled]):not([aria-disabled="true"])'
|
|
3781
|
+
)
|
|
3782
|
+
).filter((el) => isElementInActiveFramework(el, doc));
|
|
3783
|
+
if (tabs.length === 0) return false;
|
|
3784
|
+
let currentIdx = activeEl ? tabs.findIndex((t) => t === activeEl || t.contains(activeEl)) : -1;
|
|
3785
|
+
if (currentIdx === -1) {
|
|
3786
|
+
currentIdx = tabs.findIndex(
|
|
3787
|
+
(t) => t.getAttribute("aria-selected") === "true" || t.hasAttribute("data-selected") || t.getAttribute("data-state") === "active"
|
|
3788
|
+
);
|
|
3789
|
+
}
|
|
3790
|
+
if (currentIdx === -1) {
|
|
3791
|
+
currentIdx = 0;
|
|
3792
|
+
}
|
|
3793
|
+
let targetIdx;
|
|
3794
|
+
if (boundary === "first") {
|
|
3795
|
+
targetIdx = 0;
|
|
3796
|
+
} else if (boundary === "last") {
|
|
3797
|
+
targetIdx = tabs.length - 1;
|
|
3798
|
+
} else {
|
|
3799
|
+
targetIdx = ((currentIdx + delta) % tabs.length + tabs.length) % tabs.length;
|
|
3800
|
+
}
|
|
3801
|
+
const targetTab = tabs[targetIdx];
|
|
3802
|
+
if (!targetTab) return false;
|
|
3803
|
+
recordCurrentLocation();
|
|
3804
|
+
focusElementInActivePane(targetTab);
|
|
3805
|
+
targetTab.click();
|
|
3806
|
+
recordCurrentLocation();
|
|
3807
|
+
announce(`Tab ${targetTab.textContent?.trim() || targetIdx + 1}`);
|
|
3808
|
+
emit();
|
|
3809
|
+
return true;
|
|
3810
|
+
}
|
|
3811
|
+
function stepSection(delta) {
|
|
3812
|
+
const container = getActiveContainer();
|
|
3813
|
+
if (!container) return false;
|
|
3814
|
+
const sections = Array.from(
|
|
3815
|
+
container.querySelectorAll(
|
|
3816
|
+
'[data-page-section], [data-slot="page-section"], section[id], .docs-prose :is(h2, h3)'
|
|
3817
|
+
)
|
|
3818
|
+
);
|
|
3819
|
+
if (sections.length === 0) {
|
|
3820
|
+
return stepFocusInPane(delta);
|
|
3821
|
+
}
|
|
3822
|
+
const doc = resolveDoc();
|
|
3823
|
+
const activeEl = doc?.activeElement;
|
|
3824
|
+
const currentIdx = activeEl ? sections.findIndex((s) => s === activeEl || s.contains(activeEl)) : -1;
|
|
3825
|
+
const nextIdx = currentIdx === -1 ? delta >= 0 ? 0 : sections.length - 1 : Math.max(0, Math.min(sections.length - 1, currentIdx + delta));
|
|
3826
|
+
const targetSection = sections[nextIdx];
|
|
3827
|
+
if (!targetSection) return false;
|
|
3828
|
+
recordCurrentLocation();
|
|
3829
|
+
if (typeof targetSection.scrollIntoView === "function") {
|
|
3830
|
+
try {
|
|
3831
|
+
targetSection.scrollIntoView({ block: "start", behavior: "instant" });
|
|
3832
|
+
} catch {
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
const innerFocusable = getPaneFocusableItems(targetSection, options.getScopeElement?.())[0] ?? getFirstFocusable(targetSection, { includeContainer: false });
|
|
3836
|
+
if (innerFocusable instanceof HTMLElement) {
|
|
3837
|
+
focusElementInActivePane(innerFocusable);
|
|
3838
|
+
} else {
|
|
3839
|
+
runProgrammaticFocus(() => {
|
|
3840
|
+
if (targetSection.tabIndex < 0) {
|
|
3841
|
+
targetSection.tabIndex = -1;
|
|
3842
|
+
}
|
|
3843
|
+
targetSection.style.outline = "none";
|
|
3844
|
+
targetSection.focus({ preventScroll: true });
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
recordCurrentLocation();
|
|
3848
|
+
emit();
|
|
3849
|
+
return true;
|
|
3850
|
+
}
|
|
3851
|
+
function handleGenericContentEditableMotion(el, motion, count) {
|
|
3852
|
+
const win = el.ownerDocument?.defaultView;
|
|
3853
|
+
const sel = win?.getSelection?.();
|
|
3854
|
+
if (!sel || typeof sel.modify !== "function") return false;
|
|
3855
|
+
const alter = mode === "select" || (preset === "helix" || preset === "kakoune") && (motion === "wordForward" || motion === "wordBackward" || motion === "wordEnd" || motion === "lineSelect") ? "extend" : "move";
|
|
3856
|
+
for (let i = 0; i < Math.max(1, count); i += 1) {
|
|
3857
|
+
switch (motion) {
|
|
3858
|
+
case "left":
|
|
3859
|
+
sel.modify(alter, "backward", "character");
|
|
3860
|
+
break;
|
|
3861
|
+
case "right":
|
|
3862
|
+
sel.modify(alter, "forward", "character");
|
|
3863
|
+
break;
|
|
3864
|
+
case "up":
|
|
3865
|
+
sel.modify(alter, "backward", "line");
|
|
3866
|
+
break;
|
|
3867
|
+
case "down":
|
|
3868
|
+
sel.modify(alter, "forward", "line");
|
|
3869
|
+
break;
|
|
3870
|
+
case "wordForward":
|
|
3871
|
+
case "wordEnd":
|
|
3872
|
+
sel.modify(alter, "forward", "word");
|
|
3873
|
+
break;
|
|
3874
|
+
case "wordBackward":
|
|
3875
|
+
sel.modify(alter, "backward", "word");
|
|
3876
|
+
break;
|
|
3877
|
+
case "paragraphForward":
|
|
3878
|
+
sel.modify(alter, "forward", "paragraphboundary");
|
|
3879
|
+
break;
|
|
3880
|
+
case "paragraphBackward":
|
|
3881
|
+
sel.modify(alter, "backward", "paragraphboundary");
|
|
3882
|
+
break;
|
|
3883
|
+
case "lineStart":
|
|
3884
|
+
sel.modify(alter, "backward", "lineboundary");
|
|
3885
|
+
break;
|
|
3886
|
+
case "lineEnd":
|
|
3887
|
+
sel.modify(alter, "forward", "lineboundary");
|
|
3888
|
+
break;
|
|
3889
|
+
case "lineSelect":
|
|
3890
|
+
sel.modify("move", "backward", "lineboundary");
|
|
3891
|
+
sel.modify("extend", "forward", "lineboundary");
|
|
3892
|
+
break;
|
|
3893
|
+
case "docStart":
|
|
3894
|
+
sel.modify(alter, "backward", "documentboundary");
|
|
3895
|
+
break;
|
|
3896
|
+
case "docEnd":
|
|
3897
|
+
sel.modify(alter, "forward", "documentboundary");
|
|
3898
|
+
break;
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
return true;
|
|
3902
|
+
}
|
|
3903
|
+
function executeBuiltInCommand(commandId, ctx) {
|
|
3904
|
+
const doc = resolveDoc();
|
|
3905
|
+
const eventTarget = isElementLike(ctx.event?.target) ? ctx.event.target : null;
|
|
3906
|
+
const activeEl = eventTarget ?? doc?.activeElement ?? null;
|
|
3907
|
+
const editorTarget = getModalEditor(activeEl);
|
|
3908
|
+
if (commandId === "whichKey.openExplorer") {
|
|
3909
|
+
openExplorer();
|
|
3910
|
+
return true;
|
|
3911
|
+
}
|
|
3912
|
+
if (commandId === "preset.helix") {
|
|
3913
|
+
setPreset("helix");
|
|
3914
|
+
return true;
|
|
3915
|
+
}
|
|
3916
|
+
if (commandId === "preset.vim") {
|
|
3917
|
+
setPreset("vim");
|
|
3918
|
+
return true;
|
|
3919
|
+
}
|
|
3920
|
+
if (commandId === "preset.kakoune") {
|
|
3921
|
+
setPreset("kakoune");
|
|
3922
|
+
return true;
|
|
3923
|
+
}
|
|
3924
|
+
if (commandId === "mode.toggleSelect") {
|
|
3925
|
+
const nextMode = mode === "select" ? "normal" : "select";
|
|
3926
|
+
if (nextMode === "normal" && editorTarget) {
|
|
3927
|
+
editorTarget.transformSelection("collapse");
|
|
3928
|
+
}
|
|
3929
|
+
setMode(nextMode);
|
|
3930
|
+
return true;
|
|
3931
|
+
}
|
|
3932
|
+
if (commandId === "jump.start") {
|
|
3933
|
+
startJumpMode();
|
|
3934
|
+
return true;
|
|
3935
|
+
}
|
|
3936
|
+
if (commandId === "jump.activate") {
|
|
3937
|
+
startJumpMode("activate");
|
|
3938
|
+
return true;
|
|
3939
|
+
}
|
|
3940
|
+
if (commandId === "jump.focus") {
|
|
3941
|
+
startJumpMode("focus");
|
|
3942
|
+
return true;
|
|
3943
|
+
}
|
|
3944
|
+
if (commandId === "jump.action.activate") {
|
|
3945
|
+
setJumpAction("activate");
|
|
3946
|
+
return true;
|
|
3947
|
+
}
|
|
3948
|
+
if (commandId === "jump.action.focus") {
|
|
3949
|
+
setJumpAction("focus");
|
|
3950
|
+
return true;
|
|
3951
|
+
}
|
|
3952
|
+
if (commandId === "jumplist.back") {
|
|
3953
|
+
return jumpBack();
|
|
3954
|
+
}
|
|
3955
|
+
if (commandId === "jumplist.forward") {
|
|
3956
|
+
return jumpForward();
|
|
3957
|
+
}
|
|
3958
|
+
if (commandId.startsWith("pane.focus.")) {
|
|
3959
|
+
const idx = Number.parseInt(commandId.slice("pane.focus.".length), 10);
|
|
3960
|
+
return focusPane(idx);
|
|
3961
|
+
}
|
|
3962
|
+
if (commandId === "pane.left") return focusPaneDirection("left");
|
|
3963
|
+
if (commandId === "pane.down") return focusPaneDirection("down");
|
|
3964
|
+
if (commandId === "pane.up") return focusPaneDirection("up");
|
|
3965
|
+
if (commandId === "pane.right") return focusPaneDirection("right");
|
|
3966
|
+
if (commandId === "pane.next") return cyclePane(false);
|
|
3967
|
+
if (commandId === "pane.prev") return cyclePane(true);
|
|
3968
|
+
if (commandId === "view.center") return scrollActivePane("center", ctx.count);
|
|
3969
|
+
if (commandId === "view.top") return scrollActivePane("top", ctx.count);
|
|
3970
|
+
if (commandId === "view.bottom") return scrollActivePane("bottom", ctx.count);
|
|
3971
|
+
if (commandId === "view.scrollDown") return scrollActivePane("down", ctx.count);
|
|
3972
|
+
if (commandId === "view.scrollUp") return scrollActivePane("up", ctx.count);
|
|
3973
|
+
if (commandId === "tab.next") return stepTab(ctx.count) || stepSection(ctx.count);
|
|
3974
|
+
if (commandId === "tab.prev") return stepTab(-ctx.count) || stepSection(-ctx.count);
|
|
3975
|
+
if (commandId === "section.next") return stepSection(ctx.count);
|
|
3976
|
+
if (commandId === "section.prev") return stepSection(-ctx.count);
|
|
3977
|
+
if (commandId === "focus.nextBlock") return stepFocusInPane(ctx.count);
|
|
3978
|
+
if (commandId === "focus.prevBlock") return stepFocusInPane(-ctx.count);
|
|
3979
|
+
if (commandId.startsWith("motion.")) {
|
|
3980
|
+
const motion = commandId.slice("motion.".length);
|
|
3981
|
+
if (editorTarget) {
|
|
3982
|
+
const handled = editorTarget.move(motion, {
|
|
3983
|
+
preset,
|
|
3984
|
+
mode,
|
|
3985
|
+
count: ctx.count
|
|
3986
|
+
});
|
|
3987
|
+
if (motion === "lineSelect" && mode === "normal") {
|
|
3988
|
+
setMode("select");
|
|
3989
|
+
}
|
|
3990
|
+
return handled;
|
|
3991
|
+
}
|
|
3992
|
+
if (activeEl && (activeEl.isContentEditable || activeEl.getAttribute("contenteditable") === "true")) {
|
|
3993
|
+
const handled = handleGenericContentEditableMotion(activeEl, motion, ctx.count);
|
|
3994
|
+
if (handled && motion === "lineSelect" && mode === "normal") {
|
|
3995
|
+
setMode("select");
|
|
3996
|
+
}
|
|
3997
|
+
return handled;
|
|
3998
|
+
}
|
|
3999
|
+
const activeTab = activeEl?.closest('[role="tab"]');
|
|
4000
|
+
const activeTablist = activeTab?.closest('[role="tablist"]');
|
|
4001
|
+
if (activeTab && activeTablist) {
|
|
4002
|
+
const isVertical = activeTablist.getAttribute("aria-orientation") === "vertical" || activeTablist.getAttribute("data-orientation") === "vertical";
|
|
4003
|
+
if (!isVertical) {
|
|
4004
|
+
if (motion === "right" || motion === "wordForward" || motion === "wordEnd") {
|
|
4005
|
+
return stepTab(ctx.count);
|
|
4006
|
+
}
|
|
4007
|
+
if (motion === "left" || motion === "wordBackward") {
|
|
4008
|
+
return stepTab(-ctx.count);
|
|
4009
|
+
}
|
|
4010
|
+
if (motion === "lineStart") {
|
|
4011
|
+
return stepTab(0, "first");
|
|
4012
|
+
}
|
|
4013
|
+
if (motion === "lineEnd") {
|
|
4014
|
+
return stepTab(0, "last");
|
|
4015
|
+
}
|
|
4016
|
+
} else {
|
|
4017
|
+
if (motion === "down") {
|
|
4018
|
+
return stepTab(ctx.count);
|
|
4019
|
+
}
|
|
4020
|
+
if (motion === "up") {
|
|
4021
|
+
return stepTab(-ctx.count);
|
|
4022
|
+
}
|
|
4023
|
+
if (motion === "lineStart") {
|
|
4024
|
+
return stepTab(0, "first");
|
|
4025
|
+
}
|
|
4026
|
+
if (motion === "lineEnd") {
|
|
4027
|
+
return stepTab(0, "last");
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
switch (motion) {
|
|
4032
|
+
case "down":
|
|
4033
|
+
return stepFocusVerticalInPane(ctx.count);
|
|
4034
|
+
case "up":
|
|
4035
|
+
return stepFocusVerticalInPane(-ctx.count);
|
|
4036
|
+
case "wordForward":
|
|
4037
|
+
case "wordEnd":
|
|
4038
|
+
case "right":
|
|
4039
|
+
return stepFocusInPane(ctx.count);
|
|
4040
|
+
case "wordBackward":
|
|
4041
|
+
case "left":
|
|
4042
|
+
return stepFocusInPane(-ctx.count);
|
|
4043
|
+
case "paragraphForward":
|
|
4044
|
+
return stepSection(ctx.count);
|
|
4045
|
+
case "paragraphBackward":
|
|
4046
|
+
return stepSection(-ctx.count);
|
|
4047
|
+
case "docStart":
|
|
4048
|
+
return jumpToBoundary("start");
|
|
4049
|
+
case "docEnd":
|
|
4050
|
+
return jumpToBoundary("end");
|
|
4051
|
+
case "lineStart":
|
|
4052
|
+
return jumpToBoundary("first-in-group");
|
|
4053
|
+
case "lineEnd":
|
|
4054
|
+
return jumpToBoundary("last-in-group");
|
|
4055
|
+
case "lineSelect":
|
|
4056
|
+
setMode(mode === "select" ? "normal" : "select");
|
|
4057
|
+
return true;
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
if (commandId.startsWith("textObject.")) {
|
|
4061
|
+
const spec = commandId.slice("textObject.".length);
|
|
4062
|
+
if (editorTarget) {
|
|
4063
|
+
return editorTarget.selectTextObject(spec, { preset, mode });
|
|
4064
|
+
}
|
|
4065
|
+
return false;
|
|
4066
|
+
}
|
|
4067
|
+
if (commandId.startsWith("selection.")) {
|
|
4068
|
+
const transform = commandId.slice("selection.".length);
|
|
4069
|
+
if (editorTarget) {
|
|
4070
|
+
const handled = editorTarget.transformSelection(transform);
|
|
4071
|
+
if (transform === "collapse" && mode === "select") {
|
|
4072
|
+
setMode("normal");
|
|
4073
|
+
}
|
|
4074
|
+
return handled;
|
|
4075
|
+
}
|
|
4076
|
+
if (transform === "collapse" && mode === "select") {
|
|
4077
|
+
setMode("normal");
|
|
4078
|
+
return true;
|
|
4079
|
+
}
|
|
4080
|
+
return false;
|
|
4081
|
+
}
|
|
4082
|
+
if (commandId.startsWith("operator.")) {
|
|
4083
|
+
const op = commandId.slice("operator.".length);
|
|
4084
|
+
const emitYankNotification = (yankedText) => {
|
|
4085
|
+
if (!yankedText) return;
|
|
4086
|
+
options.onYank?.(yankedText, ctx);
|
|
4087
|
+
if (typeof CustomEvent === "function") {
|
|
4088
|
+
const dispatchTarget = activeEl ?? doc ?? null;
|
|
4089
|
+
dispatchTarget?.dispatchEvent?.(
|
|
4090
|
+
new CustomEvent("helical:yank", {
|
|
4091
|
+
bubbles: true,
|
|
4092
|
+
detail: {
|
|
4093
|
+
text: yankedText,
|
|
4094
|
+
preset: ctx.preset,
|
|
4095
|
+
mode: ctx.mode,
|
|
4096
|
+
count: ctx.count
|
|
4097
|
+
}
|
|
4098
|
+
})
|
|
4099
|
+
);
|
|
4100
|
+
}
|
|
4101
|
+
};
|
|
4102
|
+
if (editorTarget) {
|
|
4103
|
+
const res = editorTarget.execOperator(op, {
|
|
4104
|
+
preset,
|
|
4105
|
+
mode,
|
|
4106
|
+
count: ctx.count
|
|
4107
|
+
});
|
|
4108
|
+
if (op === "yank" && typeof res === "object" && res !== null && typeof res.yankedText === "string") {
|
|
4109
|
+
emitYankNotification(res.yankedText);
|
|
4110
|
+
}
|
|
4111
|
+
const shouldEnterInsert = typeof res === "object" && res !== null && res.enterInsert || op === "change" || op === "insertStart" || op === "appendEnd" || op === "openBelow" || op === "openAbove";
|
|
4112
|
+
if (shouldEnterInsert) {
|
|
4113
|
+
setMode("insert");
|
|
4114
|
+
} else if ((op === "delete" || op === "yank") && mode === "select") {
|
|
4115
|
+
setMode("normal");
|
|
4116
|
+
}
|
|
4117
|
+
return Boolean(res);
|
|
4118
|
+
}
|
|
4119
|
+
if (op === "yank") {
|
|
4120
|
+
let selectedText = "";
|
|
4121
|
+
if (activeEl instanceof HTMLInputElement || activeEl instanceof HTMLTextAreaElement) {
|
|
4122
|
+
const start = activeEl.selectionStart ?? 0;
|
|
4123
|
+
const end = activeEl.selectionEnd ?? 0;
|
|
4124
|
+
selectedText = activeEl.value.slice(start, end);
|
|
4125
|
+
} else {
|
|
4126
|
+
selectedText = doc?.defaultView?.getSelection?.()?.toString() ?? "";
|
|
4127
|
+
}
|
|
4128
|
+
if (selectedText && typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
4129
|
+
void navigator.clipboard.writeText(selectedText).catch(() => {
|
|
4130
|
+
});
|
|
4131
|
+
}
|
|
4132
|
+
emitYankNotification(selectedText);
|
|
4133
|
+
if (mode === "select") {
|
|
4134
|
+
setMode("normal");
|
|
4135
|
+
}
|
|
4136
|
+
return Boolean(selectedText);
|
|
4137
|
+
}
|
|
4138
|
+
if (op === "insertStart" && activeEl?.hasAttribute("data-example")) {
|
|
4139
|
+
return enterExampleContainer(activeEl);
|
|
4140
|
+
}
|
|
4141
|
+
if (op === "change" && activeEl && !isTextEntryElement(activeEl)) {
|
|
4142
|
+
const exampleCard = activeEl.closest("[data-example]");
|
|
4143
|
+
if (exampleCard) {
|
|
4144
|
+
const toggle = exampleCard.querySelector("[data-example-toggle]");
|
|
4145
|
+
if (toggle) {
|
|
4146
|
+
toggle.click();
|
|
4147
|
+
announce("Toggled example code");
|
|
4148
|
+
return true;
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
if (op === "insertStart" || op === "appendEnd" || op === "change") {
|
|
4153
|
+
if (isTextEntryElement(activeEl)) {
|
|
4154
|
+
if (activeEl instanceof HTMLInputElement || activeEl instanceof HTMLTextAreaElement) {
|
|
4155
|
+
try {
|
|
4156
|
+
const pos = op === "insertStart" ? 0 : activeEl.value.length;
|
|
4157
|
+
activeEl.setSelectionRange(pos, pos);
|
|
4158
|
+
} catch {
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
setMode("insert");
|
|
4162
|
+
return true;
|
|
4163
|
+
}
|
|
4164
|
+
setMode("insert");
|
|
4165
|
+
return true;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
return false;
|
|
4169
|
+
}
|
|
4170
|
+
function executeCommand(commandId, partialCtx) {
|
|
4171
|
+
const count = partialCtx?.count ?? (countBuffer ? Math.max(1, Number.parseInt(countBuffer, 10)) : 1);
|
|
4172
|
+
const ctx = {
|
|
4173
|
+
count,
|
|
4174
|
+
mode: partialCtx?.mode ?? mode,
|
|
4175
|
+
preset: partialCtx?.preset ?? preset,
|
|
4176
|
+
activePaneId: partialCtx?.activePaneId ?? activePaneId,
|
|
4177
|
+
event: partialCtx?.event
|
|
4178
|
+
};
|
|
4179
|
+
const customHandler = commandHandlers.get(commandId);
|
|
4180
|
+
let handled = false;
|
|
4181
|
+
if (customHandler) {
|
|
4182
|
+
const res = customHandler(ctx);
|
|
4183
|
+
handled = res !== false;
|
|
4184
|
+
}
|
|
4185
|
+
if (!handled) {
|
|
4186
|
+
handled = executeBuiltInCommand(commandId, ctx);
|
|
4187
|
+
}
|
|
4188
|
+
options.onCommand?.(commandId, ctx);
|
|
4189
|
+
return handled;
|
|
4190
|
+
}
|
|
4191
|
+
function invokeNode(node, event) {
|
|
4192
|
+
const count = countBuffer ? Math.max(1, Number.parseInt(countBuffer, 10)) : 1;
|
|
4193
|
+
const ctx = {
|
|
4194
|
+
count,
|
|
4195
|
+
mode,
|
|
4196
|
+
preset,
|
|
4197
|
+
activePaneId,
|
|
4198
|
+
event
|
|
4199
|
+
};
|
|
4200
|
+
let handled = false;
|
|
4201
|
+
if (node.action) {
|
|
4202
|
+
const res = node.action(ctx);
|
|
4203
|
+
handled = res !== false;
|
|
4204
|
+
}
|
|
4205
|
+
if (!handled && node.commandId) {
|
|
4206
|
+
handled = executeCommand(node.commandId, ctx);
|
|
4207
|
+
}
|
|
4208
|
+
countBuffer = "";
|
|
4209
|
+
if (!sticky) {
|
|
4210
|
+
activePath = [];
|
|
4211
|
+
}
|
|
4212
|
+
emit();
|
|
4213
|
+
return handled;
|
|
4214
|
+
}
|
|
4215
|
+
function executeExplorerEntry(entryOrId) {
|
|
4216
|
+
const state = computeState();
|
|
4217
|
+
const entry = typeof entryOrId === "string" ? state.explorerEntries.find((item) => item.id === entryOrId) : entryOrId;
|
|
4218
|
+
if (!entry) return false;
|
|
4219
|
+
closeExplorer();
|
|
4220
|
+
const ctx = {
|
|
4221
|
+
count: 1,
|
|
4222
|
+
mode,
|
|
4223
|
+
preset,
|
|
4224
|
+
activePaneId
|
|
4225
|
+
};
|
|
4226
|
+
let handled = false;
|
|
4227
|
+
if (entry.action) {
|
|
4228
|
+
const res = entry.action(ctx);
|
|
4229
|
+
handled = res !== false;
|
|
4230
|
+
}
|
|
4231
|
+
if (!handled && entry.commandId) {
|
|
4232
|
+
handled = executeCommand(entry.commandId, ctx);
|
|
4233
|
+
}
|
|
4234
|
+
emit();
|
|
4235
|
+
return handled;
|
|
4236
|
+
}
|
|
4237
|
+
function handleJumpKeyDown(event) {
|
|
4238
|
+
if (event.key === "Escape") {
|
|
4239
|
+
event.preventDefault();
|
|
4240
|
+
event.stopPropagation();
|
|
4241
|
+
event.stopImmediatePropagation?.();
|
|
4242
|
+
cancelJumpMode();
|
|
4243
|
+
return true;
|
|
4244
|
+
}
|
|
4245
|
+
if (event.key === "Backspace") {
|
|
4246
|
+
event.preventDefault();
|
|
4247
|
+
event.stopPropagation();
|
|
4248
|
+
if (jumpQuery.length > 0) {
|
|
4249
|
+
jumpQuery = jumpQuery.slice(0, -1);
|
|
4250
|
+
emit();
|
|
4251
|
+
} else {
|
|
4252
|
+
cancelJumpMode();
|
|
4253
|
+
}
|
|
4254
|
+
return true;
|
|
4255
|
+
}
|
|
4256
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
4257
|
+
const nextQuery = jumpQuery + event.key.toLowerCase();
|
|
4258
|
+
const matching = rawJumpTargets.filter((t) => t.label.startsWith(nextQuery));
|
|
4259
|
+
event.preventDefault();
|
|
4260
|
+
event.stopPropagation();
|
|
4261
|
+
if (matching.length === 0) {
|
|
4262
|
+
return true;
|
|
4263
|
+
}
|
|
4264
|
+
const exact = matching.find((t) => t.label === nextQuery);
|
|
4265
|
+
if (exact && matching.length === 1) {
|
|
4266
|
+
recordCurrentLocation();
|
|
4267
|
+
const targetEl = exact.element;
|
|
4268
|
+
const actionToRun = jumpAction;
|
|
4269
|
+
jumpQuery = "";
|
|
4270
|
+
rawJumpTargets = [];
|
|
4271
|
+
mode = "normal";
|
|
4272
|
+
for (const pane of panes.values()) {
|
|
4273
|
+
if (pane.element && pane.element.contains(targetEl)) {
|
|
4274
|
+
activePaneId = pane.id;
|
|
4275
|
+
break;
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
focusElementInActivePane(targetEl);
|
|
4279
|
+
if (actionToRun === "activate") {
|
|
4280
|
+
targetEl.click();
|
|
4281
|
+
}
|
|
4282
|
+
recordCurrentLocation();
|
|
4283
|
+
emit();
|
|
4284
|
+
return true;
|
|
4285
|
+
}
|
|
4286
|
+
jumpQuery = nextQuery;
|
|
4287
|
+
emit();
|
|
4288
|
+
return true;
|
|
4289
|
+
}
|
|
4290
|
+
return false;
|
|
4291
|
+
}
|
|
4292
|
+
function triggerKey(key, event) {
|
|
4293
|
+
const rootTrie = buildMergedTrie();
|
|
4294
|
+
if (activePath.length > 0) {
|
|
4295
|
+
const currentParent = resolveNode(rootTrie, activePath, mode);
|
|
4296
|
+
if (!currentParent) {
|
|
4297
|
+
closePrefix();
|
|
4298
|
+
return false;
|
|
4299
|
+
}
|
|
4300
|
+
const children = getNodeChildren(currentParent, rootTrie);
|
|
4301
|
+
const child = children[key];
|
|
4302
|
+
if (!child || !nodeMatchesMode(child, mode)) {
|
|
4303
|
+
if (!sticky) {
|
|
4304
|
+
closePrefix();
|
|
4305
|
+
}
|
|
4306
|
+
return false;
|
|
4307
|
+
}
|
|
4308
|
+
if (isGroupNode(child, rootTrie)) {
|
|
4309
|
+
activePath = [...activePath, key];
|
|
4310
|
+
if (child.sticky || child.loop) {
|
|
4311
|
+
sticky = true;
|
|
4312
|
+
}
|
|
4313
|
+
announce(`${child.group ?? child.label} menu`);
|
|
4314
|
+
emit();
|
|
4315
|
+
return true;
|
|
4316
|
+
}
|
|
4317
|
+
return invokeNode(child, event);
|
|
4318
|
+
}
|
|
4319
|
+
if (/^[0-9]$/.test(key) && (countBuffer.length > 0 || key !== "0" || !rootTrie["0"])) {
|
|
4320
|
+
if (countBuffer.length > 0 || key !== "0") {
|
|
4321
|
+
countBuffer += key;
|
|
4322
|
+
emit();
|
|
4323
|
+
return true;
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
const rootNode = rootTrie[key];
|
|
4327
|
+
if (!rootNode || !nodeMatchesMode(rootNode, mode)) {
|
|
4328
|
+
return false;
|
|
4329
|
+
}
|
|
4330
|
+
if (isGroupNode(rootNode, rootTrie)) {
|
|
4331
|
+
activePath = [key];
|
|
4332
|
+
sticky = Boolean(rootNode.sticky || rootNode.loop);
|
|
4333
|
+
announce(`${rootNode.group ?? rootNode.label} menu`);
|
|
4334
|
+
emit();
|
|
4335
|
+
return true;
|
|
4336
|
+
}
|
|
4337
|
+
return invokeNode(rootNode, event);
|
|
4338
|
+
}
|
|
4339
|
+
function handleKeyDown(event) {
|
|
4340
|
+
if (!isControllerEnabled()) return false;
|
|
4341
|
+
if (event.defaultPrevented && activePath.length === 0 && mode !== "jump") {
|
|
4342
|
+
return false;
|
|
4343
|
+
}
|
|
4344
|
+
if (explorerOpen) {
|
|
4345
|
+
if (event.key === "Escape") {
|
|
4346
|
+
event.preventDefault();
|
|
4347
|
+
event.stopPropagation();
|
|
4348
|
+
closeExplorer();
|
|
4349
|
+
return true;
|
|
4350
|
+
}
|
|
4351
|
+
return false;
|
|
4352
|
+
}
|
|
4353
|
+
const doc = resolveDoc();
|
|
4354
|
+
const targetEl = (isElementLike(event.target) ? event.target : null) ?? doc?.activeElement ?? null;
|
|
4355
|
+
const editorTarget = getModalEditor(targetEl);
|
|
4356
|
+
const inEditable = isTextEntryElement(targetEl);
|
|
4357
|
+
if (mode === "insert") {
|
|
4358
|
+
if (event.key === "Escape") {
|
|
4359
|
+
if (editorTarget?.hasActiveSuggestion?.()) {
|
|
4360
|
+
return false;
|
|
4361
|
+
}
|
|
4362
|
+
event.preventDefault();
|
|
4363
|
+
event.stopPropagation();
|
|
4364
|
+
event.stopImmediatePropagation?.();
|
|
4365
|
+
setMode("normal");
|
|
4366
|
+
return true;
|
|
4367
|
+
}
|
|
4368
|
+
return false;
|
|
4369
|
+
}
|
|
4370
|
+
if (mode === "jump") {
|
|
4371
|
+
return handleJumpKeyDown(event);
|
|
4372
|
+
}
|
|
4373
|
+
if (activePath.length > 0) {
|
|
4374
|
+
if (event.key === "Escape") {
|
|
4375
|
+
event.preventDefault();
|
|
4376
|
+
event.stopPropagation();
|
|
4377
|
+
event.stopImmediatePropagation?.();
|
|
4378
|
+
closePrefix();
|
|
4379
|
+
return true;
|
|
4380
|
+
}
|
|
4381
|
+
if (event.key === "Backspace") {
|
|
4382
|
+
event.preventDefault();
|
|
4383
|
+
event.stopPropagation();
|
|
4384
|
+
event.stopImmediatePropagation?.();
|
|
4385
|
+
stepBackPrefix();
|
|
4386
|
+
return true;
|
|
4387
|
+
}
|
|
4388
|
+
const chordCandidates2 = eventToChordKeys(event);
|
|
4389
|
+
if (chordCandidates2.length === 0) return false;
|
|
4390
|
+
const rootTrie2 = buildMergedTrie();
|
|
4391
|
+
const parentNode = resolveNode(rootTrie2, activePath, mode);
|
|
4392
|
+
const children = parentNode ? getNodeChildren(parentNode, rootTrie2) : {};
|
|
4393
|
+
const matchedChord = chordCandidates2.find((c) => Boolean(children[c]));
|
|
4394
|
+
event.preventDefault();
|
|
4395
|
+
event.stopPropagation();
|
|
4396
|
+
if (matchedChord) {
|
|
4397
|
+
return triggerKey(matchedChord, event);
|
|
4398
|
+
}
|
|
4399
|
+
if (!sticky) {
|
|
4400
|
+
closePrefix();
|
|
4401
|
+
}
|
|
4402
|
+
return true;
|
|
4403
|
+
}
|
|
4404
|
+
if (event.key === "Escape") {
|
|
4405
|
+
if (editorTarget && (mode === "select" || !editorTarget.hasActiveSuggestion?.())) {
|
|
4406
|
+
event.preventDefault();
|
|
4407
|
+
event.stopPropagation();
|
|
4408
|
+
countBuffer = "";
|
|
4409
|
+
editorTarget.setModalState({ mode: "normal", preset });
|
|
4410
|
+
if (mode === "select") {
|
|
4411
|
+
editorTarget.transformSelection("collapse");
|
|
4412
|
+
setMode("normal");
|
|
4413
|
+
} else {
|
|
4414
|
+
emit();
|
|
4415
|
+
}
|
|
4416
|
+
return true;
|
|
4417
|
+
}
|
|
4418
|
+
if (countBuffer.length > 0 || mode === "select") {
|
|
4419
|
+
event.preventDefault();
|
|
4420
|
+
event.stopPropagation();
|
|
4421
|
+
countBuffer = "";
|
|
4422
|
+
if (editorTarget) {
|
|
4423
|
+
editorTarget.transformSelection("collapse");
|
|
4424
|
+
}
|
|
4425
|
+
if (mode === "select") {
|
|
4426
|
+
setMode("normal");
|
|
4427
|
+
} else {
|
|
4428
|
+
emit();
|
|
4429
|
+
}
|
|
4430
|
+
return true;
|
|
4431
|
+
}
|
|
4432
|
+
const parentExample = targetEl instanceof HTMLElement && !targetEl.hasAttribute("data-example") ? targetEl.closest("[data-example]") : null;
|
|
4433
|
+
const hasOpenFloatingSurface = Boolean(
|
|
4434
|
+
doc?.querySelector(
|
|
4435
|
+
'[data-scope="popover"][data-state="open"], [data-scope="menu"][data-state="open"], [data-scope="select"][data-state="open"], [data-scope="combobox"][data-state="open"], [role="dialog"]:not([hidden]):not([data-state="closed"]), [role="listbox"]:not([hidden]):not([data-state="closed"]), [aria-expanded="true"]'
|
|
4436
|
+
)
|
|
4437
|
+
);
|
|
4438
|
+
if (parentExample && (!doc || !getTopMostModalDialog(doc) && !hasOpenFloatingSurface)) {
|
|
4439
|
+
event.preventDefault();
|
|
4440
|
+
event.stopPropagation();
|
|
4441
|
+
if (doc) {
|
|
4442
|
+
lastInteractedScopeByDoc.set(doc, null);
|
|
4443
|
+
}
|
|
4444
|
+
focusElementInActivePane(parentExample);
|
|
4445
|
+
announce("Exited example preview");
|
|
4446
|
+
emit();
|
|
4447
|
+
return true;
|
|
4448
|
+
}
|
|
4449
|
+
return false;
|
|
4450
|
+
}
|
|
4451
|
+
if (event.key === "Enter" && !event.ctrlKey && !event.metaKey && !event.altKey && targetEl instanceof HTMLElement && targetEl.hasAttribute("data-example")) {
|
|
4452
|
+
event.preventDefault();
|
|
4453
|
+
event.stopPropagation();
|
|
4454
|
+
return enterExampleContainer(targetEl);
|
|
4455
|
+
}
|
|
4456
|
+
if (event.key === "Enter" && !event.ctrlKey && !event.metaKey && !event.altKey && inEditable && !editorTarget) {
|
|
4457
|
+
event.preventDefault();
|
|
4458
|
+
event.stopPropagation();
|
|
4459
|
+
setMode("insert");
|
|
4460
|
+
return true;
|
|
4461
|
+
}
|
|
4462
|
+
if (event.key === " " && !event.ctrlKey && !event.metaKey && !event.altKey && targetEl) {
|
|
4463
|
+
const role = targetEl.getAttribute("role");
|
|
4464
|
+
const isToggleControl = targetEl instanceof HTMLInputElement && (targetEl.type === "checkbox" || targetEl.type === "radio") || role === "checkbox" || role === "switch" || role === "radio";
|
|
4465
|
+
if (isToggleControl) {
|
|
4466
|
+
return false;
|
|
4467
|
+
}
|
|
4468
|
+
const isButtonControl = targetEl.tagName === "BUTTON" || role === "button";
|
|
4469
|
+
if (isButtonControl) {
|
|
4470
|
+
const previewAncestor = targetEl.closest("[data-example-preview]");
|
|
4471
|
+
const ownScope = options.getScopeElement?.() ?? null;
|
|
4472
|
+
if (previewAncestor && (!ownScope || !previewAncestor.contains(ownScope))) {
|
|
4473
|
+
return false;
|
|
4474
|
+
}
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
if (editorTarget && !editorTarget.hasActiveSuggestion?.() && !event.ctrlKey && !event.metaKey && !event.altKey && (event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "ArrowUp" || event.key === "ArrowDown")) {
|
|
4478
|
+
const arrowMotion = event.key === "ArrowLeft" ? "left" : event.key === "ArrowRight" ? "right" : event.key === "ArrowUp" ? "up" : "down";
|
|
4479
|
+
if (event.shiftKey && mode === "normal") {
|
|
4480
|
+
setMode("select");
|
|
4481
|
+
}
|
|
4482
|
+
const effectiveMode = event.shiftKey ? "select" : mode;
|
|
4483
|
+
const count = countBuffer.length > 0 ? Math.max(1, Number.parseInt(countBuffer, 10)) : 1;
|
|
4484
|
+
countBuffer = "";
|
|
4485
|
+
event.preventDefault();
|
|
4486
|
+
event.stopPropagation();
|
|
4487
|
+
editorTarget.move(arrowMotion, { preset, mode: effectiveMode, count });
|
|
4488
|
+
emit();
|
|
4489
|
+
return true;
|
|
4490
|
+
}
|
|
4491
|
+
const chordCandidates = eventToChordKeys(event);
|
|
4492
|
+
if (chordCandidates.length === 0) return false;
|
|
4493
|
+
const rootTrie = buildMergedTrie();
|
|
4494
|
+
for (const candidate of chordCandidates) {
|
|
4495
|
+
if (/^[0-9]$/.test(candidate) && (countBuffer.length > 0 || candidate !== "0" || !rootTrie["0"])) {
|
|
4496
|
+
if (countBuffer.length > 0 || candidate !== "0") {
|
|
4497
|
+
event.preventDefault();
|
|
4498
|
+
event.stopPropagation();
|
|
4499
|
+
return triggerKey(candidate, event);
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
if (rootTrie[candidate] && nodeMatchesMode(rootTrie[candidate], mode)) {
|
|
4503
|
+
event.preventDefault();
|
|
4504
|
+
event.stopPropagation();
|
|
4505
|
+
return triggerKey(candidate, event);
|
|
4506
|
+
}
|
|
4507
|
+
}
|
|
4508
|
+
if (inEditable && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
4509
|
+
event.preventDefault();
|
|
4510
|
+
event.stopPropagation();
|
|
4511
|
+
return true;
|
|
4512
|
+
}
|
|
4513
|
+
return false;
|
|
4514
|
+
}
|
|
4515
|
+
function attach(target) {
|
|
4516
|
+
detachCleanups.forEach((fn) => fn());
|
|
4517
|
+
detachCleanups = [];
|
|
4518
|
+
const doc = target instanceof Document ? target : target?.ownerDocument ?? resolveDoc();
|
|
4519
|
+
if (!doc) return () => {
|
|
4520
|
+
};
|
|
4521
|
+
const eventTarget = target ?? doc;
|
|
4522
|
+
try {
|
|
4523
|
+
const cleanupModality = trackInteractionModality({
|
|
4524
|
+
root: doc,
|
|
4525
|
+
onChange: () => {
|
|
4526
|
+
}
|
|
4527
|
+
});
|
|
4528
|
+
detachCleanups.push(cleanupModality);
|
|
4529
|
+
} catch {
|
|
4530
|
+
}
|
|
4531
|
+
try {
|
|
4532
|
+
liveRegion = createLiveRegion({
|
|
4533
|
+
level: "polite",
|
|
4534
|
+
document: doc
|
|
4535
|
+
});
|
|
4536
|
+
detachCleanups.push(() => {
|
|
4537
|
+
liveRegion?.destroy();
|
|
4538
|
+
liveRegion = null;
|
|
4539
|
+
});
|
|
4540
|
+
} catch {
|
|
4541
|
+
liveRegion = null;
|
|
4542
|
+
}
|
|
4543
|
+
const entry = {
|
|
4544
|
+
getScopeElement: () => options.getScopeElement?.() ?? null,
|
|
4545
|
+
isBusy: () => activePath.length > 0 || sticky || explorerOpen || mode === "jump" || countBuffer.length > 0
|
|
4546
|
+
};
|
|
4547
|
+
let docEntries = attachedEntriesByDoc.get(doc);
|
|
4548
|
+
if (!docEntries) {
|
|
4549
|
+
docEntries = /* @__PURE__ */ new Set();
|
|
4550
|
+
attachedEntriesByDoc.set(doc, docEntries);
|
|
4551
|
+
}
|
|
4552
|
+
docEntries.add(entry);
|
|
4553
|
+
detachCleanups.push(() => {
|
|
4554
|
+
docEntries?.delete(entry);
|
|
4555
|
+
});
|
|
4556
|
+
if (!options.getScopeElement?.()) {
|
|
4557
|
+
const storedPreset = readStoredPreset();
|
|
4558
|
+
if (storedPreset && !options.preset) {
|
|
4559
|
+
preset = storedPreset;
|
|
4560
|
+
}
|
|
4561
|
+
const storedJump = readStoredJumpAction();
|
|
4562
|
+
if (storedJump && !options.jumpAction) {
|
|
4563
|
+
jumpAction = storedJump;
|
|
4564
|
+
}
|
|
4565
|
+
if (doc.documentElement) {
|
|
4566
|
+
doc.documentElement.dataset.keymapPreset = preset;
|
|
4567
|
+
doc.documentElement.dataset.jumpAction = jumpAction;
|
|
4568
|
+
}
|
|
4569
|
+
rootControllerByDoc.set(doc, controllerApi);
|
|
4570
|
+
notifyRootControllerListeners(doc);
|
|
4571
|
+
detachCleanups.push(() => {
|
|
4572
|
+
if (rootControllerByDoc.get(doc) === controllerApi) {
|
|
4573
|
+
rootControllerByDoc.delete(doc);
|
|
4574
|
+
notifyRootControllerListeners(doc);
|
|
4575
|
+
}
|
|
4576
|
+
});
|
|
4577
|
+
}
|
|
4578
|
+
syncDomPanes(doc);
|
|
4579
|
+
emit();
|
|
4580
|
+
const onPointerDown = (e) => {
|
|
4581
|
+
if (!isControllerEnabled()) return;
|
|
4582
|
+
const targetNode = e.target instanceof Element ? e.target : null;
|
|
4583
|
+
if (!targetNode) return;
|
|
4584
|
+
if (!targetNode.closest(
|
|
4585
|
+
'[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay], [data-scope="dialog"]'
|
|
4586
|
+
)) {
|
|
4587
|
+
const clickedScope = targetNode.closest("[data-which-key-scope]") ?? null;
|
|
4588
|
+
if (!clickedScope || isScopeElementActive(clickedScope, doc)) {
|
|
4589
|
+
lastInteractedScopeByDoc.set(doc, clickedScope);
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
if (!shouldEntryHandleEvent(entry, doc)) return;
|
|
4593
|
+
for (const pane of panes.values()) {
|
|
4594
|
+
if (pane.element && pane.element.contains(targetNode)) {
|
|
4595
|
+
if (activePaneId !== pane.id) {
|
|
4596
|
+
activePaneId = pane.id;
|
|
4597
|
+
emit();
|
|
4598
|
+
}
|
|
4599
|
+
break;
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
if (isTextEntryElement(targetNode) && (mode === "normal" || mode === "select")) {
|
|
4603
|
+
setMode("insert");
|
|
4604
|
+
}
|
|
4605
|
+
};
|
|
4606
|
+
const onFocusIn = (e) => {
|
|
4607
|
+
if (!isControllerEnabled()) return;
|
|
4608
|
+
const targetNode = e.target instanceof HTMLElement ? e.target : null;
|
|
4609
|
+
if (!targetNode) return;
|
|
4610
|
+
if (programmaticFocusDepth === 0 && !targetNode.closest(
|
|
4611
|
+
'[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay], [data-scope="dialog"]'
|
|
4612
|
+
)) {
|
|
4613
|
+
const focusedScope = targetNode.closest("[data-which-key-scope]") ?? null;
|
|
4614
|
+
if (!focusedScope || isScopeElementActive(focusedScope, doc)) {
|
|
4615
|
+
lastInteractedScopeByDoc.set(doc, focusedScope);
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
if (!shouldEntryHandleEvent(entry, doc)) return;
|
|
4619
|
+
for (const pane of panes.values()) {
|
|
4620
|
+
if (pane.element && pane.element.contains(targetNode)) {
|
|
4621
|
+
const prevPaneId = activePaneId;
|
|
4622
|
+
activePaneId = pane.id;
|
|
4623
|
+
pane.lastFocusedElement = targetNode;
|
|
4624
|
+
if (prevPaneId !== pane.id) {
|
|
4625
|
+
emit();
|
|
4626
|
+
}
|
|
4627
|
+
break;
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
if (programmaticFocusDepth > 0) {
|
|
4631
|
+
return;
|
|
4632
|
+
}
|
|
4633
|
+
if (isTextEntryElement(targetNode) && !getModalEditor(targetNode)) {
|
|
4634
|
+
if (mode === "normal" || mode === "select") {
|
|
4635
|
+
setMode("insert");
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
};
|
|
4639
|
+
const onKeyDown = (e) => {
|
|
4640
|
+
if (!shouldEntryHandleEvent(entry, doc)) return;
|
|
4641
|
+
if (e instanceof KeyboardEvent || e && typeof e.key === "string") {
|
|
4642
|
+
handleKeyDown(e);
|
|
4643
|
+
}
|
|
4644
|
+
};
|
|
4645
|
+
eventTarget.addEventListener("pointerdown", onPointerDown, true);
|
|
4646
|
+
eventTarget.addEventListener("focusin", onFocusIn, true);
|
|
4647
|
+
eventTarget.addEventListener("keydown", onKeyDown, true);
|
|
4648
|
+
detachCleanups.push(() => {
|
|
4649
|
+
eventTarget.removeEventListener("pointerdown", onPointerDown, true);
|
|
4650
|
+
eventTarget.removeEventListener("focusin", onFocusIn, true);
|
|
4651
|
+
eventTarget.removeEventListener("keydown", onKeyDown, true);
|
|
4652
|
+
});
|
|
4653
|
+
return () => {
|
|
4654
|
+
detachCleanups.forEach((fn) => fn());
|
|
4655
|
+
detachCleanups = [];
|
|
4656
|
+
};
|
|
4657
|
+
}
|
|
4658
|
+
function destroy() {
|
|
4659
|
+
detachCleanups.forEach((fn) => fn());
|
|
4660
|
+
detachCleanups = [];
|
|
4661
|
+
listeners.clear();
|
|
4662
|
+
panes.clear();
|
|
4663
|
+
keymapLayers.clear();
|
|
4664
|
+
}
|
|
4665
|
+
function registerKeymap(id, nodes, layerOptions) {
|
|
4666
|
+
keymapLayers.set(id, {
|
|
4667
|
+
id,
|
|
4668
|
+
nodes,
|
|
4669
|
+
scope: layerOptions?.scope,
|
|
4670
|
+
enabled: layerOptions?.enabled ?? true
|
|
4671
|
+
});
|
|
4672
|
+
emit();
|
|
4673
|
+
return () => {
|
|
4674
|
+
keymapLayers.delete(id);
|
|
4675
|
+
emit();
|
|
4676
|
+
};
|
|
4677
|
+
}
|
|
4678
|
+
function registerCommand(commandId, handler) {
|
|
4679
|
+
commandHandlers.set(commandId, handler);
|
|
4680
|
+
return () => {
|
|
4681
|
+
if (commandHandlers.get(commandId) === handler) {
|
|
4682
|
+
commandHandlers.delete(commandId);
|
|
4683
|
+
}
|
|
4684
|
+
};
|
|
4685
|
+
}
|
|
4686
|
+
function registerPane(pane) {
|
|
4687
|
+
const existing = panes.get(pane.id);
|
|
4688
|
+
const registration = {
|
|
4689
|
+
id: pane.id,
|
|
4690
|
+
title: pane.title,
|
|
4691
|
+
element: pane.element,
|
|
4692
|
+
disabled: pane.disabled,
|
|
4693
|
+
order: pane.order ?? existing?.order ?? panes.size + 1,
|
|
4694
|
+
lastFocusedElement: existing?.lastFocusedElement ?? null
|
|
4695
|
+
};
|
|
4696
|
+
panes.set(pane.id, registration);
|
|
4697
|
+
if (!activePaneId && !pane.disabled && pane.element) {
|
|
4698
|
+
activePaneId = pane.id;
|
|
4699
|
+
}
|
|
4700
|
+
emit();
|
|
4701
|
+
return () => {
|
|
4702
|
+
panes.delete(pane.id);
|
|
4703
|
+
if (activePaneId === pane.id) {
|
|
4704
|
+
const remaining = getOrderedPanes();
|
|
4705
|
+
activePaneId = remaining[0]?.id ?? null;
|
|
4706
|
+
}
|
|
4707
|
+
emit();
|
|
4708
|
+
};
|
|
4709
|
+
}
|
|
4710
|
+
function trackBranchElement(nodeOrFn) {
|
|
4711
|
+
try {
|
|
4712
|
+
return trackDismissableBranch(nodeOrFn, { defer: true });
|
|
4713
|
+
} catch {
|
|
4714
|
+
return () => {
|
|
4715
|
+
};
|
|
4716
|
+
}
|
|
4717
|
+
}
|
|
4718
|
+
const controllerApi = {
|
|
4719
|
+
getState: () => cachedState,
|
|
4720
|
+
subscribe: (listener) => {
|
|
4721
|
+
listeners.add(listener);
|
|
4722
|
+
return () => {
|
|
4723
|
+
listeners.delete(listener);
|
|
4724
|
+
};
|
|
4725
|
+
},
|
|
4726
|
+
attach,
|
|
4727
|
+
destroy,
|
|
4728
|
+
handleKeyDown,
|
|
4729
|
+
setPreset,
|
|
4730
|
+
setMode,
|
|
4731
|
+
setJumpAction,
|
|
4732
|
+
openPrefix,
|
|
4733
|
+
closePrefix,
|
|
4734
|
+
stepBackPrefix,
|
|
4735
|
+
triggerKey: (key) => triggerKey(key),
|
|
4736
|
+
openExplorer,
|
|
4737
|
+
closeExplorer,
|
|
4738
|
+
setExplorerQuery,
|
|
4739
|
+
executeExplorerEntry,
|
|
4740
|
+
registerKeymap,
|
|
4741
|
+
registerCommand,
|
|
4742
|
+
executeCommand,
|
|
4743
|
+
registerPane,
|
|
4744
|
+
focusPane,
|
|
4745
|
+
focusPaneDirection,
|
|
4746
|
+
cyclePane,
|
|
4747
|
+
stepFocusInPane,
|
|
4748
|
+
jumpToBoundary,
|
|
4749
|
+
scrollActivePane,
|
|
4750
|
+
startJumpMode,
|
|
4751
|
+
cancelJumpMode,
|
|
4752
|
+
jumpBack,
|
|
4753
|
+
jumpForward,
|
|
4754
|
+
trackBranchElement
|
|
4755
|
+
};
|
|
4756
|
+
return controllerApi;
|
|
4757
|
+
}
|
|
4758
|
+
|
|
4759
|
+
// src/which-key/styles.ts
|
|
4760
|
+
import { cva as cva20 } from "class-variance-authority";
|
|
4761
|
+
var whichKeyVariants = cva20(
|
|
4762
|
+
"fixed z-50 flex flex-col overflow-hidden border bg-popover/95 text-popover-foreground shadow-xl backdrop-blur-md transition-all duration-150 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
4763
|
+
{
|
|
4764
|
+
variants: {
|
|
4765
|
+
variant: {
|
|
4766
|
+
helix: "right-4 bottom-4 w-80 max-w-[calc(100vw-2rem)] rounded-lg data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2",
|
|
4767
|
+
modern: "bottom-4 left-1/2 w-[min(36rem,calc(100vw-2rem))] -translate-x-1/2 rounded-xl data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2",
|
|
4768
|
+
classic: "inset-x-0 bottom-0 w-full rounded-none border-x-0 border-b-0 px-4 py-2"
|
|
4769
|
+
}
|
|
4770
|
+
},
|
|
4771
|
+
defaultVariants: {
|
|
4772
|
+
variant: "helix"
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
);
|
|
4776
|
+
var whichKeyHeaderBase = "flex items-center justify-between gap-2 px-3 pt-2.5 pb-1 text-xs font-medium";
|
|
4777
|
+
var whichKeyTitleBase = "flex items-center gap-1.5 font-semibold text-foreground";
|
|
4778
|
+
var whichKeyBreadcrumbBase = "flex items-center gap-1 text-[11px] text-muted-foreground";
|
|
4779
|
+
var whichKeyBodyVariants = cva20("p-1.5", {
|
|
4780
|
+
variants: {
|
|
4781
|
+
variant: {
|
|
4782
|
+
helix: "flex flex-col gap-0.5",
|
|
4783
|
+
modern: "grid grid-cols-1 gap-1 sm:grid-cols-2",
|
|
4784
|
+
classic: "grid grid-cols-2 gap-x-4 gap-y-1 sm:grid-cols-3 md:grid-cols-4"
|
|
4785
|
+
}
|
|
4786
|
+
},
|
|
4787
|
+
defaultVariants: {
|
|
4788
|
+
variant: "helix"
|
|
4789
|
+
}
|
|
4790
|
+
});
|
|
4791
|
+
var whichKeyItemBase = "group flex w-full cursor-pointer items-center justify-between gap-3 rounded-md px-2 py-1 text-left text-xs transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none";
|
|
4792
|
+
var whichKeyItemLabelBase = "truncate text-foreground group-hover:text-accent-foreground data-[group=true]:font-medium data-[group=true]:text-primary";
|
|
4793
|
+
var whichKeyFooterBase = "flex items-center justify-between gap-2 px-3 pt-1 pb-2 text-[10px] text-muted-foreground";
|
|
4794
|
+
var whichKeyModeBadgeVariants = cva20(
|
|
4795
|
+
"inline-flex items-center gap-1 rounded font-mono font-semibold tracking-wider uppercase select-none",
|
|
4796
|
+
{
|
|
4797
|
+
variants: {
|
|
4798
|
+
mode: {
|
|
4799
|
+
normal: "bg-primary/15 text-primary",
|
|
4800
|
+
select: "bg-warn/20 text-warn",
|
|
4801
|
+
insert: "bg-success/20 text-success",
|
|
4802
|
+
jump: "bg-info/20 text-info"
|
|
4803
|
+
},
|
|
4804
|
+
size: {
|
|
4805
|
+
sm: "px-1.5 py-0.5 text-[10px]",
|
|
4806
|
+
md: "px-2 py-0.5 text-xs",
|
|
4807
|
+
lg: "px-2.5 py-1 text-sm"
|
|
4808
|
+
}
|
|
4809
|
+
},
|
|
4810
|
+
defaultVariants: {
|
|
4811
|
+
mode: "normal",
|
|
4812
|
+
size: "sm"
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
);
|
|
4816
|
+
var whichKeyExplorerContentBase = "flex max-h-[min(34rem,85vh)] w-full max-w-xl flex-col gap-0 overflow-hidden bg-popover p-0 text-popover-foreground";
|
|
4817
|
+
var whichKeyExplorerHeaderBase = "flex flex-row items-center justify-between gap-2 px-4 pt-3.5 pb-2.5";
|
|
4818
|
+
var whichKeyExplorerListboxBase = "flex min-h-0 flex-1 flex-col rounded-none border-0 bg-transparent shadow-none";
|
|
4819
|
+
var whichKeyExplorerInputBase = "mx-4 mb-2 w-[calc(100%-2rem)] rounded-md border-0 border-b-2 border-transparent bg-muted/60 px-3 py-2 text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus-visible:border-primary focus-visible:ring-0";
|
|
4820
|
+
var whichKeyExplorerListContentBase = "max-h-none flex-1 overflow-visible px-2.5 pt-1 pb-3 outline-none";
|
|
4821
|
+
var whichKeyExplorerItemBase = "flex w-full cursor-pointer items-center justify-between gap-3 rounded-md px-2.5 py-1.5 text-sm outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground";
|
|
4822
|
+
var whichKeyExplorerHighlightMarkBase = "rounded-xs bg-primary/20 px-0.5 font-semibold text-foreground";
|
|
4823
|
+
var paneVariants = cva20(
|
|
4824
|
+
"relative transition-shadow duration-150 data-[pane-active=true]:ring-1 data-[pane-active=true]:ring-primary/40",
|
|
4825
|
+
{
|
|
4826
|
+
variants: {
|
|
4827
|
+
active: {
|
|
4828
|
+
true: "ring-1 ring-primary/40",
|
|
4829
|
+
false: ""
|
|
4830
|
+
}
|
|
4831
|
+
},
|
|
4832
|
+
defaultVariants: {
|
|
4833
|
+
active: false
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4836
|
+
);
|
|
4837
|
+
var jumpOverlayRootBase = "pointer-events-none fixed inset-0 z-[60] overflow-hidden";
|
|
4838
|
+
var jumpBadgeVariants = cva20(
|
|
4839
|
+
"pointer-events-auto fixed z-[61] inline-flex items-center justify-center rounded border px-1 py-0.5 font-mono text-[11px] leading-none font-bold shadow-md transition-transform select-none",
|
|
4840
|
+
{
|
|
4841
|
+
variants: {
|
|
4842
|
+
action: {
|
|
4843
|
+
focus: "border-primary bg-primary text-primary-foreground",
|
|
4844
|
+
activate: "border-warn bg-warn text-warn-foreground"
|
|
4845
|
+
}
|
|
4846
|
+
},
|
|
4847
|
+
defaultVariants: {
|
|
4848
|
+
action: "focus"
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
);
|
|
4852
|
+
var jumpBadgeMatchedPrefixBase = "opacity-50 line-through";
|
|
1210
4853
|
|
|
1211
4854
|
// src/editor/build-extensions.ts
|
|
1212
4855
|
import StarterKit from "@tiptap/starter-kit";
|
|
@@ -1315,9 +4958,898 @@ var EditorHeading = Heading2.extend({
|
|
|
1315
4958
|
});
|
|
1316
4959
|
|
|
1317
4960
|
// src/editor/extensions/slash-commands.ts
|
|
1318
|
-
import { Extension as
|
|
1319
|
-
import { PluginKey as
|
|
4961
|
+
import { Extension as Extension4 } from "@tiptap/core";
|
|
4962
|
+
import { PluginKey as PluginKey3 } from "@tiptap/pm/state";
|
|
1320
4963
|
import Suggestion from "@tiptap/suggestion";
|
|
4964
|
+
|
|
4965
|
+
// src/editor/extensions/modal-keymap.ts
|
|
4966
|
+
import { Extension as Extension3 } from "@tiptap/core";
|
|
4967
|
+
import { undo, redo } from "@tiptap/pm/history";
|
|
4968
|
+
import { NodeSelection, Plugin as Plugin2, PluginKey as PluginKey2, Selection, TextSelection } from "@tiptap/pm/state";
|
|
4969
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
4970
|
+
var modalKeymapPluginKey = new PluginKey2("modalKeymap");
|
|
4971
|
+
function collectLeafBlocks(doc) {
|
|
4972
|
+
const blocks = [];
|
|
4973
|
+
doc.descendants((node, pos) => {
|
|
4974
|
+
if (node.isTextblock) {
|
|
4975
|
+
blocks.push({
|
|
4976
|
+
node,
|
|
4977
|
+
pos,
|
|
4978
|
+
start: pos + 1,
|
|
4979
|
+
end: pos + 1 + node.content.size,
|
|
4980
|
+
isTextblock: true,
|
|
4981
|
+
isAtom: false
|
|
4982
|
+
});
|
|
4983
|
+
return false;
|
|
4984
|
+
}
|
|
4985
|
+
if (node.isAtom && !node.isText) {
|
|
4986
|
+
blocks.push({
|
|
4987
|
+
node,
|
|
4988
|
+
pos,
|
|
4989
|
+
start: pos,
|
|
4990
|
+
end: pos + node.nodeSize,
|
|
4991
|
+
isTextblock: false,
|
|
4992
|
+
isAtom: true
|
|
4993
|
+
});
|
|
4994
|
+
return false;
|
|
4995
|
+
}
|
|
4996
|
+
return true;
|
|
4997
|
+
});
|
|
4998
|
+
return blocks;
|
|
4999
|
+
}
|
|
5000
|
+
function collectWords(doc) {
|
|
5001
|
+
const tokens = [];
|
|
5002
|
+
doc.descendants((node, pos) => {
|
|
5003
|
+
if (!node.isTextblock) return true;
|
|
5004
|
+
const blockStart = pos + 1;
|
|
5005
|
+
const blockEnd = pos + 1 + node.content.size;
|
|
5006
|
+
let offset = 0;
|
|
5007
|
+
node.forEach((child) => {
|
|
5008
|
+
if (child.isText && child.text) {
|
|
5009
|
+
const regex = /\w+|[^\w\s]+/g;
|
|
5010
|
+
let match = regex.exec(child.text);
|
|
5011
|
+
while (match !== null) {
|
|
5012
|
+
tokens.push({
|
|
5013
|
+
start: blockStart + offset + match.index,
|
|
5014
|
+
end: blockStart + offset + match.index + match[0].length,
|
|
5015
|
+
text: match[0],
|
|
5016
|
+
blockStart,
|
|
5017
|
+
blockEnd
|
|
5018
|
+
});
|
|
5019
|
+
match = regex.exec(child.text);
|
|
5020
|
+
}
|
|
5021
|
+
} else if (child.isAtom) {
|
|
5022
|
+
tokens.push({
|
|
5023
|
+
start: blockStart + offset,
|
|
5024
|
+
end: blockStart + offset + child.nodeSize,
|
|
5025
|
+
text: "\uFFFC",
|
|
5026
|
+
blockStart,
|
|
5027
|
+
blockEnd
|
|
5028
|
+
});
|
|
5029
|
+
}
|
|
5030
|
+
offset += child.nodeSize;
|
|
5031
|
+
});
|
|
5032
|
+
return false;
|
|
5033
|
+
});
|
|
5034
|
+
return tokens;
|
|
5035
|
+
}
|
|
5036
|
+
function dispatchTransaction(editor, tr) {
|
|
5037
|
+
editor.view.dispatch(tr);
|
|
5038
|
+
}
|
|
5039
|
+
function isEditorInInsertMode(editor) {
|
|
5040
|
+
const storage = editor.storage.modalKeymap;
|
|
5041
|
+
if (!storage) return true;
|
|
5042
|
+
return storage.mode === "insert";
|
|
5043
|
+
}
|
|
5044
|
+
function getEditorModalTarget(editor) {
|
|
5045
|
+
const storage = editor.storage.modalKeymap;
|
|
5046
|
+
if (!storage) return void 0;
|
|
5047
|
+
if (editor.state.plugins.length === 0 && editor.extensionManager?.plugins?.length) {
|
|
5048
|
+
editor.view.updateState(editor.state.reconfigure({ plugins: editor.extensionManager.plugins }));
|
|
5049
|
+
}
|
|
5050
|
+
if (!storage.target) {
|
|
5051
|
+
storage.target = createModalTargetForEditor(editor, { enforceTitle: true });
|
|
5052
|
+
}
|
|
5053
|
+
return storage.target;
|
|
5054
|
+
}
|
|
5055
|
+
var sharedRegisterSlice = null;
|
|
5056
|
+
function getCharEnd(doc, pos) {
|
|
5057
|
+
if (pos < 0 || pos >= doc.content.size) return pos;
|
|
5058
|
+
const $pos = doc.resolve(pos);
|
|
5059
|
+
if ($pos.parent.isTextblock && pos < $pos.end()) {
|
|
5060
|
+
const after = $pos.nodeAfter;
|
|
5061
|
+
if (after && after.isAtom && !after.isText) {
|
|
5062
|
+
return pos + after.nodeSize;
|
|
5063
|
+
}
|
|
5064
|
+
return pos + 1;
|
|
5065
|
+
}
|
|
5066
|
+
return pos;
|
|
5067
|
+
}
|
|
5068
|
+
function getCursorCharPos(doc, sel) {
|
|
5069
|
+
if (sel.empty) return sel.head;
|
|
5070
|
+
if (sel.head > sel.anchor) {
|
|
5071
|
+
const $head = doc.resolve(sel.head);
|
|
5072
|
+
if ($head.parent.isTextblock && sel.head > $head.start() && sel.head - 1 >= sel.from) {
|
|
5073
|
+
return sel.head - 1;
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
return sel.head;
|
|
5077
|
+
}
|
|
5078
|
+
function getAnchorCharPos(doc, sel) {
|
|
5079
|
+
if (sel.empty) return sel.anchor;
|
|
5080
|
+
if (sel.head < sel.anchor) {
|
|
5081
|
+
const $anchor = doc.resolve(sel.anchor);
|
|
5082
|
+
if ($anchor.parent.isTextblock && sel.anchor > $anchor.start() && sel.anchor - 1 >= sel.from) {
|
|
5083
|
+
return sel.anchor - 1;
|
|
5084
|
+
}
|
|
5085
|
+
}
|
|
5086
|
+
return sel.anchor;
|
|
5087
|
+
}
|
|
5088
|
+
function createExtendedSelection(doc, sel, nextCursorChar) {
|
|
5089
|
+
const anchorChar = getAnchorCharPos(doc, sel);
|
|
5090
|
+
if (nextCursorChar >= anchorChar) {
|
|
5091
|
+
return TextSelection.create(doc, anchorChar, getCharEnd(doc, nextCursorChar));
|
|
5092
|
+
}
|
|
5093
|
+
return TextSelection.create(doc, getCharEnd(doc, anchorChar), nextCursorChar);
|
|
5094
|
+
}
|
|
5095
|
+
function createModalTargetForEditor(editor, options) {
|
|
5096
|
+
const getStorage = () => editor.storage.modalKeymap;
|
|
5097
|
+
const updateMeta = (tr, patch) => {
|
|
5098
|
+
const prev = modalKeymapPluginKey.getState(editor.state) ?? {
|
|
5099
|
+
mode: getStorage().mode,
|
|
5100
|
+
preset: getStorage().preset,
|
|
5101
|
+
secondaryRanges: [],
|
|
5102
|
+
goalColumn: null
|
|
5103
|
+
};
|
|
5104
|
+
return tr.setMeta(modalKeymapPluginKey, {
|
|
5105
|
+
...prev,
|
|
5106
|
+
...patch
|
|
5107
|
+
});
|
|
5108
|
+
};
|
|
5109
|
+
return {
|
|
5110
|
+
move(motion, { preset, mode, count }) {
|
|
5111
|
+
const state = editor.state;
|
|
5112
|
+
const doc = state.doc;
|
|
5113
|
+
const sel = state.selection;
|
|
5114
|
+
const steps = Math.max(1, count);
|
|
5115
|
+
const isSelectionFirst = (preset === "helix" || preset === "kakoune") && mode === "normal";
|
|
5116
|
+
const isExtend = mode === "select";
|
|
5117
|
+
let tr = state.tr;
|
|
5118
|
+
const pluginState = modalKeymapPluginKey.getState(state);
|
|
5119
|
+
if (motion === "wordForward" || motion === "wordBackward" || motion === "wordEnd") {
|
|
5120
|
+
const words = collectWords(doc);
|
|
5121
|
+
if (words.length === 0) return false;
|
|
5122
|
+
const cursor = sel.head;
|
|
5123
|
+
let targetWord;
|
|
5124
|
+
if (motion === "wordForward") {
|
|
5125
|
+
const idx = words.findIndex((w) => w.start > cursor);
|
|
5126
|
+
if (idx === -1) {
|
|
5127
|
+
targetWord = words[words.length - 1];
|
|
5128
|
+
} else {
|
|
5129
|
+
const currentWord = words.find((w) => cursor >= w.start && cursor < w.end);
|
|
5130
|
+
if (isSelectionFirst && currentWord && sel.empty) {
|
|
5131
|
+
targetWord = words[Math.min(words.length - 1, words.indexOf(currentWord) + (steps - 1))];
|
|
5132
|
+
} else {
|
|
5133
|
+
targetWord = words[Math.min(words.length - 1, idx + steps - 1)];
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
} else if (motion === "wordEnd") {
|
|
5137
|
+
const idx = words.findIndex((w) => w.end > cursor);
|
|
5138
|
+
targetWord = idx === -1 ? words[words.length - 1] : words[Math.min(words.length - 1, idx + steps - 1)];
|
|
5139
|
+
} else {
|
|
5140
|
+
const backRef = sel.empty ? cursor : sel.from;
|
|
5141
|
+
let idx = -1;
|
|
5142
|
+
for (let i = words.length - 1; i >= 0; i -= 1) {
|
|
5143
|
+
if (words[i].start < backRef) {
|
|
5144
|
+
idx = i;
|
|
5145
|
+
break;
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
targetWord = idx === -1 ? words[0] : words[Math.max(0, idx - (steps - 1))];
|
|
5149
|
+
}
|
|
5150
|
+
if (!targetWord) return false;
|
|
5151
|
+
if (isExtend) {
|
|
5152
|
+
const nextCursor = motion === "wordBackward" ? targetWord.start : Math.max(targetWord.start, targetWord.end - 1);
|
|
5153
|
+
tr = tr.setSelection(createExtendedSelection(doc, sel, nextCursor));
|
|
5154
|
+
} else if (isSelectionFirst) {
|
|
5155
|
+
if (motion === "wordBackward") {
|
|
5156
|
+
tr = tr.setSelection(TextSelection.create(doc, targetWord.end, targetWord.start));
|
|
5157
|
+
} else {
|
|
5158
|
+
tr = tr.setSelection(TextSelection.create(doc, targetWord.start, targetWord.end));
|
|
5159
|
+
}
|
|
5160
|
+
} else {
|
|
5161
|
+
const destPos = motion === "wordEnd" ? Math.max(targetWord.start, targetWord.end - 1) : targetWord.start;
|
|
5162
|
+
tr = tr.setSelection(TextSelection.create(doc, destPos));
|
|
5163
|
+
}
|
|
5164
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5165
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5166
|
+
return true;
|
|
5167
|
+
}
|
|
5168
|
+
if (motion === "lineSelect") {
|
|
5169
|
+
const blocks = collectLeafBlocks(doc).filter((b) => b.isTextblock);
|
|
5170
|
+
if (blocks.length === 0) return false;
|
|
5171
|
+
const currentBlockIdx = blocks.findIndex((b) => sel.from >= b.start && sel.from <= b.end);
|
|
5172
|
+
const startIdx = currentBlockIdx === -1 ? 0 : currentBlockIdx;
|
|
5173
|
+
const startBlock = blocks[startIdx];
|
|
5174
|
+
const alreadyCoversCurrent = sel.from <= startBlock.start && sel.to >= startBlock.end && !sel.empty;
|
|
5175
|
+
let endBlockIdx = startIdx + (steps - 1);
|
|
5176
|
+
if (alreadyCoversCurrent) {
|
|
5177
|
+
const currentEndIdx = blocks.findIndex((b) => sel.to >= b.start && sel.to <= b.end);
|
|
5178
|
+
endBlockIdx = (currentEndIdx === -1 ? startIdx : currentEndIdx) + steps;
|
|
5179
|
+
}
|
|
5180
|
+
const endBlock = blocks[Math.min(blocks.length - 1, endBlockIdx)];
|
|
5181
|
+
tr = tr.setSelection(TextSelection.create(doc, startBlock.start, endBlock.end));
|
|
5182
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5183
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5184
|
+
return true;
|
|
5185
|
+
}
|
|
5186
|
+
if (motion === "lineStart" || motion === "lineEnd") {
|
|
5187
|
+
const cursorPos = getCursorCharPos(doc, sel);
|
|
5188
|
+
const $head = doc.resolve(cursorPos);
|
|
5189
|
+
if (isExtend) {
|
|
5190
|
+
const dest = motion === "lineStart" ? $head.start() : Math.max($head.start(), $head.end() - 1);
|
|
5191
|
+
tr = tr.setSelection(createExtendedSelection(doc, sel, dest));
|
|
5192
|
+
} else {
|
|
5193
|
+
const dest = motion === "lineStart" ? $head.start() : $head.end();
|
|
5194
|
+
tr = tr.setSelection(TextSelection.create(doc, dest));
|
|
5195
|
+
}
|
|
5196
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5197
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5198
|
+
return true;
|
|
5199
|
+
}
|
|
5200
|
+
if (motion === "docStart" || motion === "docEnd") {
|
|
5201
|
+
const edgeSel = motion === "docStart" ? Selection.atStart(doc) : Selection.atEnd(doc);
|
|
5202
|
+
if (isExtend) {
|
|
5203
|
+
const dest = motion === "docStart" ? edgeSel.head : Math.max(edgeSel.$head.start(), edgeSel.head - 1);
|
|
5204
|
+
tr = tr.setSelection(createExtendedSelection(doc, sel, dest));
|
|
5205
|
+
} else {
|
|
5206
|
+
tr = tr.setSelection(edgeSel);
|
|
5207
|
+
}
|
|
5208
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5209
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5210
|
+
return true;
|
|
5211
|
+
}
|
|
5212
|
+
if (motion === "paragraphForward" || motion === "paragraphBackward") {
|
|
5213
|
+
const dir = motion === "paragraphForward" ? 1 : -1;
|
|
5214
|
+
const blocks = collectLeafBlocks(doc);
|
|
5215
|
+
if (blocks.length === 0) return false;
|
|
5216
|
+
const cursorPos = getCursorCharPos(doc, sel);
|
|
5217
|
+
let currentIdx = blocks.findIndex(
|
|
5218
|
+
(b) => b.isTextblock ? cursorPos >= b.start && cursorPos <= b.end : sel.from === b.pos
|
|
5219
|
+
);
|
|
5220
|
+
if (currentIdx === -1) {
|
|
5221
|
+
currentIdx = 0;
|
|
5222
|
+
}
|
|
5223
|
+
const targetIdx = Math.max(0, Math.min(blocks.length - 1, currentIdx + dir * steps));
|
|
5224
|
+
const targetBlock = blocks[targetIdx];
|
|
5225
|
+
if (targetBlock.isAtom && NodeSelection.isSelectable(targetBlock.node)) {
|
|
5226
|
+
tr = tr.setSelection(NodeSelection.create(doc, targetBlock.pos));
|
|
5227
|
+
} else if (isExtend) {
|
|
5228
|
+
const dest = dir > 0 ? Math.max(targetBlock.start, targetBlock.end - 1) : targetBlock.start;
|
|
5229
|
+
tr = tr.setSelection(createExtendedSelection(doc, sel, dest));
|
|
5230
|
+
} else if (isSelectionFirst) {
|
|
5231
|
+
tr = tr.setSelection(TextSelection.create(doc, targetBlock.start, targetBlock.end));
|
|
5232
|
+
} else {
|
|
5233
|
+
tr = tr.setSelection(TextSelection.create(doc, targetBlock.start));
|
|
5234
|
+
}
|
|
5235
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5236
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5237
|
+
return true;
|
|
5238
|
+
}
|
|
5239
|
+
if (motion === "left" || motion === "right") {
|
|
5240
|
+
const dir = motion === "left" ? -1 : 1;
|
|
5241
|
+
const blocks = collectLeafBlocks(doc);
|
|
5242
|
+
if (blocks.length === 0) return false;
|
|
5243
|
+
let targetPos = getCursorCharPos(doc, sel);
|
|
5244
|
+
for (let i = 0; i < steps; i += 1) {
|
|
5245
|
+
const $pos = doc.resolve(targetPos);
|
|
5246
|
+
const nextInBlock = targetPos + dir;
|
|
5247
|
+
if ($pos.parent.isTextblock && nextInBlock >= $pos.start() && nextInBlock <= $pos.end()) {
|
|
5248
|
+
const childNode = dir > 0 ? $pos.nodeAfter : $pos.nodeBefore;
|
|
5249
|
+
if (childNode && childNode.isAtom && !childNode.isText && NodeSelection.isSelectable(childNode)) {
|
|
5250
|
+
const atomPos = dir > 0 ? targetPos : targetPos - childNode.nodeSize;
|
|
5251
|
+
tr = tr.setSelection(NodeSelection.create(doc, atomPos));
|
|
5252
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5253
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5254
|
+
return true;
|
|
5255
|
+
}
|
|
5256
|
+
targetPos = nextInBlock;
|
|
5257
|
+
} else {
|
|
5258
|
+
const found = Selection.findFrom(
|
|
5259
|
+
doc.resolve(Math.max(0, Math.min(doc.content.size, targetPos + dir))),
|
|
5260
|
+
dir,
|
|
5261
|
+
true
|
|
5262
|
+
);
|
|
5263
|
+
if (found) {
|
|
5264
|
+
targetPos = found.head;
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
}
|
|
5268
|
+
tr = tr.setSelection(
|
|
5269
|
+
isExtend ? createExtendedSelection(doc, sel, targetPos) : TextSelection.create(doc, targetPos)
|
|
5270
|
+
);
|
|
5271
|
+
tr = updateMeta(tr, { goalColumn: null });
|
|
5272
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5273
|
+
return true;
|
|
5274
|
+
}
|
|
5275
|
+
if (motion === "down" || motion === "up") {
|
|
5276
|
+
const dir = motion === "down" ? 1 : -1;
|
|
5277
|
+
const blocks = collectLeafBlocks(doc);
|
|
5278
|
+
if (blocks.length === 0) return false;
|
|
5279
|
+
const cursorPos = getCursorCharPos(doc, sel);
|
|
5280
|
+
let currentIdx = blocks.findIndex(
|
|
5281
|
+
(b) => b.isTextblock ? cursorPos >= b.start && cursorPos <= b.end : sel.from === b.pos
|
|
5282
|
+
);
|
|
5283
|
+
if (currentIdx === -1) {
|
|
5284
|
+
currentIdx = 0;
|
|
5285
|
+
}
|
|
5286
|
+
const currentBlock = blocks[currentIdx];
|
|
5287
|
+
const currentColumn = currentBlock.isTextblock ? cursorPos - currentBlock.start : 0;
|
|
5288
|
+
const goalCol = pluginState?.goalColumn ?? currentColumn;
|
|
5289
|
+
const targetIdx = Math.max(0, Math.min(blocks.length - 1, currentIdx + dir * steps));
|
|
5290
|
+
const targetBlock = blocks[targetIdx];
|
|
5291
|
+
if (targetBlock.isAtom && NodeSelection.isSelectable(targetBlock.node)) {
|
|
5292
|
+
tr = tr.setSelection(NodeSelection.create(doc, targetBlock.pos));
|
|
5293
|
+
} else {
|
|
5294
|
+
const maxTargetPos = targetBlock.end > targetBlock.start ? targetBlock.end - 1 : targetBlock.start;
|
|
5295
|
+
const nextHead = Math.min(targetBlock.start + goalCol, isExtend ? maxTargetPos : targetBlock.end);
|
|
5296
|
+
tr = tr.setSelection(
|
|
5297
|
+
isExtend ? createExtendedSelection(doc, sel, nextHead) : TextSelection.create(doc, nextHead)
|
|
5298
|
+
);
|
|
5299
|
+
}
|
|
5300
|
+
tr = updateMeta(tr, { goalColumn: goalCol });
|
|
5301
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5302
|
+
return true;
|
|
5303
|
+
}
|
|
5304
|
+
return false;
|
|
5305
|
+
},
|
|
5306
|
+
selectTextObject(spec) {
|
|
5307
|
+
const state = editor.state;
|
|
5308
|
+
const doc = state.doc;
|
|
5309
|
+
const sel = state.selection;
|
|
5310
|
+
const isInner = spec.startsWith("i");
|
|
5311
|
+
const kind = spec.slice(1);
|
|
5312
|
+
if (kind === "w") {
|
|
5313
|
+
const words = collectWords(doc);
|
|
5314
|
+
if (words.length === 0) return false;
|
|
5315
|
+
const cursor = sel.head;
|
|
5316
|
+
const matched = words.find((w) => cursor >= w.start && cursor <= w.end) ?? words.find((w) => w.start >= cursor) ?? words[words.length - 1];
|
|
5317
|
+
let from = matched.start;
|
|
5318
|
+
let to = matched.end;
|
|
5319
|
+
if (!isInner) {
|
|
5320
|
+
const $end = doc.resolve(to);
|
|
5321
|
+
const afterText = doc.textBetween(to, $end.end(), "");
|
|
5322
|
+
const trailingWs = /^\s+/.exec(afterText);
|
|
5323
|
+
if (trailingWs) {
|
|
5324
|
+
to += trailingWs[0].length;
|
|
5325
|
+
} else {
|
|
5326
|
+
const $start = doc.resolve(from);
|
|
5327
|
+
const beforeText = doc.textBetween($start.start(), from, "");
|
|
5328
|
+
const leadingWs = /\s+$/.exec(beforeText);
|
|
5329
|
+
if (leadingWs) {
|
|
5330
|
+
from -= leadingWs[0].length;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5334
|
+
const tr2 = state.tr.setSelection(TextSelection.create(doc, from, to));
|
|
5335
|
+
dispatchTransaction(editor, tr2.scrollIntoView());
|
|
5336
|
+
return true;
|
|
5337
|
+
}
|
|
5338
|
+
const matchesNodeType = (typeName) => {
|
|
5339
|
+
switch (kind) {
|
|
5340
|
+
case "p":
|
|
5341
|
+
return typeName === "paragraph" || typeName === "heading";
|
|
5342
|
+
case "c":
|
|
5343
|
+
return typeName === "codeBlock";
|
|
5344
|
+
case "n":
|
|
5345
|
+
return typeName === "notice" || typeName === "blockquote";
|
|
5346
|
+
case "l":
|
|
5347
|
+
return typeName === "listItem" || typeName === "taskItem";
|
|
5348
|
+
default:
|
|
5349
|
+
return false;
|
|
5350
|
+
}
|
|
5351
|
+
};
|
|
5352
|
+
const $head = sel.$head;
|
|
5353
|
+
let targetNode = null;
|
|
5354
|
+
let targetPos = -1;
|
|
5355
|
+
if (kind === "p") {
|
|
5356
|
+
for (let d = $head.depth; d >= 1; d -= 1) {
|
|
5357
|
+
const ancestor = $head.node(d);
|
|
5358
|
+
if (ancestor.type.name === "paragraph") {
|
|
5359
|
+
targetNode = ancestor;
|
|
5360
|
+
targetPos = $head.before(d);
|
|
5361
|
+
break;
|
|
5362
|
+
}
|
|
5363
|
+
}
|
|
5364
|
+
if (!targetNode) {
|
|
5365
|
+
doc.descendants((node, pos) => {
|
|
5366
|
+
if (targetNode) return false;
|
|
5367
|
+
if (node.type.name === "paragraph") {
|
|
5368
|
+
targetNode = node;
|
|
5369
|
+
targetPos = pos;
|
|
5370
|
+
return false;
|
|
5371
|
+
}
|
|
5372
|
+
return true;
|
|
5373
|
+
});
|
|
5374
|
+
}
|
|
5375
|
+
}
|
|
5376
|
+
if (!targetNode) {
|
|
5377
|
+
for (let d = $head.depth; d >= 1; d -= 1) {
|
|
5378
|
+
const ancestor = $head.node(d);
|
|
5379
|
+
if (matchesNodeType(ancestor.type.name)) {
|
|
5380
|
+
targetNode = ancestor;
|
|
5381
|
+
targetPos = $head.before(d);
|
|
5382
|
+
break;
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
if (!targetNode) {
|
|
5387
|
+
doc.descendants((node, pos) => {
|
|
5388
|
+
if (targetNode) return false;
|
|
5389
|
+
if (matchesNodeType(node.type.name)) {
|
|
5390
|
+
targetNode = node;
|
|
5391
|
+
targetPos = pos;
|
|
5392
|
+
return false;
|
|
5393
|
+
}
|
|
5394
|
+
return true;
|
|
5395
|
+
});
|
|
5396
|
+
}
|
|
5397
|
+
if (!targetNode || targetPos < 0) return false;
|
|
5398
|
+
const foundNode = targetNode;
|
|
5399
|
+
let firstTextStart = -1;
|
|
5400
|
+
let lastTextEnd = -1;
|
|
5401
|
+
foundNode.descendants((child, relPos) => {
|
|
5402
|
+
if (child.isTextblock) {
|
|
5403
|
+
const absStart = targetPos + 1 + relPos + 1;
|
|
5404
|
+
const absEnd = absStart + child.content.size;
|
|
5405
|
+
if (firstTextStart === -1) firstTextStart = absStart;
|
|
5406
|
+
lastTextEnd = absEnd;
|
|
5407
|
+
return false;
|
|
5408
|
+
}
|
|
5409
|
+
return true;
|
|
5410
|
+
});
|
|
5411
|
+
if (foundNode.isTextblock) {
|
|
5412
|
+
firstTextStart = targetPos + 1;
|
|
5413
|
+
lastTextEnd = targetPos + 1 + foundNode.content.size;
|
|
5414
|
+
}
|
|
5415
|
+
if (firstTextStart === -1 || lastTextEnd === -1) return false;
|
|
5416
|
+
if (isInner) {
|
|
5417
|
+
const tr2 = state.tr.setSelection(TextSelection.create(doc, firstTextStart, lastTextEnd));
|
|
5418
|
+
dispatchTransaction(editor, tr2.scrollIntoView());
|
|
5419
|
+
return true;
|
|
5420
|
+
}
|
|
5421
|
+
const nodeStart = Selection.findFrom(doc.resolve(targetPos), 1, true)?.from ?? firstTextStart;
|
|
5422
|
+
const nodeEnd = Selection.findFrom(doc.resolve(targetPos + foundNode.nodeSize), -1, true)?.to ?? lastTextEnd;
|
|
5423
|
+
const tr = state.tr.setSelection(
|
|
5424
|
+
TextSelection.create(doc, Math.min(nodeStart, firstTextStart), Math.max(nodeEnd, lastTextEnd))
|
|
5425
|
+
);
|
|
5426
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5427
|
+
return true;
|
|
5428
|
+
},
|
|
5429
|
+
transformSelection(action) {
|
|
5430
|
+
const state = editor.state;
|
|
5431
|
+
const doc = state.doc;
|
|
5432
|
+
const sel = state.selection;
|
|
5433
|
+
const pluginState = modalKeymapPluginKey.getState(state);
|
|
5434
|
+
const currentSecondary = pluginState?.secondaryRanges ?? [];
|
|
5435
|
+
if (action === "collapse") {
|
|
5436
|
+
let tr = state.tr.setSelection(TextSelection.create(doc, getCursorCharPos(doc, sel)));
|
|
5437
|
+
tr = updateMeta(tr, { secondaryRanges: [] });
|
|
5438
|
+
dispatchTransaction(editor, tr);
|
|
5439
|
+
return true;
|
|
5440
|
+
}
|
|
5441
|
+
if (action === "flip") {
|
|
5442
|
+
if (sel.empty) return false;
|
|
5443
|
+
const tr = state.tr.setSelection(TextSelection.create(doc, sel.head, sel.anchor));
|
|
5444
|
+
dispatchTransaction(editor, tr);
|
|
5445
|
+
return true;
|
|
5446
|
+
}
|
|
5447
|
+
if (action === "keepPrimary") {
|
|
5448
|
+
const tr = updateMeta(state.tr, { secondaryRanges: [] });
|
|
5449
|
+
dispatchTransaction(editor, tr);
|
|
5450
|
+
return true;
|
|
5451
|
+
}
|
|
5452
|
+
if (action === "addCursorBelow" || action === "addCursorAbove") {
|
|
5453
|
+
const dir = action === "addCursorBelow" ? 1 : -1;
|
|
5454
|
+
const blocks = collectLeafBlocks(doc).filter((b) => b.isTextblock);
|
|
5455
|
+
if (blocks.length < 2) return false;
|
|
5456
|
+
const referenceHead = currentSecondary.length > 0 ? currentSecondary[currentSecondary.length - 1].head : sel.head;
|
|
5457
|
+
const currentIdx = blocks.findIndex((b) => referenceHead >= b.start && referenceHead <= b.end);
|
|
5458
|
+
if (currentIdx === -1) return false;
|
|
5459
|
+
const nextIdx = currentIdx + dir;
|
|
5460
|
+
if (nextIdx < 0 || nextIdx >= blocks.length) return false;
|
|
5461
|
+
const currBlock = blocks[currentIdx];
|
|
5462
|
+
const nextBlock = blocks[nextIdx];
|
|
5463
|
+
const colOffset = referenceHead - currBlock.start;
|
|
5464
|
+
const selLength = Math.max(0, sel.to - sel.from);
|
|
5465
|
+
const nextFrom = Math.min(nextBlock.start + colOffset, nextBlock.end);
|
|
5466
|
+
const nextTo = Math.min(nextFrom + selLength, nextBlock.end);
|
|
5467
|
+
const nextRange = {
|
|
5468
|
+
from: nextFrom,
|
|
5469
|
+
to: nextTo,
|
|
5470
|
+
head: nextTo
|
|
5471
|
+
};
|
|
5472
|
+
const tr = updateMeta(state.tr, {
|
|
5473
|
+
secondaryRanges: [...currentSecondary, nextRange]
|
|
5474
|
+
});
|
|
5475
|
+
dispatchTransaction(editor, tr);
|
|
5476
|
+
return true;
|
|
5477
|
+
}
|
|
5478
|
+
return false;
|
|
5479
|
+
},
|
|
5480
|
+
execOperator(op, { count }) {
|
|
5481
|
+
const state = editor.state;
|
|
5482
|
+
const doc = state.doc;
|
|
5483
|
+
const sel = state.selection;
|
|
5484
|
+
const storage = getStorage();
|
|
5485
|
+
const pluginState = modalKeymapPluginKey.getState(state);
|
|
5486
|
+
const secondaryRanges = pluginState?.secondaryRanges ?? [];
|
|
5487
|
+
if (op === "undo") {
|
|
5488
|
+
if (typeof editor.commands?.undo === "function") {
|
|
5489
|
+
const ok = editor.commands.undo();
|
|
5490
|
+
if (ok) return true;
|
|
5491
|
+
}
|
|
5492
|
+
return undo(state, (tr) => dispatchTransaction(editor, tr));
|
|
5493
|
+
}
|
|
5494
|
+
if (op === "redo") {
|
|
5495
|
+
if (typeof editor.commands?.redo === "function") {
|
|
5496
|
+
const ok = editor.commands.redo();
|
|
5497
|
+
if (ok) return true;
|
|
5498
|
+
}
|
|
5499
|
+
return redo(state, (tr) => dispatchTransaction(editor, tr));
|
|
5500
|
+
}
|
|
5501
|
+
if (op === "insertStart") {
|
|
5502
|
+
let tr = state.tr.setSelection(TextSelection.create(doc, sel.from));
|
|
5503
|
+
tr = updateMeta(tr, { mode: "insert", secondaryRanges: [] });
|
|
5504
|
+
storage.mode = "insert";
|
|
5505
|
+
dispatchTransaction(editor, tr);
|
|
5506
|
+
return { enterInsert: true };
|
|
5507
|
+
}
|
|
5508
|
+
if (op === "appendEnd") {
|
|
5509
|
+
const dest = sel.empty ? Math.min(sel.$head.end(), sel.to + 1) : sel.to;
|
|
5510
|
+
let tr = state.tr.setSelection(TextSelection.create(doc, dest));
|
|
5511
|
+
tr = updateMeta(tr, { mode: "insert", secondaryRanges: [] });
|
|
5512
|
+
storage.mode = "insert";
|
|
5513
|
+
dispatchTransaction(editor, tr);
|
|
5514
|
+
return { enterInsert: true };
|
|
5515
|
+
}
|
|
5516
|
+
if (op === "openBelow" || op === "openAbove") {
|
|
5517
|
+
const $pos = sel.$head;
|
|
5518
|
+
const blockDepth = Math.max(1, $pos.depth);
|
|
5519
|
+
const beforeBlock = $pos.before(blockDepth);
|
|
5520
|
+
const afterBlock = $pos.after(blockDepth);
|
|
5521
|
+
const enforceH1 = options.enforceTitle !== false;
|
|
5522
|
+
const isFirstTitle = enforceH1 && beforeBlock === 0 && doc.firstChild?.type.name === "heading" && doc.firstChild.attrs.level === 1;
|
|
5523
|
+
const insertPos = op === "openBelow" || isFirstTitle ? afterBlock : beforeBlock;
|
|
5524
|
+
const paragraphType = state.schema.nodes.paragraph;
|
|
5525
|
+
if (!paragraphType) return false;
|
|
5526
|
+
const newParagraph = paragraphType.create();
|
|
5527
|
+
let tr = state.tr.insert(insertPos, newParagraph);
|
|
5528
|
+
tr = tr.setSelection(TextSelection.create(tr.doc, insertPos + 1));
|
|
5529
|
+
tr = updateMeta(tr, { mode: "insert", secondaryRanges: [] });
|
|
5530
|
+
storage.mode = "insert";
|
|
5531
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5532
|
+
return { enterInsert: true };
|
|
5533
|
+
}
|
|
5534
|
+
let primaryFrom = sel.from;
|
|
5535
|
+
let primaryTo = sel.to;
|
|
5536
|
+
if (primaryFrom === primaryTo) {
|
|
5537
|
+
const $head = sel.$head;
|
|
5538
|
+
if ($head.parent.isTextblock) {
|
|
5539
|
+
if (op === "yank") {
|
|
5540
|
+
primaryFrom = $head.start();
|
|
5541
|
+
primaryTo = $head.end();
|
|
5542
|
+
} else {
|
|
5543
|
+
primaryTo = Math.min($head.end(), primaryFrom + Math.max(1, count));
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5547
|
+
if (op === "yank") {
|
|
5548
|
+
const slice = doc.slice(primaryFrom, primaryTo);
|
|
5549
|
+
storage.registerSlice = slice;
|
|
5550
|
+
sharedRegisterSlice = slice;
|
|
5551
|
+
const yankedText = doc.textBetween(primaryFrom, primaryTo, "\n");
|
|
5552
|
+
if (yankedText && typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
5553
|
+
void navigator.clipboard.writeText(yankedText).catch(() => {
|
|
5554
|
+
});
|
|
5555
|
+
}
|
|
5556
|
+
const tr = state.tr.setSelection(TextSelection.create(doc, primaryFrom));
|
|
5557
|
+
dispatchTransaction(editor, tr);
|
|
5558
|
+
return { enterInsert: false, yankedText };
|
|
5559
|
+
}
|
|
5560
|
+
if (op === "delete" || op === "change") {
|
|
5561
|
+
const enforceH1 = options.enforceTitle !== false;
|
|
5562
|
+
const firstChild = doc.firstChild;
|
|
5563
|
+
const hasTitleH1 = enforceH1 && firstChild?.type.name === "heading" && firstChild.attrs.level === 1;
|
|
5564
|
+
const titleEnd = hasTitleH1 ? 1 + firstChild.content.size : -1;
|
|
5565
|
+
const clampRange = (from, to) => {
|
|
5566
|
+
if (hasTitleH1 && from <= titleEnd) {
|
|
5567
|
+
const clampedFrom = Math.max(1, from);
|
|
5568
|
+
const clampedTo = to <= titleEnd + 1 ? Math.min(titleEnd, to) : to;
|
|
5569
|
+
return { from: clampedFrom, to: Math.max(clampedFrom, clampedTo) };
|
|
5570
|
+
}
|
|
5571
|
+
return { from, to };
|
|
5572
|
+
};
|
|
5573
|
+
const primaryClamped = clampRange(primaryFrom, primaryTo);
|
|
5574
|
+
const slice = doc.slice(primaryClamped.from, primaryClamped.to);
|
|
5575
|
+
storage.registerSlice = slice;
|
|
5576
|
+
sharedRegisterSlice = slice;
|
|
5577
|
+
const allRanges = [
|
|
5578
|
+
primaryClamped,
|
|
5579
|
+
...secondaryRanges.map(
|
|
5580
|
+
(r) => clampRange(r.from, r.to > r.from ? r.to : Math.min(doc.content.size, r.from + 1))
|
|
5581
|
+
)
|
|
5582
|
+
].sort((a, b) => b.from - a.from);
|
|
5583
|
+
let tr = state.tr;
|
|
5584
|
+
for (const r of allRanges) {
|
|
5585
|
+
if (r.to > r.from) {
|
|
5586
|
+
tr = tr.delete(r.from, r.to);
|
|
5587
|
+
}
|
|
5588
|
+
}
|
|
5589
|
+
const nextPos = Math.min(tr.doc.content.size, primaryClamped.from);
|
|
5590
|
+
const resolved = Selection.near(tr.doc.resolve(nextPos));
|
|
5591
|
+
tr = tr.setSelection(resolved);
|
|
5592
|
+
const nextMode = op === "change" ? "insert" : storage.mode;
|
|
5593
|
+
storage.mode = nextMode;
|
|
5594
|
+
tr = updateMeta(tr, { mode: nextMode, secondaryRanges: [] });
|
|
5595
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5596
|
+
return { enterInsert: op === "change" };
|
|
5597
|
+
}
|
|
5598
|
+
if (op === "pasteAfter" || op === "pasteBefore") {
|
|
5599
|
+
const slice = storage.registerSlice ?? sharedRegisterSlice;
|
|
5600
|
+
if (!slice || slice.size === 0) return false;
|
|
5601
|
+
let insertPos = op === "pasteAfter" ? sel.to : sel.from;
|
|
5602
|
+
if (op === "pasteAfter" && sel.empty && sel.$head.parent.isTextblock && insertPos < sel.$head.end()) {
|
|
5603
|
+
insertPos += 1;
|
|
5604
|
+
}
|
|
5605
|
+
let tr = state.tr;
|
|
5606
|
+
for (let i = 0; i < Math.max(1, count); i += 1) {
|
|
5607
|
+
tr = tr.replaceRange(insertPos, insertPos, slice);
|
|
5608
|
+
}
|
|
5609
|
+
dispatchTransaction(editor, tr.scrollIntoView());
|
|
5610
|
+
return true;
|
|
5611
|
+
}
|
|
5612
|
+
return false;
|
|
5613
|
+
},
|
|
5614
|
+
setModalState({ mode: nextMode, preset: nextPreset }) {
|
|
5615
|
+
const storage = getStorage();
|
|
5616
|
+
const prev = modalKeymapPluginKey.getState(editor.state);
|
|
5617
|
+
if (storage.mode === nextMode && storage.preset === nextPreset && prev?.mode === nextMode && prev?.preset === nextPreset) {
|
|
5618
|
+
return;
|
|
5619
|
+
}
|
|
5620
|
+
storage.mode = nextMode;
|
|
5621
|
+
storage.preset = nextPreset;
|
|
5622
|
+
if (prev && prev.mode === nextMode && prev.preset === nextPreset && prev.secondaryRanges.length === 0) {
|
|
5623
|
+
return;
|
|
5624
|
+
}
|
|
5625
|
+
try {
|
|
5626
|
+
const tr = updateMeta(editor.state.tr, {
|
|
5627
|
+
mode: nextMode,
|
|
5628
|
+
preset: nextPreset,
|
|
5629
|
+
...nextMode === "insert" ? { secondaryRanges: [] } : {}
|
|
5630
|
+
});
|
|
5631
|
+
dispatchTransaction(editor, tr);
|
|
5632
|
+
} catch {
|
|
5633
|
+
}
|
|
5634
|
+
},
|
|
5635
|
+
hasActiveSuggestion() {
|
|
5636
|
+
const doc = typeof document !== "undefined" ? document : null;
|
|
5637
|
+
if (!doc) return false;
|
|
5638
|
+
const activePopup = doc.querySelector(
|
|
5639
|
+
'[data-slash-menu-surface], [data-mention-menu-surface], [data-editor-slash-menu], [data-editor-mention-menu], .tippy-box[data-state="visible"]'
|
|
5640
|
+
);
|
|
5641
|
+
if (activePopup) return true;
|
|
5642
|
+
let root = doc;
|
|
5643
|
+
try {
|
|
5644
|
+
root = editor.view.dom.parentElement ?? doc;
|
|
5645
|
+
} catch {
|
|
5646
|
+
root = doc;
|
|
5647
|
+
}
|
|
5648
|
+
if (root.querySelector('[role="dialog"]')) return true;
|
|
5649
|
+
const toolbars = Array.from(root.querySelectorAll('[role="toolbar"]'));
|
|
5650
|
+
for (const tb of toolbars) {
|
|
5651
|
+
const style = doc.defaultView?.getComputedStyle(tb);
|
|
5652
|
+
if (style && style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0") {
|
|
5653
|
+
return true;
|
|
5654
|
+
}
|
|
5655
|
+
}
|
|
5656
|
+
return false;
|
|
5657
|
+
}
|
|
5658
|
+
};
|
|
5659
|
+
}
|
|
5660
|
+
var ModalKeymap = Extension3.create({
|
|
5661
|
+
name: "modalKeymap",
|
|
5662
|
+
addOptions() {
|
|
5663
|
+
return {
|
|
5664
|
+
enforceTitle: true
|
|
5665
|
+
};
|
|
5666
|
+
},
|
|
5667
|
+
addStorage() {
|
|
5668
|
+
return {
|
|
5669
|
+
target: null,
|
|
5670
|
+
mode: "insert",
|
|
5671
|
+
preset: "helix",
|
|
5672
|
+
registerSlice: null,
|
|
5673
|
+
cleanupDomRegistration: void 0
|
|
5674
|
+
};
|
|
5675
|
+
},
|
|
5676
|
+
onCreate() {
|
|
5677
|
+
const target = this.storage.target ?? createModalTargetForEditor(this.editor, this.options);
|
|
5678
|
+
this.storage.target = target;
|
|
5679
|
+
try {
|
|
5680
|
+
const dom = this.editor.view.dom;
|
|
5681
|
+
if (typeof HTMLElement !== "undefined" && dom instanceof HTMLElement) {
|
|
5682
|
+
this.storage.cleanupDomRegistration = registerModalEditor(dom, target);
|
|
5683
|
+
}
|
|
5684
|
+
} catch {
|
|
5685
|
+
}
|
|
5686
|
+
},
|
|
5687
|
+
onDestroy() {
|
|
5688
|
+
this.storage.cleanupDomRegistration?.();
|
|
5689
|
+
this.storage.cleanupDomRegistration = void 0;
|
|
5690
|
+
this.storage.target = null;
|
|
5691
|
+
},
|
|
5692
|
+
addProseMirrorPlugins() {
|
|
5693
|
+
const { storage, editor, options } = this;
|
|
5694
|
+
if (!storage.target) {
|
|
5695
|
+
storage.target = createModalTargetForEditor(editor, options);
|
|
5696
|
+
}
|
|
5697
|
+
return [
|
|
5698
|
+
new Plugin2({
|
|
5699
|
+
key: modalKeymapPluginKey,
|
|
5700
|
+
state: {
|
|
5701
|
+
init() {
|
|
5702
|
+
return {
|
|
5703
|
+
mode: storage.mode,
|
|
5704
|
+
preset: storage.preset,
|
|
5705
|
+
secondaryRanges: [],
|
|
5706
|
+
goalColumn: null
|
|
5707
|
+
};
|
|
5708
|
+
},
|
|
5709
|
+
apply(tr, prev) {
|
|
5710
|
+
const meta = tr.getMeta(modalKeymapPluginKey);
|
|
5711
|
+
if (meta) {
|
|
5712
|
+
return {
|
|
5713
|
+
mode: meta.mode ?? prev.mode,
|
|
5714
|
+
preset: meta.preset ?? prev.preset,
|
|
5715
|
+
secondaryRanges: meta.secondaryRanges ?? prev.secondaryRanges,
|
|
5716
|
+
goalColumn: meta.goalColumn !== void 0 ? meta.goalColumn : prev.goalColumn
|
|
5717
|
+
};
|
|
5718
|
+
}
|
|
5719
|
+
if (tr.docChanged && prev.secondaryRanges.length > 0) {
|
|
5720
|
+
return {
|
|
5721
|
+
...prev,
|
|
5722
|
+
secondaryRanges: prev.secondaryRanges.map((r) => ({
|
|
5723
|
+
from: tr.mapping.map(r.from),
|
|
5724
|
+
to: tr.mapping.map(r.to),
|
|
5725
|
+
head: tr.mapping.map(r.head)
|
|
5726
|
+
}))
|
|
5727
|
+
};
|
|
5728
|
+
}
|
|
5729
|
+
return prev;
|
|
5730
|
+
}
|
|
5731
|
+
},
|
|
5732
|
+
view(editorView) {
|
|
5733
|
+
if (typeof HTMLElement !== "undefined" && editorView.dom instanceof HTMLElement && storage.target && !storage.cleanupDomRegistration) {
|
|
5734
|
+
storage.cleanupDomRegistration = registerModalEditor(editorView.dom, storage.target);
|
|
5735
|
+
}
|
|
5736
|
+
return {
|
|
5737
|
+
destroy() {
|
|
5738
|
+
storage.cleanupDomRegistration?.();
|
|
5739
|
+
storage.cleanupDomRegistration = void 0;
|
|
5740
|
+
}
|
|
5741
|
+
};
|
|
5742
|
+
},
|
|
5743
|
+
props: {
|
|
5744
|
+
handleDOMEvents: {
|
|
5745
|
+
mousedown(view) {
|
|
5746
|
+
if (storage.mode !== "insert") {
|
|
5747
|
+
storage.mode = "insert";
|
|
5748
|
+
try {
|
|
5749
|
+
const prev = modalKeymapPluginKey.getState(view.state);
|
|
5750
|
+
if (prev && prev.mode !== "insert") {
|
|
5751
|
+
view.dispatch(
|
|
5752
|
+
view.state.tr.setMeta(modalKeymapPluginKey, {
|
|
5753
|
+
...prev,
|
|
5754
|
+
mode: "insert",
|
|
5755
|
+
secondaryRanges: []
|
|
5756
|
+
})
|
|
5757
|
+
);
|
|
5758
|
+
}
|
|
5759
|
+
} catch {
|
|
5760
|
+
}
|
|
5761
|
+
}
|
|
5762
|
+
return false;
|
|
5763
|
+
}
|
|
5764
|
+
},
|
|
5765
|
+
attributes(state) {
|
|
5766
|
+
const pluginState = modalKeymapPluginKey.getState(state);
|
|
5767
|
+
const currentMode = pluginState?.mode ?? "insert";
|
|
5768
|
+
const currentPreset = pluginState?.preset ?? "helix";
|
|
5769
|
+
return {
|
|
5770
|
+
"data-modal-mode": currentMode,
|
|
5771
|
+
"data-modal-preset": currentPreset
|
|
5772
|
+
};
|
|
5773
|
+
},
|
|
5774
|
+
decorations(state) {
|
|
5775
|
+
const pluginState = modalKeymapPluginKey.getState(state);
|
|
5776
|
+
if (!pluginState || pluginState.mode === "insert") {
|
|
5777
|
+
return DecorationSet.empty;
|
|
5778
|
+
}
|
|
5779
|
+
const decos = [];
|
|
5780
|
+
const { doc, selection } = state;
|
|
5781
|
+
const head = selection.head;
|
|
5782
|
+
const pushCursorDecoration = (pos, isMulti = false) => {
|
|
5783
|
+
if (pos < 0 || pos > doc.content.size) return;
|
|
5784
|
+
const $pos = doc.resolve(pos);
|
|
5785
|
+
const nodeAfter = $pos.nodeAfter;
|
|
5786
|
+
if (nodeAfter?.isText && nodeAfter.text && nodeAfter.text.length > 0 && pos + 1 <= doc.content.size) {
|
|
5787
|
+
decos.push(
|
|
5788
|
+
Decoration.inline(
|
|
5789
|
+
pos,
|
|
5790
|
+
pos + 1,
|
|
5791
|
+
isMulti ? { class: "pm-multi-cursor", "data-pm-multi-cursor": "true" } : { class: "pm-modal-cursor", "data-pm-modal-cursor": pluginState.mode }
|
|
5792
|
+
)
|
|
5793
|
+
);
|
|
5794
|
+
return;
|
|
5795
|
+
}
|
|
5796
|
+
if (typeof document !== "undefined") {
|
|
5797
|
+
decos.push(
|
|
5798
|
+
Decoration.widget(
|
|
5799
|
+
pos,
|
|
5800
|
+
() => {
|
|
5801
|
+
const span = document.createElement("span");
|
|
5802
|
+
span.className = isMulti ? "pm-multi-cursor pm-modal-cursor-eol" : "pm-modal-cursor pm-modal-cursor-eol";
|
|
5803
|
+
span.setAttribute(
|
|
5804
|
+
isMulti ? "data-pm-multi-cursor" : "data-pm-modal-cursor",
|
|
5805
|
+
isMulti ? "true" : pluginState.mode
|
|
5806
|
+
);
|
|
5807
|
+
span.setAttribute("aria-hidden", "true");
|
|
5808
|
+
span.textContent = "\xA0";
|
|
5809
|
+
return span;
|
|
5810
|
+
},
|
|
5811
|
+
{
|
|
5812
|
+
side: 1,
|
|
5813
|
+
key: isMulti ? `multi-cursor-${pos}` : `modal-cursor-${pos}-${pluginState.mode}`
|
|
5814
|
+
}
|
|
5815
|
+
)
|
|
5816
|
+
);
|
|
5817
|
+
}
|
|
5818
|
+
};
|
|
5819
|
+
if (selection.empty) {
|
|
5820
|
+
pushCursorDecoration(head, false);
|
|
5821
|
+
} else if (selection.from < selection.to) {
|
|
5822
|
+
decos.push(
|
|
5823
|
+
Decoration.inline(selection.from, selection.to, {
|
|
5824
|
+
class: "pm-modal-selection",
|
|
5825
|
+
"data-pm-modal-selection": pluginState.mode
|
|
5826
|
+
})
|
|
5827
|
+
);
|
|
5828
|
+
const $head = doc.resolve(head);
|
|
5829
|
+
const cursorPos = selection.head > selection.anchor ? $head.nodeBefore?.isText && head - 1 >= selection.from ? head - 1 : head : head;
|
|
5830
|
+
pushCursorDecoration(cursorPos, false);
|
|
5831
|
+
}
|
|
5832
|
+
for (const range of pluginState.secondaryRanges) {
|
|
5833
|
+
if (range.from >= 0 && range.to <= doc.content.size && range.from < range.to) {
|
|
5834
|
+
decos.push(
|
|
5835
|
+
Decoration.inline(range.from, range.to, {
|
|
5836
|
+
class: "pm-multi-selection",
|
|
5837
|
+
"data-pm-multi-selection": "true"
|
|
5838
|
+
})
|
|
5839
|
+
);
|
|
5840
|
+
} else {
|
|
5841
|
+
pushCursorDecoration(range.head, true);
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
return DecorationSet.create(doc, decos);
|
|
5845
|
+
}
|
|
5846
|
+
}
|
|
5847
|
+
})
|
|
5848
|
+
];
|
|
5849
|
+
}
|
|
5850
|
+
});
|
|
5851
|
+
|
|
5852
|
+
// src/editor/extensions/slash-commands.ts
|
|
1321
5853
|
function registerImageInsertCallback(editor, cb) {
|
|
1322
5854
|
editor.storage.slashCommands.onInsertImage = cb;
|
|
1323
5855
|
}
|
|
@@ -1330,13 +5862,14 @@ function registerYouTubeInsertCallback(editor, cb) {
|
|
|
1330
5862
|
function unregisterYouTubeInsertCallback(editor) {
|
|
1331
5863
|
editor.storage.slashCommands.onInsertYouTube = void 0;
|
|
1332
5864
|
}
|
|
1333
|
-
var slashCommands =
|
|
5865
|
+
var slashCommands = Extension4.create({
|
|
1334
5866
|
name: "slashCommands",
|
|
1335
5867
|
addOptions() {
|
|
1336
5868
|
return {
|
|
1337
5869
|
suggestion: {
|
|
1338
5870
|
char: "/",
|
|
1339
|
-
pluginKey: new
|
|
5871
|
+
pluginKey: new PluginKey3("slashCommands"),
|
|
5872
|
+
allow: ({ editor }) => isEditorInInsertMode(editor),
|
|
1340
5873
|
command: ({
|
|
1341
5874
|
editor,
|
|
1342
5875
|
range,
|
|
@@ -1549,9 +6082,9 @@ var createCodeBlockCustom = (lowlight, nodeView) => CodeBlockLowlight.extend({
|
|
|
1549
6082
|
|
|
1550
6083
|
// src/editor/extensions/image-node.ts
|
|
1551
6084
|
import { Node as Node2 } from "@tiptap/core";
|
|
1552
|
-
import { Plugin as
|
|
1553
|
-
import { DecorationSet, Decoration } from "@tiptap/pm/view";
|
|
1554
|
-
var imageBackspaceKey = new
|
|
6085
|
+
import { Plugin as Plugin3, PluginKey as PluginKey4, NodeSelection as NodeSelection2, TextSelection as TextSelection2 } from "@tiptap/pm/state";
|
|
6086
|
+
import { DecorationSet as DecorationSet2, Decoration as Decoration2 } from "@tiptap/pm/view";
|
|
6087
|
+
var imageBackspaceKey = new PluginKey4("imageBackspace");
|
|
1555
6088
|
var createImageNode = (nodeView) => Node2.create({
|
|
1556
6089
|
name: "imageNode",
|
|
1557
6090
|
group: "block",
|
|
@@ -1601,8 +6134,8 @@ var createImageNode = (nodeView) => Node2.create({
|
|
|
1601
6134
|
},
|
|
1602
6135
|
addProseMirrorPlugins() {
|
|
1603
6136
|
let arrowKeyPressed = false;
|
|
1604
|
-
const captionFocusPlugin = new
|
|
1605
|
-
key: new
|
|
6137
|
+
const captionFocusPlugin = new Plugin3({
|
|
6138
|
+
key: new PluginKey4("imageNodeCaptionFocus"),
|
|
1606
6139
|
props: {
|
|
1607
6140
|
handleKeyDown(_view, event) {
|
|
1608
6141
|
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
@@ -1616,7 +6149,7 @@ var createImageNode = (nodeView) => Node2.create({
|
|
|
1616
6149
|
update(view, prevState) {
|
|
1617
6150
|
const { selection } = view.state;
|
|
1618
6151
|
const { selection: prevSelection } = prevState;
|
|
1619
|
-
const movedOntoImage = arrowKeyPressed && selection instanceof
|
|
6152
|
+
const movedOntoImage = arrowKeyPressed && selection instanceof NodeSelection2 && selection.node.type.name === "imageNode" && !(prevSelection instanceof NodeSelection2 && prevSelection.from === selection.from);
|
|
1620
6153
|
arrowKeyPressed = false;
|
|
1621
6154
|
if (movedOntoImage) {
|
|
1622
6155
|
const pos = selection.from;
|
|
@@ -1626,7 +6159,7 @@ var createImageNode = (nodeView) => Node2.create({
|
|
|
1626
6159
|
if (input) {
|
|
1627
6160
|
const { tr, doc } = view.state;
|
|
1628
6161
|
const $after = doc.resolve(Math.min(pos + nodeSize, doc.content.size));
|
|
1629
|
-
view.dispatch(tr.setSelection(
|
|
6162
|
+
view.dispatch(tr.setSelection(TextSelection2.near($after)));
|
|
1630
6163
|
input.focus({ preventScroll: true });
|
|
1631
6164
|
setTimeout(() => {
|
|
1632
6165
|
const rect = input.getBoundingClientRect();
|
|
@@ -1640,7 +6173,7 @@ var createImageNode = (nodeView) => Node2.create({
|
|
|
1640
6173
|
};
|
|
1641
6174
|
}
|
|
1642
6175
|
});
|
|
1643
|
-
const backspacePlugin = new
|
|
6176
|
+
const backspacePlugin = new Plugin3({
|
|
1644
6177
|
key: imageBackspaceKey,
|
|
1645
6178
|
state: {
|
|
1646
6179
|
init: () => null,
|
|
@@ -1685,8 +6218,8 @@ var createImageNode = (nodeView) => Node2.create({
|
|
|
1685
6218
|
if (pendingPos == null) return null;
|
|
1686
6219
|
const node = state.doc.nodeAt(pendingPos);
|
|
1687
6220
|
if (!node) return null;
|
|
1688
|
-
return
|
|
1689
|
-
|
|
6221
|
+
return DecorationSet2.create(state.doc, [
|
|
6222
|
+
Decoration2.node(pendingPos, pendingPos + node.nodeSize, {
|
|
1690
6223
|
class: "image-node-pending-delete"
|
|
1691
6224
|
})
|
|
1692
6225
|
]);
|
|
@@ -2002,6 +6535,7 @@ var createInternalMention = ({ mentionSource, hrefBuilder, render }) => Mention.
|
|
|
2002
6535
|
suggestion: {
|
|
2003
6536
|
char: "@",
|
|
2004
6537
|
allowSpaces: true,
|
|
6538
|
+
allow: ({ editor }) => isEditorInInsertMode(editor),
|
|
2005
6539
|
command: ({ editor, range, props }) => {
|
|
2006
6540
|
editor.chain().focus().insertContentAt(range, [
|
|
2007
6541
|
{
|
|
@@ -2024,7 +6558,7 @@ var createInternalMention = ({ mentionSource, hrefBuilder, render }) => Mention.
|
|
|
2024
6558
|
|
|
2025
6559
|
// src/editor/extensions/notice-node.ts
|
|
2026
6560
|
import { Node as Node5, mergeAttributes as mergeAttributes4 } from "@tiptap/core";
|
|
2027
|
-
import { Plugin as
|
|
6561
|
+
import { Plugin as Plugin4 } from "@tiptap/pm/state";
|
|
2028
6562
|
var createNoticeNode = (nodeView) => Node5.create({
|
|
2029
6563
|
name: "notice",
|
|
2030
6564
|
group: "block",
|
|
@@ -2061,7 +6595,7 @@ var createNoticeNode = (nodeView) => Node5.create({
|
|
|
2061
6595
|
},
|
|
2062
6596
|
addProseMirrorPlugins() {
|
|
2063
6597
|
return [
|
|
2064
|
-
new
|
|
6598
|
+
new Plugin4({
|
|
2065
6599
|
props: {
|
|
2066
6600
|
handleKeyDown: (view, event) => {
|
|
2067
6601
|
if (event.key !== "ArrowUp") return false;
|
|
@@ -2102,23 +6636,23 @@ var createNoticeNode = (nodeView) => Node5.create({
|
|
|
2102
6636
|
});
|
|
2103
6637
|
|
|
2104
6638
|
// src/editor/extensions/current-empty-block.ts
|
|
2105
|
-
import { Extension as
|
|
2106
|
-
import { Plugin as
|
|
2107
|
-
import { Decoration as
|
|
2108
|
-
var currentEmptyBlockKey = new
|
|
2109
|
-
var CurrentEmptyBlock =
|
|
6639
|
+
import { Extension as Extension5 } from "@tiptap/core";
|
|
6640
|
+
import { Plugin as Plugin5, PluginKey as PluginKey5 } from "@tiptap/pm/state";
|
|
6641
|
+
import { Decoration as Decoration3, DecorationSet as DecorationSet3 } from "@tiptap/pm/view";
|
|
6642
|
+
var currentEmptyBlockKey = new PluginKey5("currentEmptyBlock");
|
|
6643
|
+
var CurrentEmptyBlock = Extension5.create({
|
|
2110
6644
|
name: "currentEmptyBlock",
|
|
2111
6645
|
addProseMirrorPlugins() {
|
|
2112
6646
|
return [
|
|
2113
|
-
new
|
|
6647
|
+
new Plugin5({
|
|
2114
6648
|
key: currentEmptyBlockKey,
|
|
2115
6649
|
props: {
|
|
2116
6650
|
decorations(state) {
|
|
2117
6651
|
const { selection } = state;
|
|
2118
6652
|
const { $from } = selection;
|
|
2119
6653
|
if (!selection.empty || $from.depth === 0 || $from.parent.content.size > 0) return null;
|
|
2120
|
-
return
|
|
2121
|
-
|
|
6654
|
+
return DecorationSet3.create(state.doc, [
|
|
6655
|
+
Decoration3.node($from.before($from.depth), $from.after($from.depth), {
|
|
2122
6656
|
class: "is-current-empty"
|
|
2123
6657
|
})
|
|
2124
6658
|
]);
|
|
@@ -2185,7 +6719,8 @@ function buildExtensions(options) {
|
|
|
2185
6719
|
createLinkPreview(nodeViews.linkPreview),
|
|
2186
6720
|
createImageNode(nodeViews.image),
|
|
2187
6721
|
createUrlMention(nodeViews.urlMention),
|
|
2188
|
-
slashCommands.configure({ suggestion: { render: slashRender ?? (() => ({})) } })
|
|
6722
|
+
slashCommands.configure({ suggestion: { render: slashRender ?? (() => ({})) } }),
|
|
6723
|
+
ModalKeymap.configure({ enforceTitle })
|
|
2189
6724
|
];
|
|
2190
6725
|
}
|
|
2191
6726
|
|
|
@@ -2243,9 +6778,12 @@ function lockEditorOverlayScroll(editorElement, overlayElement) {
|
|
|
2243
6778
|
return () => container.removeEventListener("wheel", preventWheel);
|
|
2244
6779
|
}
|
|
2245
6780
|
export {
|
|
6781
|
+
DEFAULT_JUMP_ALPHABET,
|
|
2246
6782
|
EditorHeading,
|
|
2247
6783
|
ExitHeading,
|
|
2248
6784
|
HeadingWithId,
|
|
6785
|
+
Jumplist,
|
|
6786
|
+
ModalKeymap,
|
|
2249
6787
|
SIDEBAR_KEYBOARD_SHORTCUT,
|
|
2250
6788
|
SIDEBAR_WIDGET_DEFAULT_SNAP_POINT,
|
|
2251
6789
|
SIDEBAR_WIDGET_SNAP_POINTS,
|
|
@@ -2258,6 +6796,7 @@ export {
|
|
|
2258
6796
|
badgeVariants,
|
|
2259
6797
|
buildChartDefinition,
|
|
2260
6798
|
buildExtensions,
|
|
6799
|
+
buildWhichKeyTree,
|
|
2261
6800
|
buttonVariants,
|
|
2262
6801
|
cardBodyBase,
|
|
2263
6802
|
cardCoverVariants,
|
|
@@ -2302,11 +6841,16 @@ export {
|
|
|
2302
6841
|
comboboxTriggerBase,
|
|
2303
6842
|
containerBase,
|
|
2304
6843
|
createCodeBlockCustom,
|
|
6844
|
+
createHelixPreset,
|
|
2305
6845
|
createImageNode,
|
|
2306
6846
|
createInternalMention,
|
|
6847
|
+
createJumplist,
|
|
6848
|
+
createKakounePreset,
|
|
2307
6849
|
createLinkPreview,
|
|
2308
6850
|
createNoticeNode,
|
|
2309
6851
|
createUrlMention,
|
|
6852
|
+
createVimPreset,
|
|
6853
|
+
createWhichKeyController,
|
|
2310
6854
|
defaultChartColor,
|
|
2311
6855
|
defaultListboxFilter,
|
|
2312
6856
|
dialogBackdropBase,
|
|
@@ -2320,6 +6864,7 @@ export {
|
|
|
2320
6864
|
dialogHeaderStickyBase,
|
|
2321
6865
|
dialogPositionerBase,
|
|
2322
6866
|
dialogTitleBase,
|
|
6867
|
+
eventToChordKeys,
|
|
2323
6868
|
extractYouTubeId,
|
|
2324
6869
|
feedbackCorrectBase,
|
|
2325
6870
|
feedbackExplanationBase,
|
|
@@ -2337,13 +6882,30 @@ export {
|
|
|
2337
6882
|
figureCaptionBase,
|
|
2338
6883
|
figureImageBase,
|
|
2339
6884
|
figureRootBase,
|
|
6885
|
+
findDirectionalPane,
|
|
2340
6886
|
findEditorScrollContainer,
|
|
6887
|
+
flattenKeymapEntries,
|
|
6888
|
+
formatKeyChord,
|
|
6889
|
+
formatKeySequence,
|
|
2341
6890
|
formatTime,
|
|
6891
|
+
generateJumpLabels,
|
|
6892
|
+
getDocumentWhichKeyController,
|
|
6893
|
+
getEditorModalTarget,
|
|
6894
|
+
getModalEditor,
|
|
6895
|
+
getNodeChildren,
|
|
6896
|
+
getPresetKeymap,
|
|
2342
6897
|
hstackBase,
|
|
2343
6898
|
injectCodeBlockStyles,
|
|
2344
6899
|
inputVariants,
|
|
2345
6900
|
insertPastedUrlAsLink,
|
|
6901
|
+
isEditorInInsertMode,
|
|
6902
|
+
isGroupNode,
|
|
2346
6903
|
itemVariants,
|
|
6904
|
+
jumpBadgeMatchedPrefixBase,
|
|
6905
|
+
jumpBadgeVariants,
|
|
6906
|
+
jumpOverlayRootBase,
|
|
6907
|
+
kbdGroupBase,
|
|
6908
|
+
kbdVariants,
|
|
2347
6909
|
latexDisplayBase,
|
|
2348
6910
|
latexErrorBase,
|
|
2349
6911
|
latexInlineBase,
|
|
@@ -2352,6 +6914,8 @@ export {
|
|
|
2352
6914
|
listboxEmptyBase,
|
|
2353
6915
|
listboxInputBase,
|
|
2354
6916
|
listboxItemBase,
|
|
6917
|
+
listboxItemGroupBase,
|
|
6918
|
+
listboxItemGroupLabelBase,
|
|
2355
6919
|
listboxItemIndicatorBase,
|
|
2356
6920
|
listboxItemTextBase,
|
|
2357
6921
|
listboxLabelBase,
|
|
@@ -2368,6 +6932,7 @@ export {
|
|
|
2368
6932
|
mermaidSourceBase,
|
|
2369
6933
|
mermaidSvgAspectRatio,
|
|
2370
6934
|
mermaidSvgBase,
|
|
6935
|
+
modalKeymapPluginKey,
|
|
2371
6936
|
nativeSelectIconBase,
|
|
2372
6937
|
nativeSelectVariants,
|
|
2373
6938
|
nativeSelectWrapperBase,
|
|
@@ -2397,9 +6962,12 @@ export {
|
|
|
2397
6962
|
navbarShrunkBase,
|
|
2398
6963
|
navbarTriggerVariants,
|
|
2399
6964
|
navbarVariants,
|
|
6965
|
+
nodeMatchesMode,
|
|
6966
|
+
normalizeNodeModes,
|
|
2400
6967
|
noticeDescriptionBase,
|
|
2401
6968
|
noticeTitleBase,
|
|
2402
6969
|
noticeVariants,
|
|
6970
|
+
notifyAllModalEditors,
|
|
2403
6971
|
numberInputControlBase,
|
|
2404
6972
|
numberInputInputBase,
|
|
2405
6973
|
numberInputRootBase,
|
|
@@ -2415,6 +6983,7 @@ export {
|
|
|
2415
6983
|
paginationItemBase,
|
|
2416
6984
|
paginationRootBase,
|
|
2417
6985
|
paginationTriggerBase,
|
|
6986
|
+
paneVariants,
|
|
2418
6987
|
parseYouTubeChapters,
|
|
2419
6988
|
placeEditorOverlay,
|
|
2420
6989
|
placeEditorOverlayAt,
|
|
@@ -2454,11 +7023,13 @@ export {
|
|
|
2454
7023
|
radioGroupItemTextBase,
|
|
2455
7024
|
radioGroupRootBase,
|
|
2456
7025
|
registerImageInsertCallback,
|
|
7026
|
+
registerModalEditor,
|
|
2457
7027
|
registerYouTubeInsertCallback,
|
|
2458
7028
|
renderChartSvgString,
|
|
2459
7029
|
renderCodeToHtml,
|
|
2460
7030
|
renderMermaidSource,
|
|
2461
7031
|
resolveMermaidThemeVariables,
|
|
7032
|
+
resolveNode,
|
|
2462
7033
|
revealChevronBase,
|
|
2463
7034
|
revealContentBase,
|
|
2464
7035
|
revealRootBase,
|
|
@@ -2489,6 +7060,7 @@ export {
|
|
|
2489
7060
|
splitterResizeTriggerSeparatorBase,
|
|
2490
7061
|
splitterRootBase,
|
|
2491
7062
|
stackBase,
|
|
7063
|
+
subscribeDocumentWhichKeyController,
|
|
2492
7064
|
switchControlBase,
|
|
2493
7065
|
switchLabelBase,
|
|
2494
7066
|
switchThumbBase,
|
|
@@ -2518,6 +7090,22 @@ export {
|
|
|
2518
7090
|
unregisterImageInsertCallback,
|
|
2519
7091
|
unregisterYouTubeInsertCallback,
|
|
2520
7092
|
vstackBase,
|
|
7093
|
+
whichKeyBodyVariants,
|
|
7094
|
+
whichKeyBreadcrumbBase,
|
|
7095
|
+
whichKeyExplorerContentBase,
|
|
7096
|
+
whichKeyExplorerHeaderBase,
|
|
7097
|
+
whichKeyExplorerHighlightMarkBase,
|
|
7098
|
+
whichKeyExplorerInputBase,
|
|
7099
|
+
whichKeyExplorerItemBase,
|
|
7100
|
+
whichKeyExplorerListContentBase,
|
|
7101
|
+
whichKeyExplorerListboxBase,
|
|
7102
|
+
whichKeyFooterBase,
|
|
7103
|
+
whichKeyHeaderBase,
|
|
7104
|
+
whichKeyItemBase,
|
|
7105
|
+
whichKeyItemLabelBase,
|
|
7106
|
+
whichKeyModeBadgeVariants,
|
|
7107
|
+
whichKeyTitleBase,
|
|
7108
|
+
whichKeyVariants,
|
|
2521
7109
|
windowBodyBase,
|
|
2522
7110
|
windowCloseTriggerBase,
|
|
2523
7111
|
windowContentBase,
|