Skip to content

refactor(frontend): extract useQuickTemplates from TerminalView.vue - #326

Merged
attson merged 1 commit into
mainfrom
refactor/extract-quick-templates
Aug 4, 2026
Merged

refactor(frontend): extract useQuickTemplates from TerminalView.vue#326
attson merged 1 commit into
mainfrom
refactor/extract-quick-templates

Conversation

@attson

@attson attson commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Second slice of milestone 5-b. Templates state (list + hidden flag + pending-confirm) and every function that manipulates them (`sendTemplate`, `requestTemplateSend`, `confirmTemplateSend`, `cancelTemplateSend`, `onTemplateHotkey`, `onTemplateBarWheel`) plus the `parseHotkey`/`hotkeyMatches` internals were interleaved with the rest of TerminalView.vue's setup.

Move to `composables/useQuickTemplates.ts`. The composable takes:
```ts
{ send, confirmRequired, focused, templatesBridge }
```
where `send` is the closure that wraps `conn?.sendInput` so the composable stays session-transport agnostic — critical because that's where the two-writes-per-template split lives.

⚠️ HARD CONSTRAINT preserved inline in `sendTemplate`

```ts
send(tpl.text);
window.setTimeout(() => send("\r"), 16);
```

This must NOT be "simplified" into a single `sendInput` call — Codex and other raw-mode TUIs treat bundled `"text\r"` as a paste (the CR becomes a literal newline in the prompt instead of submitting). Regressed twice before: fixed in #63, deleted in #110, re-fixed in #129. Documented in memory as `[[feedback_template_send_split_cr]]`.

TerminalView side

  • Drop `templates` / `templatesHidden` / `pendingTemplateConfirm` refs (moved).
  • Drop `templateConfirmOpen` computed (composable exports it).
  • Drop `templateConfirmRequired` computed (passed in as `confirmRequired` arg).
  • Drop `sendTemplate` / `requestTemplateSend` / `cancelTemplateSend` / `confirmTemplateSend` / `onTemplateHotkey` / `onTemplateBarWheel` functions.
  • Drop `parseHotkey` + `hotkeyMatches` helpers (private to composable now).
  • Drop `effectiveTemplates` import (consumed by composable).
  • Add `useQuickTemplates` destructure + composable import.
  • `reloadShortcutBars` simplifies: delegates templates to `reloadQuickTemplates()` and reloads aux keys inline (aux keys stay here until M5-b-5 extracts TerminalAuxKeyBar).

Test update

Two source-scan tests in `TerminalView.test.ts` that pinned the exact old inline structure now also scan `useQuickTemplates.ts?raw` for the moved parts. Regex tweaked to match the composable's 2-space-indented nested-function closing braces.

Net: TerminalView.vue -110 / +21 (net -89, 2724 → 2635); new composable +181.

Test plan

  • `npm test` 1631/1631
  • `npm run build` (vue-tsc + vite) green
  • Manual (desktop): tap a template button in the mobile shortcut bar → text + Enter sent as two writes (Codex prompt submits, not pastes)
  • Manual (web): first tap opens confirm panel; second tap sends
  • Manual: template hotkey (e.g. Mod+1) fires on the focused pane only

Second slice of milestone 5-b. Templates state (list + hidden flag +
pending-confirm) and every function that manipulates them
(sendTemplate, requestTemplateSend, confirmTemplateSend, cancelTemplateSend,
onTemplateHotkey, onTemplateBarWheel) plus the parseHotkey/hotkeyMatches
internals were interleaved with the rest of TerminalView.vue's setup.

Move to composables/useQuickTemplates.ts. The composable takes:
  { send, confirmRequired, focused, templatesBridge }
where `send` is the closure that wraps `conn?.sendInput` so the
composable stays session-transport agnostic — critical because that's
where the two-writes-per-template split lives.

⚠️  HARD CONSTRAINT preserved inline in sendTemplate:
   send(tpl.text);
   window.setTimeout(() => send("\r"), 16);
This must NOT be "simplified" into a single sendInput call — Codex and
other raw-mode TUIs treat bundled "text\r" as a paste (the CR becomes a
literal newline in the prompt instead of submitting). Regressed twice
before: fixed in #63, deleted in #110, re-fixed in #129. Documented in
memory as [[feedback_template_send_split_cr]].

TerminalView side:
- Drop templates / templatesHidden / pendingTemplateConfirm refs (moved).
- Drop templateConfirmOpen computed (composable exports it).
- Drop templateConfirmRequired computed (passed in as confirmRequired arg).
- Drop sendTemplate / requestTemplateSend / cancelTemplateSend /
  confirmTemplateSend / onTemplateHotkey / onTemplateBarWheel functions.
- Drop parseHotkey + hotkeyMatches helpers (private to composable now).
- Drop effectiveTemplates import (consumed by composable).
- Add useQuickTemplates destructure + composable import.
- reloadShortcutBars simplifies: delegates templates to
  reloadQuickTemplates() and reloads aux keys inline (aux keys stay
  here until M5-b-5 extracts TerminalAuxKeyBar).

Test update: two source-scan tests in TerminalView.test.ts that pinned
the exact old inline structure now also scan
useQuickTemplates.ts?raw for the moved parts. Regex tweaked to match
the composable's 2-space-indented nested-function closing braces.

Net: TerminalView.vue -110 / +21 (net -89, 2724 → 2635); new composable
+181. `npm test` 1631/1631; `npm run build` green.
@attson
attson force-pushed the refactor/extract-quick-templates branch from 1dd20dd to b9e33d6 Compare August 4, 2026 15:15
@attson
attson merged commit 2980255 into main Aug 4, 2026
7 checks passed
@attson
attson deleted the refactor/extract-quick-templates branch August 4, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant