pi-cc-extensions 0.5.2 → 0.5.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.
@@ -321,7 +321,7 @@ let toolMouseTui: any = null;
321
321
  let toolMouseUi: any = null;
322
322
  let toolMouseInputUnsubscribe: (() => void) | null = null;
323
323
  let toolMouseInputPatchTui: any = null;
324
- let toolMouseInputPatchOriginalAdd: ((...args: any[]) => any) | null = null;
324
+ let toolMouseInputPatchOriginalHandle: ((...args: any[]) => any) | null = null;
325
325
  let toolMouseInputPatchWrapper: ((...args: any[]) => any) | null = null;
326
326
 
327
327
  function parseSgrMousePackets(data: string): SgrMousePacket[] | null {
@@ -445,56 +445,51 @@ function toggleToolAtMouseClick(tui: any, packet: SgrMousePacket): boolean {
445
445
  }
446
446
 
447
447
  /**
448
- * Pi TUI input listeners are ordered by registration. pi-zentui's fixed editor
449
- * consumes left-button presses for selection, so a later click listener never
450
- * sees tool rows. Keep this handler first while still returning undefined for
451
- * scroll/selection events so pi-zentui remains the owner of those interactions.
448
+ * pi-zentui consumes left-button presses for text selection. Intercept only a
449
+ * tool-row click at the TUI input boundary, before extension listeners run.
450
+ * Keyboard, wheel, drag, release, and non-tool clicks continue through Pi's
451
+ * original dispatcher, preserving pi-zentui's scroll-to-bottom behavior.
452
452
  */
453
- function prioritizeToolMouseInput(tui: any): void {
454
- const listeners = tui?.inputListeners;
455
- if (!(listeners instanceof Set) || !listeners.has(handleToolMouseInput)) return;
456
-
457
- const ordered = Array.from(listeners);
458
- if (ordered[0] === handleToolMouseInput) return;
459
- listeners.clear();
460
- listeners.add(handleToolMouseInput);
461
- for (const listener of ordered) {
462
- if (listener !== handleToolMouseInput) listeners.add(listener);
463
- }
464
- }
465
-
466
- function patchToolMouseInputPriority(tui: any): void {
467
- if (toolMouseInputPatchTui === tui) {
468
- prioritizeToolMouseInput(tui);
469
- return;
470
- }
453
+ function patchToolMouseInputCapture(tui: any): void {
454
+ if (toolMouseInputPatchTui === tui) return;
471
455
 
472
- restoreToolMouseInputPriority();
473
- const originalAdd = tui?.addInputListener;
474
- if (typeof originalAdd !== "function") return;
456
+ restoreToolMouseInputCapture();
457
+ const originalHandle = tui?.handleInput;
458
+ if (typeof originalHandle !== "function") return;
475
459
 
476
460
  const wrapper = function (this: any, ...args: any[]): any {
477
- const result = Reflect.apply(originalAdd, this, args);
478
- prioritizeToolMouseInput(this);
479
- return result;
461
+ const data = args[0];
462
+ if (typeof data === "string") {
463
+ const packets = parseSgrMousePackets(data);
464
+ if (packets) {
465
+ for (const packet of packets) {
466
+ if (isSgrLeftPress(packet) && toggleToolAtMouseClick(this, packet)) return;
467
+ }
468
+ }
469
+ }
470
+ return Reflect.apply(originalHandle, this, args);
480
471
  };
481
- tui.addInputListener = wrapper;
472
+
473
+ try {
474
+ tui.handleInput = wrapper;
475
+ } catch {
476
+ return;
477
+ }
482
478
  toolMouseInputPatchTui = tui;
483
- toolMouseInputPatchOriginalAdd = originalAdd;
479
+ toolMouseInputPatchOriginalHandle = originalHandle;
484
480
  toolMouseInputPatchWrapper = wrapper;
485
- prioritizeToolMouseInput(tui);
486
481
  }
487
482
 
488
- function restoreToolMouseInputPriority(): void {
483
+ function restoreToolMouseInputCapture(): void {
489
484
  if (
490
485
  toolMouseInputPatchTui
491
- && toolMouseInputPatchOriginalAdd
492
- && toolMouseInputPatchTui.addInputListener === toolMouseInputPatchWrapper
486
+ && toolMouseInputPatchOriginalHandle
487
+ && toolMouseInputPatchTui.handleInput === toolMouseInputPatchWrapper
493
488
  ) {
494
- toolMouseInputPatchTui.addInputListener = toolMouseInputPatchOriginalAdd;
489
+ toolMouseInputPatchTui.handleInput = toolMouseInputPatchOriginalHandle;
495
490
  }
496
491
  toolMouseInputPatchTui = null;
497
- toolMouseInputPatchOriginalAdd = null;
492
+ toolMouseInputPatchOriginalHandle = null;
498
493
  toolMouseInputPatchWrapper = null;
499
494
  }
500
495
 
@@ -528,7 +523,7 @@ function teardownToolMouseInteraction(): void {
528
523
  } catch {
529
524
  // The UI context may already have been reset during /reload.
530
525
  }
531
- restoreToolMouseInputPriority();
526
+ restoreToolMouseInputCapture();
532
527
  toolMouseTui = null;
533
528
  toolMouseUi = null;
534
529
  }
@@ -541,7 +536,7 @@ function installToolMouseInteraction(ctx: any): void {
541
536
  toolMouseUi = ctx.ui;
542
537
  ctx.ui.setWidget(TOOL_MOUSE_WIDGET_KEY, (tui: any) => {
543
538
  toolMouseTui = tui;
544
- patchToolMouseInputPriority(tui);
539
+ patchToolMouseInputCapture(tui);
545
540
  tui?.terminal?.write?.(TOOL_MOUSE_ENABLE);
546
541
  // Keep the widget visually empty so Pi's default input bar/layout remains.
547
542
  return { render: () => [], invalidate() {} };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cc-extensions",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Personal extensions for the Pi coding agent",
5
5
  "type": "module",
6
6
  "keywords": [