pi-ui-extend 0.1.27 → 0.1.28

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.
@@ -11,6 +11,8 @@ export function setFileLinkOpenerTestDeps(overrides) {
11
11
  };
12
12
  }
13
13
  export function openFileLink(link) {
14
+ if (isWebUrl(link.url))
15
+ return openPathWithSystemViewer(link.url);
14
16
  const filePath = link.filePath ?? filePathFromUrl(link.url);
15
17
  if (!filePath)
16
18
  return false;
@@ -19,6 +21,9 @@ export function openFileLink(link) {
19
21
  return true;
20
22
  return openPathWithSystemViewer(filePath);
21
23
  }
24
+ function isWebUrl(url) {
25
+ return url.startsWith("http://") || url.startsWith("https://");
26
+ }
22
27
  function filePathFromUrl(url) {
23
28
  if (!url.startsWith("file://"))
24
29
  return undefined;
@@ -3,10 +3,11 @@ import { homedir } from "node:os";
3
3
  import { isAbsolute, resolve } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  const FILE_PATH_CANDIDATE = /(?<![\p{L}\p{N}_:])((?:file:\/\/\/|~[\\/]|\.{1,2}[\\/]|[A-Za-z]:[\\/]|[\\/]|[A-Za-z0-9_.@-]+[\\/])[^\s"'`<>]*)/gu;
6
+ const WEB_URL_CANDIDATE = /https?:\/\/[^\s"'`<>]+/gu;
6
7
  const TRAILING_PUNCTUATION = new Set([".", ",", ";", ")", "]", "}"]);
7
8
  export function detectFileLinks(text, cwd) {
8
9
  const links = [];
9
- if (!text.includes("/") && !text.includes("\\"))
10
+ if (!text.includes("/") && !text.includes("\\") && !text.includes("http://") && !text.includes("https://"))
10
11
  return links;
11
12
  for (const match of text.matchAll(FILE_PATH_CANDIDATE)) {
12
13
  const raw = match[1];
@@ -28,6 +29,17 @@ export function detectFileLinks(text, cwd) {
28
29
  column: location.column,
29
30
  });
30
31
  }
32
+ for (const match of text.matchAll(WEB_URL_CANDIDATE)) {
33
+ const raw = match[0];
34
+ const candidate = trimTrailingPunctuation(raw);
35
+ if (!candidate)
36
+ continue;
37
+ links.push({
38
+ start: match.index,
39
+ end: match.index + candidate.length,
40
+ url: candidate,
41
+ });
42
+ }
31
43
  return mergeOverlappingLinks(links);
32
44
  }
33
45
  export function hyperlink(text, url) {
@@ -139,6 +139,7 @@ export declare class AppMouseController {
139
139
  private inputClickFlashRegionForEvent;
140
140
  private imageTargetAt;
141
141
  private fileLinkAt;
142
+ private fileLinkTargetAt;
142
143
  private statusTargetAt;
143
144
  private handleImageClick;
144
145
  private handleFileLinkClick;
@@ -60,6 +60,8 @@ export class AppMouseController {
60
60
  this.showClickFlashOnPress(event);
61
61
  if (event.button === 0 && !event.released && this.handleInputBorderStatusClick(event))
62
62
  return;
63
+ if (event.button === 0 && !event.released && this.fileLinkAt(event))
64
+ return;
63
65
  if (this.handleMouseSelection(event))
64
66
  return;
65
67
  if (this.withClickFlash(event, () => this.handleImageClick(event)))
@@ -234,9 +236,9 @@ export class AppMouseController {
234
236
  const imageTarget = this.imageTargetAt(event);
235
237
  if (imageTarget)
236
238
  return { y: event.y, startColumn: imageTarget.start + 1, endColumn: imageTarget.end + 1 };
237
- const link = this.fileLinkAt(event);
238
- if (link)
239
- return { y: event.y, startColumn: link.start + 1, endColumn: link.end + 1 };
239
+ const linkTarget = this.fileLinkTargetAt(event);
240
+ if (linkTarget)
241
+ return { y: event.y, startColumn: linkTarget.startColumn, endColumn: linkTarget.endColumn };
240
242
  const tabTarget = this.tabLineTargetAt(event);
241
243
  if (tabTarget)
242
244
  return { y: tabTarget.row, startColumn: tabTarget.startColumn, endColumn: tabTarget.endColumn };
@@ -290,10 +292,19 @@ export class AppMouseController {
290
292
  return targets?.find((candidate) => event.x >= candidate.start + 1 && event.x <= candidate.end);
291
293
  }
292
294
  fileLinkAt(event) {
295
+ return this.fileLinkTargetAt(event)?.link;
296
+ }
297
+ fileLinkTargetAt(event) {
293
298
  const text = this.renderedRowTexts.get(event.y);
294
299
  if (!text)
295
300
  return undefined;
296
- return detectFileLinks(text, this.host.cwd()).find((candidate) => event.x >= candidate.start + 1 && event.x <= candidate.end);
301
+ for (const link of detectFileLinks(text, this.host.cwd())) {
302
+ const startColumn = stringDisplayWidth(text.slice(0, link.start)) + 1;
303
+ const endColumn = startColumn + stringDisplayWidth(text.slice(link.start, link.end));
304
+ if (event.x >= startColumn && event.x < endColumn)
305
+ return { link, startColumn, endColumn };
306
+ }
307
+ return undefined;
297
308
  }
298
309
  statusTargetAt(event) {
299
310
  const target = [
@@ -323,7 +334,7 @@ export class AppMouseController {
323
334
  };
324
335
  }
325
336
  handleImageClick(event) {
326
- if (event.button !== 0 || !event.released)
337
+ if (!isPrimaryButtonRelease(event))
327
338
  return false;
328
339
  const imageTarget = this.imageTargetAt(event);
329
340
  if (!imageTarget)
@@ -341,7 +352,7 @@ export class AppMouseController {
341
352
  }
342
353
  handleFileLinkClick(event) {
343
354
  const modifiedPress = isModifiedPrimaryButton(event.button) && !event.released;
344
- const plainRelease = event.button === 0 && event.released;
355
+ const plainRelease = isPrimaryButtonRelease(event);
345
356
  if (!modifiedPress && !plainRelease)
346
357
  return false;
347
358
  const link = this.fileLinkAt(event);
@@ -1053,6 +1064,9 @@ function isModifiedPrimaryButton(button) {
1053
1064
  const modifierBits = button & (8 | 16);
1054
1065
  return primaryButton && modifierBits !== 0;
1055
1066
  }
1067
+ function isPrimaryButtonRelease(event) {
1068
+ return event.released && (event.button === 0 || (event.button & 3) === 3);
1069
+ }
1056
1070
  function editorLayoutRows(terminalRows, tabPanelRows) {
1057
1071
  return Math.max(1, terminalRows - tabPanelRows);
1058
1072
  }
@@ -70,6 +70,10 @@ export function firstUserMessageText(ctx: ExtensionContext): string | undefined
70
70
  return undefined;
71
71
  }
72
72
 
73
+ function hasExistingUserMessage(ctx: ExtensionContext): boolean {
74
+ return firstUserMessageText(ctx) !== undefined;
75
+ }
76
+
73
77
  export function fallbackSessionTitleFromInput(input: string, maxTitleChars: number): string | undefined {
74
78
  const normalized = input
75
79
  .replace(/[\t\r\n]+/gu, " ")
@@ -371,24 +375,6 @@ export default function sessionTitle(pi: ExtensionAPI) {
371
375
  })();
372
376
  }
373
377
 
374
- function primeTitleGenerationFromExistingSession(ctx: ExtensionContext, currentConfig: SessionTitleConfig): void {
375
- if (currentSessionName(ctx)) return;
376
-
377
- const input = firstUserMessageText(ctx);
378
- if (!input) return;
379
- if (!currentConfig.enabled) {
380
- applyFallbackSessionTitle(ctx, currentConfig, input);
381
- return;
382
- }
383
-
384
- pendingGeneration = {
385
- sessionId: ctx.sessionManager.getSessionId(),
386
- input: truncateInput(input, currentConfig.maxInputChars),
387
- attempts: 0,
388
- };
389
- startTitleGeneration(ctx, currentConfig);
390
- }
391
-
392
378
  function isSameSessionPath(left: string | undefined, right: string | undefined): boolean {
393
379
  if (!left || !right) return false;
394
380
  if (left === right) return true;
@@ -447,7 +433,6 @@ export default function sessionTitle(pi: ExtensionAPI) {
447
433
  await prepareForkTitleState(event, ctx);
448
434
  refreshSessionUi(ctx, { force: true });
449
435
  scheduleSessionUiRefresh(ctx);
450
- if (!forkTitleState) primeTitleGenerationFromExistingSession(ctx, config);
451
436
  });
452
437
 
453
438
  pi.on("session_shutdown", async () => {
@@ -480,6 +465,10 @@ export default function sessionTitle(pi: ExtensionAPI) {
480
465
  sessionId = currentSessionId;
481
466
  const currentName = currentSessionName(ctx);
482
467
  const activeForkTitleState = forkTitleState?.sessionId === currentSessionId ? forkTitleState : undefined;
468
+ if (!activeForkTitleState && hasExistingUserMessage(ctx)) {
469
+ forkTitleState = undefined;
470
+ return { action: "continue" as const };
471
+ }
483
472
  if (currentName && (!activeForkTitleState || currentName !== activeForkTitleState.inheritedSessionName)) {
484
473
  forkTitleState = undefined;
485
474
  return { action: "continue" as const };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ui-extend",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {