office-core 0.1.1 → 0.1.2
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.
|
@@ -124,16 +124,37 @@ function findCmd(name) {
|
|
|
124
124
|
let _menuLines = 0;
|
|
125
125
|
let _menuSelection = 0;
|
|
126
126
|
let _menuScrollOffset = 0;
|
|
127
|
+
let _menuQuery = "";
|
|
127
128
|
const MAX_VISIBLE_SLASH_ITEMS = 6;
|
|
128
129
|
function getSlashMatches(partial) {
|
|
129
130
|
const q = partial.toLowerCase();
|
|
130
131
|
return CMDS.filter((c) => c.name.startsWith(q) || c.alias?.some((a) => a.startsWith(q)));
|
|
131
132
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
133
|
+
function eraseSlashMenu() {
|
|
134
|
+
if (_menuLines === 0)
|
|
135
|
+
return;
|
|
136
|
+
process.stdout.write(`\x1b[s\n`);
|
|
137
|
+
clearScreenDown(process.stdout);
|
|
138
|
+
process.stdout.write(`\x1b[u`);
|
|
139
|
+
_menuLines = 0;
|
|
140
|
+
}
|
|
141
|
+
function resetSlashMenuState() {
|
|
142
|
+
_menuSelection = 0;
|
|
143
|
+
_menuScrollOffset = 0;
|
|
144
|
+
_menuQuery = "";
|
|
145
|
+
}
|
|
146
|
+
function renderSlashMenu(partial, preserveSelection = false) {
|
|
147
|
+
eraseSlashMenu();
|
|
148
|
+
if (!preserveSelection || partial !== _menuQuery) {
|
|
149
|
+
_menuSelection = 0;
|
|
150
|
+
_menuScrollOffset = 0;
|
|
151
|
+
}
|
|
152
|
+
_menuQuery = partial;
|
|
134
153
|
const hits = getSlashMatches(partial);
|
|
135
|
-
if (hits.length === 0)
|
|
154
|
+
if (hits.length === 0) {
|
|
155
|
+
resetSlashMenuState();
|
|
136
156
|
return;
|
|
157
|
+
}
|
|
137
158
|
_menuSelection = Math.max(0, Math.min(_menuSelection, hits.length - 1));
|
|
138
159
|
if (_menuSelection < _menuScrollOffset) {
|
|
139
160
|
_menuScrollOffset = _menuSelection;
|
|
@@ -167,14 +188,8 @@ function renderSlashMenu(partial) {
|
|
|
167
188
|
_menuLines = lines.length;
|
|
168
189
|
}
|
|
169
190
|
function clearSlashMenu() {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
process.stdout.write(`\x1b[s\n`);
|
|
173
|
-
clearScreenDown(process.stdout);
|
|
174
|
-
process.stdout.write(`\x1b[u`);
|
|
175
|
-
_menuLines = 0;
|
|
176
|
-
_menuSelection = 0;
|
|
177
|
-
_menuScrollOffset = 0;
|
|
191
|
+
eraseSlashMenu();
|
|
192
|
+
resetSlashMenuState();
|
|
178
193
|
}
|
|
179
194
|
// ─── Tab Completer ──────────────────────────────────────────────────────────
|
|
180
195
|
function completer(line) {
|
|
@@ -608,16 +623,16 @@ async function main() {
|
|
|
608
623
|
key.name === "up"
|
|
609
624
|
? (_menuSelection + hits.length - 1) % hits.length
|
|
610
625
|
: (_menuSelection + 1) % hits.length;
|
|
611
|
-
renderSlashMenu(line.slice(1));
|
|
626
|
+
renderSlashMenu(line.slice(1), true);
|
|
612
627
|
return;
|
|
613
628
|
}
|
|
614
629
|
if (hits.length > 0 && key?.name === "tab") {
|
|
615
630
|
const selected = hits[_menuSelection] ?? hits[0];
|
|
616
631
|
replaceInputLine(rl, `/${selected.name} `);
|
|
617
|
-
renderSlashMenu(selected.name);
|
|
632
|
+
renderSlashMenu(selected.name, false);
|
|
618
633
|
return;
|
|
619
634
|
}
|
|
620
|
-
renderSlashMenu(line.slice(1));
|
|
635
|
+
renderSlashMenu(line.slice(1), false);
|
|
621
636
|
}
|
|
622
637
|
else {
|
|
623
638
|
clearSlashMenu();
|