@saifymatteo/pi-cell-actions 0.1.1 → 0.1.3

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 CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.3] - 2026-11-30
6
+
7
+ ### Fixed
8
+
9
+ - A code block whose first or last line wraps in the transcript gets its copy and run menu again; long one-line commands at some terminal widths fell back to the surrounding paragraph's text copy.
10
+
11
+ ## [0.1.2] - 2026-11-27
12
+
13
+ ### Changed
14
+
15
+ - Builds and typechecks against Pi 1.6.1 host types (read-only `render()` lines and related type changes); no behaviour change.
16
+
5
17
  ## [0.1.1] - 2026-11-27
6
18
 
7
19
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saifymatteo/pi-cell-actions",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "Hover a transcript cell for a ⋯ menu: copy messages, code, tables (Markdown/TSV/CSV) and tool calls; run shell blocks",
6
6
  "engines": {
package/src/cells.ts CHANGED
@@ -98,6 +98,24 @@ function isFenceBorder(text: string, lang: string): boolean {
98
98
  return t.startsWith("```") || t.startsWith("~~~") || /─{3,}/.test(t) || (lang !== "" && t === lang);
99
99
  }
100
100
 
101
+ /**
102
+ * First row at or after `from` where `needle` starts, and the row where it ends, matching
103
+ * across row breaks with whitespace removed: renderers wrap long code lines at any column.
104
+ */
105
+ function findAcrossRows(rows: string[], needle: string, from: number): { start: number; end: number } | undefined {
106
+ const target = needle.replace(/\s/g, "");
107
+ if (!target) return undefined;
108
+ let joined = "";
109
+ const rowAt: number[] = [];
110
+ for (let i = from; i < rows.length; i++) {
111
+ const text = rows[i].replace(/\s/g, "");
112
+ joined += text;
113
+ for (let k = 0; k < text.length; k++) rowAt.push(i);
114
+ }
115
+ const at = joined.indexOf(target);
116
+ return at === -1 ? undefined : { start: rowAt[at], end: rowAt[at + target.length - 1] };
117
+ }
118
+
101
119
  /**
102
120
  * Map source blocks to the rows a renderer drew them on, by content: renderers
103
121
  * differ (stock fences, shaded blocks, pi-codeblock-borders rules and gutters),
@@ -126,10 +144,16 @@ export function locateBlocks(rows: string[], blocks: SourceBlock[]): LocatedBloc
126
144
  const lastIndex = codeLines.findLastIndex((line) => line.trim() !== "");
127
145
  const head = codeLines[firstIndex].trim().slice(0, 40);
128
146
  const tail = codeLines[lastIndex].trim().slice(-30);
129
- const start = rows.findIndex((row, i) => i >= cursor && row.includes(head));
130
- if (start === -1) continue;
131
- const end = rows.findIndex((row, i) => i >= start + (lastIndex - firstIndex) && row.includes(tail));
132
- if (end === -1) continue;
147
+ let start = rows.findIndex((row, i) => i >= cursor && row.includes(head));
148
+ let end = start === -1 ? -1 : rows.findIndex((row, i) => i >= start + (lastIndex - firstIndex) && row.includes(tail));
149
+ if (end === -1) {
150
+ // A wrap split the head or tail across rows; match without whitespace instead.
151
+ const first = findAcrossRows(rows, head, cursor);
152
+ const last = first && findAcrossRows(rows, tail, first.start);
153
+ if (!first || !last) continue;
154
+ start = first.start;
155
+ end = Math.max(last.end, first.end);
156
+ }
133
157
  const top = start > 0 && isFenceBorder(rows[start - 1], block.lang) ? start - 1 : start;
134
158
  const bottom = end + 1 < rows.length && isFenceBorder(rows[end + 1], block.lang) ? end + 1 : end;
135
159
  located.push({ ...block, top, bottom });
package/src/index.ts CHANGED
@@ -85,7 +85,7 @@ export default function (pi: ExtensionAPI) {
85
85
  let sawCell = false;
86
86
  let toolHover: ToolHover | undefined;
87
87
  const restores: (() => void)[] = [];
88
- const layoutCache = new WeakMap<object, { width: number; lines: string[]; text: string; blocks: LocatedBlock[] }>();
88
+ const layoutCache = new WeakMap<object, { width: number; lines: readonly string[]; text: string; blocks: LocatedBlock[] }>();
89
89
 
90
90
  const options: OverlayOptions = { row: 0, col: 0, width: 3, nonCapturing: true, visible: () => !!hovered && !suppressed };
91
91
  let buttons: { start: number; end: number; action: Action }[] = [];
@@ -174,7 +174,7 @@ export default function (pi: ExtensionAPI) {
174
174
  }
175
175
 
176
176
  /** The first non-blank row from `top`, so the badge sits on the cell's text, not its padding. */
177
- function firstText(lines: string[], top: number): number {
177
+ function firstText(lines: readonly string[], top: number): number {
178
178
  let row = top;
179
179
  while (row < lines.length - 1 && !stripTerminalSequences(lines[row] ?? "").trim()) row++;
180
180
  return row;