@jerryan/pi-hashline-edit 0.8.1 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jerryan/pi-hashline-edit",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Fork of pi-hashline-edit with trimmed schema, unified diff, and extra safety guardrails.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/edit.ts CHANGED
@@ -196,65 +196,19 @@ function getRenderablePreviewInput(args: unknown): EditRequestParams | null {
196
196
  return request.edits.length > 0 ? request : null;
197
197
  }
198
198
 
199
- function colorDiffLine(
200
- line: string,
201
- theme: { fg: (token: string, text: string) => string },
202
- ): string {
203
- const prefix = line[0];
204
- if (prefix !== "-" && prefix !== "+" && prefix !== " ") {
205
- return theme.fg("dim", line);
206
- }
207
- if (line.startsWith("---") || line.startsWith("+++")) {
208
- return theme.fg("dim", line);
209
- }
210
-
211
- const sepIdx = line.indexOf(CONTENT_SEP);
212
- if (sepIdx === -1) {
213
- if (prefix === "-") return theme.fg("error", line);
214
- if (prefix === "+") return theme.fg("success", line);
215
- return theme.fg("dim", line);
216
- }
217
-
218
- const meta = line.slice(0, sepIdx); // prefix + lineNum + anchor/pad
219
- const content = line.slice(sepIdx + CONTENT_SEP.length);
220
-
221
- const digits = meta.match(/\d+/);
222
- if (!digits) {
223
- if (prefix === "-") return theme.fg("error", line);
224
- if (prefix === "+") return theme.fg("success", line);
225
- return theme.fg("dim", line);
226
- }
227
-
228
- const lineNumStart = meta.indexOf(digits[0]);
229
- const lineNumEnd = lineNumStart + digits[0].length;
230
- const prefixAndLineNum = meta.slice(0, lineNumEnd);
231
- const anchorAndSep = meta.slice(lineNumEnd) + CONTENT_SEP;
232
-
233
- if (prefix === "-") {
234
- return (
235
- theme.fg("error", prefixAndLineNum) +
236
- theme.fg("muted", anchorAndSep) +
237
- theme.fg("error", content)
238
- );
239
- }
240
- if (prefix === "+") {
241
- return (
242
- theme.fg("success", prefixAndLineNum) +
243
- theme.fg("muted", anchorAndSep) +
244
- theme.fg("success", content)
245
- );
246
- }
247
- return (
248
- theme.fg("dim", prefixAndLineNum) +
249
- theme.fg("muted", anchorAndSep) +
250
- theme.fg("dim", content)
251
- );
252
- }
253
199
  function colorDiffLines(
254
200
  lines: string[],
255
201
  theme: { fg: (token: string, text: string) => string },
256
202
  ): string[] {
257
- return lines.map((line) => colorDiffLine(line, theme));
203
+ return lines.map((line) => {
204
+ if (line.startsWith("+") && !line.startsWith("+++")) {
205
+ return theme.fg("success", line);
206
+ }
207
+ if (line.startsWith("-") && !line.startsWith("---")) {
208
+ return theme.fg("error", line);
209
+ }
210
+ return theme.fg("dim", line);
211
+ });
258
212
  }
259
213
  function formatPreviewDiff(
260
214
  diff: string,
@@ -263,7 +217,7 @@ function formatPreviewDiff(
263
217
  ): string {
264
218
  const lines = diff.split("\n");
265
219
  const maxLines = expanded ? 40 : 16;
266
- const shown = lines.slice(0, maxLines).map((line) => colorDiffLine(line, theme));
220
+ const shown = colorDiffLines(lines.slice(0, maxLines), theme);
267
221
 
268
222
  if (lines.length > maxLines) {
269
223
  shown.push(theme.fg("muted", `... ${lines.length - maxLines} more diff lines`));
@@ -275,7 +229,7 @@ function formatResultDiff(
275
229
  diff: string,
276
230
  theme: { fg: (token: string, text: string) => string },
277
231
  ): string {
278
- return diff.split("\n").map((line) => colorDiffLine(line, theme)).join("\n");
232
+ return colorDiffLines(diff.split("\n"), theme).join("\n");
279
233
  }
280
234
  function getRenderedEditTextContent(
281
235
  result: { content?: Array<{ type: string; text?: string }> },
@@ -1,4 +1,4 @@
1
1
  export const PACKAGE_INFO = {
2
2
  name: "@jerryan/pi-hashline-edit",
3
- version: "0.8.1",
3
+ version: "0.8.2",
4
4
  };