openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

[deep-review][duplication] D1: CopyTextToClipboard duplicated across 17 sites

Open codemonkeychris opened this issue 6 months ago • 2 comments

Summary

Two byte-identical CopyTextToClipboard methods plus 15 other sites that inline the same new DataPackage(); SetText; SetContent ritual. Total: 17 call sites doing the same three operations.

Where

  • src/OpenClaw.Tray.WinUI/App.xaml.cs:4395 — CopyTextToClipboard (one of two byte-identical implementations)
  • src/OpenClaw.Tray.WinUI/Dialogs/QuickSendDialog.cs:344 — CopyTextToClipboard (the other byte-identical implementation)
  • 15 other call sites where the three-line pattern new DataPackage(), .SetText(...), Clipboard.SetContent(...) is inlined directly. Easiest find: grep -rn "Clipboard.SetContent" src/.

PR #336 (refactor/extract-copy-diagnostic-helper) already established a sibling seam — CopyDiagnosticHelper — for the redacted-diagnostic copy operations. The same seam can absorb plain text copy.

Why it matters

  • Three-line patterns are exactly where AI-assisted edits introduce subtle behavior differences. E.g., one site forgets try { } catch (COMException) { } to guard against the clipboard being held by another process; another adds it. Drift accumulates.
  • New developers can't find the canonical helper because there isn't one.

Proposed fix

Extend the helper introduced in PR #336:

public static class ClipboardHelper
{
    public static void CopyText(string text);          // existing pattern
    public static void CopyDiagnostic(string text);    // already exists from #336
}

Migrate all 17 sites in one PR. Delete the two CopyTextToClipboard methods.

Severity

Low (cosmetic) — but a fast win that demonstrates the pattern for the larger refactors.

codemonkeychris avatar May 14 '26 00:05 codemonkeychris

🤖 This is an automated response from Repo Assist.

I've opened a draft PR that removes the two CopyTextToClipboard wrapper methods and points all 7 call sites directly to ClipboardHelper.CopyText.

ClipboardHelper.CopyText was already the canonical helper — both wrappers were thin delegates that did nothing but forward to it. The PR deletes them and updates:

  • App.xaml.cs — 4 internal calls + method definition removed
  • QuickSendDialog.cs — 2 calls + method definition removed
  • Onboarding/Pages/ConnectionPage.cs — 1 call updated from App.CopyTextToClipboard to ClipboardHelper.CopyText

No behaviour change.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

github-actions[bot] avatar May 16 '26 01:05 github-actions[bot]

Closing during the post-refactor deep-review cleanup. Clipboard duplication is much smaller in the current tree and is consolidated into #372 as a scoped cleanup item. This keeps the signal while reducing stale one-off issue noise.

shanselman avatar May 18 '26 00:05 shanselman