Skip to content

feat: auto-submit username form on paste#50

Closed
cernymatej wants to merge 1 commit intoMatteoGabriele:mainfrom
cernymatej:feat/auto-submit-on-paste
Closed

feat: auto-submit username form on paste#50
cernymatej wants to merge 1 commit intoMatteoGabriele:mainfrom
cernymatej:feat/auto-submit-on-paste

Conversation

@cernymatej
Copy link
Copy Markdown

@cernymatej cernymatej commented Apr 17, 2026

This will auto-submit the form when users pase input form their clipboard.

Summary by CodeRabbit

  • New Features
    • Added paste event handling to the analysis form, allowing users to paste values directly into the input field for automatic submission.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 17, 2026

Deploy Preview for agentscan ready!

Name Link
🔨 Latest commit 50a8476
🔍 Latest deploy log https://app.netlify.com/projects/agentscan/deploys/69e2224b55abc10008ad21f7
😎 Deploy Preview https://deploy-preview-50--agentscan.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

A new usePaste Vue composable was introduced to handle clipboard paste events on DOM elements. The Form component was updated to integrate this composable, enabling submission when content is pasted into the input field, with the pasted value normalized to lowercase.

Changes

Cohort / File(s) Summary
Paste Event Handling
app/composables/usePaste.ts
New composable that registers paste event listeners, extracts clipboard text, and invokes a callback with the pasted string and event context. Includes dev-only warning when clipboard interface is unavailable.
Form Submission Integration
app/components/Analysis/Form.vue
Refactored submission logic into a submit() helper that validates and normalizes input to lowercase. Integrated usePaste composable to trigger submission when content is pasted into the input field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A paste event hops into view,
Text from clipboard, fresh and new,
Lowercase letters spring and dance,
Form submissions get their chance!
Happy hopping through the code,
Down this well-crafted paste-event road! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: auto-submit username form on paste' clearly and concisely summarizes the main change: adding auto-submission functionality to a username form when users paste content.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/composables/usePaste.ts (1)

10-10: Drop the window.clipboardData legacy fallback.

window.clipboardData is an IE-only API. This app targets modern browsers (Nuxt 3 + Vue 3), where event.clipboardData is always present on a ClipboardEvent. The fallback adds a typeof event.clipboardData cast that obscures types and a dead-code branch that will never trigger, making the dev-only warning effectively unreachable too.

♻️ Suggested simplification
-    const clipboard = (event.clipboardData || ("clipboardData" in window && window.clipboardData)) as typeof event.clipboardData;
-    if (!clipboard) {
-      if (import.meta.dev) {
-        console.warn("[usePaste] Clipboard API not supported in this browser.");
-      }
-      return;
-    }
-    const pasted = clipboard.getData("text");
+    const pasted = event.clipboardData?.getData("text") ?? "";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/composables/usePaste.ts` at line 10, Remove the legacy IE fallback and
cast: replace the clipboard assignment that uses (event.clipboardData ||
("clipboardData" in window && window.clipboardData)) with a direct use of
event.clipboardData in usePaste.ts; update any type assertions so clipboard is
typed as event.clipboardData's type (or let TypeScript infer it), and remove the
now-dead branch and any dev-only warning code that depended on
window.clipboardData being checked.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/components/Analysis/Form.vue`:
- Around line 28-30: The paste handler wired via usePaste should trim the pasted
text and sync it into the form model before calling submit: when the paste
callback receives pasted, trim it (e.g., const value = pasted.trim()), write
that trimmed value back into the input element (inputRef.value.value = value)
and into the reactive model (accountName = value) and then call submit(value);
also update submit() itself to trim its incoming value so typed input benefits
from the same empty/whitespace guard; adjust references to usePaste, inputRef,
accountName, and submit accordingly.

---

Nitpick comments:
In `@app/composables/usePaste.ts`:
- Line 10: Remove the legacy IE fallback and cast: replace the clipboard
assignment that uses (event.clipboardData || ("clipboardData" in window &&
window.clipboardData)) with a direct use of event.clipboardData in usePaste.ts;
update any type assertions so clipboard is typed as event.clipboardData's type
(or let TypeScript infer it), and remove the now-dead branch and any dev-only
warning code that depended on window.clipboardData being checked.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 529dc9cd-c244-471d-8723-3c33b947e08b

📥 Commits

Reviewing files that changed from the base of the PR and between df4bf60 and 50a8476.

📒 Files selected for processing (2)
  • app/components/Analysis/Form.vue
  • app/composables/usePaste.ts

Comment on lines +28 to +30
usePaste(inputRef, (pasted) => {
submit(pasted);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Trim pasted value and sync it into the model.

Two issues with the paste-submit wiring:

  1. Whitespace bypasses the empty guard. Clipboard contents often carry leading/trailing whitespace (e.g. when copying a username from a sentence or a table cell). submit() only checks !value, so a pasted " " or "foo\n" will be emitted as-is, leading to router.push({ params: { name: "foo\n" } }) in app/pages/index.vue and a broken route.
  2. accountName is not updated. The paste event fires before the browser writes the value into the input, so accountName keeps its prior value while submit(pasted) emits the new one. If navigation is cancelled/aborted (e.g. route guard, error boundary), the field visibly diverges from what was actually submitted.
🛠️ Suggested fix
 usePaste(inputRef, (pasted) => {
-  submit(pasted);
+  const value = pasted.trim();
+  accountName.value = value;
+  submit(value);
 });

You may also want submit() itself to trim, so manual typing benefits from the same guard:

 function submit(value: string) {
-  if (!value) {
+  const normalized = value.trim();
+  if (!normalized) {
     return;
   }
-  emit("submit", value.toLowerCase());
+  emit("submit", normalized.toLowerCase());
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
usePaste(inputRef, (pasted) => {
submit(pasted);
});
usePaste(inputRef, (pasted) => {
const value = pasted.trim();
accountName.value = value;
submit(value);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/components/Analysis/Form.vue` around lines 28 - 30, The paste handler
wired via usePaste should trim the pasted text and sync it into the form model
before calling submit: when the paste callback receives pasted, trim it (e.g.,
const value = pasted.trim()), write that trimmed value back into the input
element (inputRef.value.value = value) and into the reactive model (accountName
= value) and then call submit(value); also update submit() itself to trim its
incoming value so typed input benefits from the same empty/whitespace guard;
adjust references to usePaste, inputRef, accountName, and submit accordingly.

@MatteoGabriele
Copy link
Copy Markdown
Owner

Hi @cernymatej, thanks for developing this idea. However, I don't believe it's a well-known pattern, and it could introduce unnecessary complexity and potentially unexpected behaviors. As a user, I wouldn't expect this. I prefer a simpler approach: copy, paste, search: it's more straightforward and predictable.

@cernymatej
Copy link
Copy Markdown
Author

right, feel feee to close this then 😅
I just thought it would be nice to have the result load quicker since there really isn't anything else to configure once you've filled in the name

it's actually similar to how npmx.dev does it -> it also loads the results immediately (though that's implemented as a debounced search)

@MatteoGabriele
Copy link
Copy Markdown
Owner

Yeah, I personally fought to remove that feature: for me, it has always been a bit jarring and has added quite a bit of complexity as well. 😅
Thanks again, and feel free to contribute to other areas of the website that could be improved. 🙏

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.

2 participants