@xynogen/pix-display 0.1.11 → 0.1.12
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/package.json +1 -1
- package/src/paste-chips.ts +37 -4
package/package.json
CHANGED
package/src/paste-chips.ts
CHANGED
|
@@ -149,11 +149,20 @@ export function replaceImagePaths(
|
|
|
149
149
|
*
|
|
150
150
|
* Width-preserving is not required — Pi re-wraps each render call.
|
|
151
151
|
*/
|
|
152
|
+
// A `[...]` span that starts with `paste #` and may carry interleaved cursor
|
|
153
|
+
// SGR codes (e.g. `[paste #1 \x1b[7m5\x1b[0m8 chars]`). We strip ANSI from the
|
|
154
|
+
// matched span only, never the whole line, so the editor cursor's own
|
|
155
|
+
// inverse-video block outside any marker survives.
|
|
156
|
+
const MARKER_SPAN_RE =
|
|
157
|
+
/(?:\x1b\[[0-9;]*m)*\[(?:\x1b\[[0-9;]*m)*paste #(?:[^\]]|\x1b\[[0-9;]*m)*\]/g;
|
|
158
|
+
|
|
152
159
|
export function restyleMarkers(line: string, imageIds: Set<number>): string {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
return line.replace(MARKER_SPAN_RE, (span) => {
|
|
161
|
+
const clean = span.includes("\x1b") ? span.replace(CURSOR_RE, "") : span;
|
|
162
|
+
MARKER_RE.lastIndex = 0;
|
|
163
|
+
const m = MARKER_RE.exec(clean);
|
|
164
|
+
if (!m?.[1]) return span;
|
|
165
|
+
const [, idStr, , , linesStr, charsStr] = m;
|
|
157
166
|
const id = Number.parseInt(idStr, 10);
|
|
158
167
|
if (imageIds.has(id)) {
|
|
159
168
|
return chip(FG_BLUE, icon("paste.image"), "image", `#${id}`);
|
|
@@ -191,6 +200,18 @@ function compactNumber(raw: string): string {
|
|
|
191
200
|
// per-instance, capturing the base implementation, so large text pastes get the
|
|
192
201
|
// same trailing-space treatment as image chips.
|
|
193
202
|
type PasteHandler = { handlePaste(text: string): void };
|
|
203
|
+
type SubmitHandler = { submitValue(): void };
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Drop image classifications when Pi resets its paste IDs after a submit.
|
|
207
|
+
*
|
|
208
|
+
* The base editor clears `pastes` and resets `pasteCounter` to zero, so IDs are
|
|
209
|
+
* reused in the next prompt. Keeping the old IDs would make a later text paste
|
|
210
|
+
* with the same ID render as an image chip.
|
|
211
|
+
*/
|
|
212
|
+
export function clearImageIdsAfterSubmit(imageIds: Set<number>): void {
|
|
213
|
+
imageIds.clear();
|
|
214
|
+
}
|
|
194
215
|
|
|
195
216
|
class ChipEditor extends CustomEditor {
|
|
196
217
|
private readonly imageIds = new Set<number>();
|
|
@@ -199,6 +220,7 @@ class ChipEditor extends CustomEditor {
|
|
|
199
220
|
super(...args);
|
|
200
221
|
this.patchHandlePaste();
|
|
201
222
|
this.patchExpandPasteMarkers();
|
|
223
|
+
this.patchSubmitValue();
|
|
202
224
|
}
|
|
203
225
|
|
|
204
226
|
override insertTextAtCursor(text: string): void {
|
|
@@ -237,6 +259,17 @@ class ChipEditor extends CustomEditor {
|
|
|
237
259
|
};
|
|
238
260
|
}
|
|
239
261
|
|
|
262
|
+
private patchSubmitValue(): void {
|
|
263
|
+
const self = this as unknown as SubmitHandler;
|
|
264
|
+
const base = self.submitValue.bind(self);
|
|
265
|
+
self.submitValue = () => {
|
|
266
|
+
// Pi resets pasteCounter to zero in submitValue. Clear the parallel
|
|
267
|
+
// image-ID registry in the same operation before those IDs get reused.
|
|
268
|
+
clearImageIdsAfterSubmit(this.imageIds);
|
|
269
|
+
base();
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
240
273
|
override render(width: number): string[] {
|
|
241
274
|
const raw = super.render(width);
|
|
242
275
|
return raw.map((line) => {
|