@senad-d/micme 0.3.6 → 0.3.7
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/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/editor.ts +115 -62
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ All notable changes to Micme will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
-
- Preserve Pi's built-in keyboard shortcuts by installing Micme's editor fallback only
|
|
7
|
+
- Preserve Pi's built-in keyboard shortcuts by installing Micme's editor fallback only for printable-character shortcuts and retaining the `CustomEditor` app-handler contract when wrapping another extension's editor.
|
|
8
8
|
- Move normal Micme persistence to the global `~/.pi/agent/micme.json` store; shell environment variables still override saved settings.
|
|
9
9
|
- Update `/micme conf`, `micme-doctor`, docs, and package examples for the new global JSON config path.
|
|
10
10
|
- Document the scoped npm package name, `@senad-d/micme`, in install, diagnostics, update, and uninstall commands.
|
package/package.json
CHANGED
package/src/editor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomEditor, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type AutocompleteProvider, decodeKittyPrintable } from "@earendil-works/pi-tui";
|
|
1
|
+
import { type AppKeybinding, CustomEditor, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type AutocompleteProvider, decodeKittyPrintable, type EditorComponent } from "@earendil-works/pi-tui";
|
|
3
3
|
import { getPrintableShortcuts, matchesPrintableMicmeShortcut } from "./config.ts";
|
|
4
4
|
|
|
5
5
|
type CustomEditorArgs = ConstructorParameters<typeof CustomEditor>;
|
|
@@ -12,6 +12,14 @@ export type MicmeEditorInputHandlers = {
|
|
|
12
12
|
toggle: () => Promise<void> | void;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
type AppAwareEditor = EditorComponent & {
|
|
16
|
+
actionHandlers: Map<AppKeybinding, () => void>;
|
|
17
|
+
onEscape?: () => void;
|
|
18
|
+
onCtrlD?: () => void;
|
|
19
|
+
onPasteImage?: () => void;
|
|
20
|
+
onExtensionShortcut?: (data: string) => boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
15
23
|
class MicmeEditor extends CustomEditor {
|
|
16
24
|
private readonly micmeHandlers: MicmeEditorInputHandlers;
|
|
17
25
|
|
|
@@ -26,6 +34,110 @@ class MicmeEditor extends CustomEditor {
|
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
// Pi wires app handlers only onto the outer editor returned by the active factory.
|
|
38
|
+
// Keep that identity while delegating editing behavior to the previously installed editor.
|
|
39
|
+
class WrappedMicmeEditor extends CustomEditor {
|
|
40
|
+
readonly wantsKeyRelease?: boolean;
|
|
41
|
+
private readonly base: EditorComponent;
|
|
42
|
+
private readonly baseAppEditor: AppAwareEditor | undefined;
|
|
43
|
+
private readonly micmeHandlers: MicmeEditorInputHandlers;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
tui: CustomEditorArgs[0],
|
|
47
|
+
theme: CustomEditorArgs[1],
|
|
48
|
+
keybindings: CustomEditorArgs[2],
|
|
49
|
+
base: EditorComponent,
|
|
50
|
+
micmeHandlers: MicmeEditorInputHandlers,
|
|
51
|
+
) {
|
|
52
|
+
super(tui, theme, keybindings);
|
|
53
|
+
this.base = base;
|
|
54
|
+
this.baseAppEditor = getAppAwareEditor(base);
|
|
55
|
+
this.micmeHandlers = micmeHandlers;
|
|
56
|
+
this.wantsKeyRelease = base.wantsKeyRelease;
|
|
57
|
+
this.focused = "focused" in base && Boolean(base.focused);
|
|
58
|
+
this.onSubmit = base.onSubmit;
|
|
59
|
+
this.onChange = base.onChange;
|
|
60
|
+
if (base.borderColor !== undefined) this.borderColor = base.borderColor;
|
|
61
|
+
if (this.baseAppEditor) this.adoptBaseAppHandlers(this.baseAppEditor);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override render(width: number): string[] {
|
|
65
|
+
this.syncBaseEditor();
|
|
66
|
+
return this.base.render(width);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override invalidate(): void {
|
|
70
|
+
this.syncBaseEditor();
|
|
71
|
+
this.base.invalidate();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override getText(): string {
|
|
75
|
+
return this.base.getText();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override setText(text: string): void {
|
|
79
|
+
this.syncBaseEditor();
|
|
80
|
+
this.base.setText(text);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override getExpandedText(): string {
|
|
84
|
+
return this.base.getExpandedText?.() ?? this.base.getText();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
override addToHistory(text: string): void {
|
|
88
|
+
this.base.addToHistory?.(text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override insertTextAtCursor(text: string): void {
|
|
92
|
+
this.syncBaseEditor();
|
|
93
|
+
this.base.insertTextAtCursor?.(text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override setAutocompleteProvider(provider: AutocompleteProvider): void {
|
|
97
|
+
this.base.setAutocompleteProvider?.(provider);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override setPaddingX(padding: number): void {
|
|
101
|
+
this.base.setPaddingX?.(padding);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override setAutocompleteMaxVisible(maxVisible: number): void {
|
|
105
|
+
this.base.setAutocompleteMaxVisible?.(maxVisible);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
override handleInput(data: string): void {
|
|
109
|
+
if (handleMicmeEditorInput(data, this.micmeHandlers)) return;
|
|
110
|
+
this.syncBaseEditor();
|
|
111
|
+
this.base.handleInput(data);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private adoptBaseAppHandlers(base: AppAwareEditor): void {
|
|
115
|
+
// Sharing the map makes Pi's later handler copy immediately visible to the wrapped CustomEditor.
|
|
116
|
+
this.actionHandlers = base.actionHandlers;
|
|
117
|
+
this.onEscape = base.onEscape;
|
|
118
|
+
this.onCtrlD = base.onCtrlD;
|
|
119
|
+
this.onPasteImage = base.onPasteImage;
|
|
120
|
+
this.onExtensionShortcut = base.onExtensionShortcut;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private syncBaseEditor(): void {
|
|
124
|
+
if ("focused" in this.base) this.base.focused = this.focused;
|
|
125
|
+
this.base.onSubmit = this.onSubmit;
|
|
126
|
+
this.base.onChange = this.onChange;
|
|
127
|
+
this.base.borderColor = this.borderColor;
|
|
128
|
+
if (!this.baseAppEditor) return;
|
|
129
|
+
this.baseAppEditor.onEscape = this.onEscape;
|
|
130
|
+
this.baseAppEditor.onCtrlD = this.onCtrlD;
|
|
131
|
+
this.baseAppEditor.onPasteImage = this.onPasteImage;
|
|
132
|
+
this.baseAppEditor.onExtensionShortcut = this.onExtensionShortcut;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getAppAwareEditor(editor: EditorComponent): AppAwareEditor | undefined {
|
|
137
|
+
if (!("actionHandlers" in editor) || !(editor.actionHandlers instanceof Map)) return undefined;
|
|
138
|
+
return editor as AppAwareEditor;
|
|
139
|
+
}
|
|
140
|
+
|
|
29
141
|
function handleMicmeEditorInput(data: string, handlers: MicmeEditorInputHandlers) {
|
|
30
142
|
const printable = decodeKittyPrintable(data);
|
|
31
143
|
let printableShortcut: string | undefined;
|
|
@@ -57,66 +169,7 @@ export function installMicmeEditorFallback(ctx: ExtensionContext, micmeHandlers:
|
|
|
57
169
|
if (previousEditor) {
|
|
58
170
|
ctx.ui.setEditorComponent((tui, theme, keybindings) => {
|
|
59
171
|
const base = previousEditor(tui, theme, keybindings);
|
|
60
|
-
return
|
|
61
|
-
get focused(): boolean {
|
|
62
|
-
return Boolean((base as { focused?: boolean }).focused);
|
|
63
|
-
},
|
|
64
|
-
set focused(value: boolean) {
|
|
65
|
-
if ("focused" in base) (base as { focused?: boolean }).focused = value;
|
|
66
|
-
},
|
|
67
|
-
get onSubmit(): ((text: string) => void) | undefined {
|
|
68
|
-
return base.onSubmit;
|
|
69
|
-
},
|
|
70
|
-
set onSubmit(handler: ((text: string) => void) | undefined) {
|
|
71
|
-
base.onSubmit = handler;
|
|
72
|
-
},
|
|
73
|
-
get onChange(): ((text: string) => void) | undefined {
|
|
74
|
-
return base.onChange;
|
|
75
|
-
},
|
|
76
|
-
set onChange(handler: ((text: string) => void) | undefined) {
|
|
77
|
-
base.onChange = handler;
|
|
78
|
-
},
|
|
79
|
-
get borderColor(): ((str: string) => string) | undefined {
|
|
80
|
-
return base.borderColor;
|
|
81
|
-
},
|
|
82
|
-
set borderColor(handler: ((str: string) => string) | undefined) {
|
|
83
|
-
base.borderColor = handler;
|
|
84
|
-
},
|
|
85
|
-
render(width: number) {
|
|
86
|
-
return base.render(width);
|
|
87
|
-
},
|
|
88
|
-
invalidate() {
|
|
89
|
-
base.invalidate();
|
|
90
|
-
},
|
|
91
|
-
getText() {
|
|
92
|
-
return base.getText();
|
|
93
|
-
},
|
|
94
|
-
setText(text: string) {
|
|
95
|
-
base.setText(text);
|
|
96
|
-
},
|
|
97
|
-
getExpandedText() {
|
|
98
|
-
return base.getExpandedText?.() ?? base.getText();
|
|
99
|
-
},
|
|
100
|
-
addToHistory(text: string) {
|
|
101
|
-
base.addToHistory?.(text);
|
|
102
|
-
},
|
|
103
|
-
insertTextAtCursor(text: string) {
|
|
104
|
-
base.insertTextAtCursor?.(text);
|
|
105
|
-
},
|
|
106
|
-
setAutocompleteProvider(provider: AutocompleteProvider) {
|
|
107
|
-
base.setAutocompleteProvider?.(provider);
|
|
108
|
-
},
|
|
109
|
-
setPaddingX(padding: number) {
|
|
110
|
-
base.setPaddingX?.(padding);
|
|
111
|
-
},
|
|
112
|
-
setAutocompleteMaxVisible(maxVisible: number) {
|
|
113
|
-
base.setAutocompleteMaxVisible?.(maxVisible);
|
|
114
|
-
},
|
|
115
|
-
handleInput(data: string) {
|
|
116
|
-
if (handleMicmeEditorInput(data, micmeHandlers)) return;
|
|
117
|
-
base.handleInput(data);
|
|
118
|
-
},
|
|
119
|
-
};
|
|
172
|
+
return new WrappedMicmeEditor(tui, theme, keybindings, base, micmeHandlers);
|
|
120
173
|
});
|
|
121
174
|
return;
|
|
122
175
|
}
|