@xynogen/pix-pretty 1.5.0 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, FFF search, and paste chip formatting",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { describe, expect, it } from "bun:test";
10
10
  import { visibleWidth } from "@earendil-works/pi-tui";
11
- import { restyleMarkers } from "./paste-chips";
11
+ import { endsWithMarker, restyleMarkers } from "./paste-chips";
12
12
 
13
13
  const stripAnsi = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
14
14
 
@@ -132,3 +132,31 @@ describe("paste-chips width safety", () => {
132
132
  });
133
133
  });
134
134
  });
135
+
136
+ // ─── endsWithMarker (trailing-space gate) ──────────────────────────────
137
+
138
+ describe("paste-chips endsWithMarker", () => {
139
+ it("matches a chars marker at end of string", () => {
140
+ expect(endsWithMarker("[paste #1 2232 chars]")).toBe(true);
141
+ });
142
+
143
+ it("matches a lines marker at end of string", () => {
144
+ expect(endsWithMarker("hello [paste #2 +42 lines]")).toBe(true);
145
+ });
146
+
147
+ it("matches a bare marker at end of string", () => {
148
+ expect(endsWithMarker("[paste #3]")).toBe(true);
149
+ });
150
+
151
+ it("does not match when marker is not at the end", () => {
152
+ expect(endsWithMarker("[paste #1 58 chars] trailing")).toBe(false);
153
+ });
154
+
155
+ it("does not match plain text", () => {
156
+ expect(endsWithMarker("just some text")).toBe(false);
157
+ });
158
+
159
+ it("does not match a lone trailing space", () => {
160
+ expect(endsWithMarker(" ")).toBe(false);
161
+ });
162
+ });
@@ -134,6 +134,11 @@ function chip(
134
134
  return `${color}${BOLD}${icon} ${label}${RST}${FG_DIM} ${meta}${RST}`;
135
135
  }
136
136
 
137
+ /** True when `text` ends with a Pi paste marker (chip), e.g. `[paste #1 58 chars]`. */
138
+ export function endsWithMarker(text: string): boolean {
139
+ return /\[paste #\d+[^\]]*\]$/.test(text);
140
+ }
141
+
137
142
  function compactNumber(raw: string): string {
138
143
  const n = Number.parseInt(raw, 10);
139
144
  if (!Number.isFinite(n)) return raw;
@@ -144,16 +149,42 @@ function compactNumber(raw: string): string {
144
149
 
145
150
  // ─── Custom editor ────────────────────────────────────────────────────────────
146
151
 
152
+ // handlePaste is TS-private in CustomEditor but runtime-public JS. We patch it
153
+ // per-instance, capturing the base implementation, so large text pastes get the
154
+ // same trailing-space treatment as image chips.
155
+ type PasteHandler = { handlePaste(text: string): void };
156
+
147
157
  class ChipEditor extends CustomEditor {
148
158
  private readonly imageIds = new Set<number>();
149
159
 
160
+ constructor(...args: ConstructorParameters<typeof CustomEditor>) {
161
+ super(...args);
162
+ this.patchHandlePaste();
163
+ }
164
+
150
165
  override insertTextAtCursor(text: string): void {
151
166
  const internals = this as unknown as EditorInternals;
152
167
  const replaced = replaceImagePaths(text, internals, this.imageIds);
153
168
  // Append a trailing space when the insertion ends with a paste marker so
154
169
  // the cursor lands after the chip rather than inside it.
155
- const needsSpace = /\[paste #\d+[^\]]*\]$/.test(replaced);
156
- super.insertTextAtCursor(needsSpace ? `${replaced} ` : replaced);
170
+ super.insertTextAtCursor(
171
+ endsWithMarker(replaced) ? `${replaced} ` : replaced,
172
+ );
173
+ }
174
+
175
+ private patchHandlePaste(): void {
176
+ const self = this as unknown as PasteHandler;
177
+ const base = self.handlePaste.bind(self);
178
+ self.handlePaste = (pastedText: string) => {
179
+ const before = this.getText();
180
+ base(pastedText);
181
+ const after = this.getText();
182
+ // Only nudge a space when the paste collapsed into a marker chip;
183
+ // inline small pastes (no marker) are left untouched.
184
+ if (endsWithMarker(after) && after !== before) {
185
+ super.insertTextAtCursor(" ");
186
+ }
187
+ };
157
188
  }
158
189
 
159
190
  override render(width: number): string[] {