Skip to content

🧹 Refactor paste method to improve readability by extracting OS-specific logic - #35

Merged
undivisible merged 5 commits into
mainfrom
refactor-paste-method-9147010404471194839
Sep 2, 2026
Merged

🧹 Refactor paste method to improve readability by extracting OS-specific logic#35
undivisible merged 5 commits into
mainfrom
refactor-paste-method-9147010404471194839

Conversation

@undivisible

@undivisible undivisible commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🎯 What: The code health issue addressed
The paste function in src/lib.rs was overly long (100+ lines) and complex, primarily because it directly embedded lengthy, heavily nested, OS-specific logic for Windows and macOS directly in the method body.

💡 Why: How this improves maintainability
Extracting the Windows and macOS logic into their own dedicated, conditionally compiled functions (windows_native_paste and macos_native_paste) reduces the size of the paste method drastically. It makes the main paste function much easier to read (it now simply acts as a dispatcher to OS-specific handlers) and isolates the platform-specific code, making future changes or debugging on specific platforms easier.

Verification: How you confirmed the change is safe

  • Extracted code functionally exactly matches the original inline code.
  • Passed cargo check and cargo fmt.
  • Passed cargo clippy.
  • Ran full test suite via cargo test which confirmed no functionality was broken.
  • Requested review from AI agent which gave a "Correct" rating.

Result: The improvement achieved
The paste method is now clean, readable, and small, effectively delegating to well-named helper functions to handle the actual logic for macOS and Windows, resolving the "overly long function" code health issue.


PR created automatically by Jules for task 9147010404471194839 started by @undivisible


Note

Low Risk
Pure refactor with no behavioral change to clipboard or synthetic keyboard input; Linux paste was already externalized the same way.

Overview
Refactors native paste so NativeRuntime::paste matches the existing Linux pattern: it only dispatches to OS-specific helpers instead of embedding large inline blocks.

macOS logic moves to macos_native_paste (accessibility check, pbcopy, Cmd+V via mac_post_key). Windows logic moves to windows_native_paste (clipboard Unicode setup and Ctrl+V via SendInput). Behavior is unchanged—code was relocated, not rewritten.

tests/cli.rs fixes indentation on the stdin write_all block in the CLI test helper.

Reviewed by Cursor Bugbot for commit 77f466c. Configure here.

…nctions

Extracted heavily nested Windows and macOS OS-specific logic from the `NativeRuntime::paste` method in `src/lib.rs` into new conditionally compiled helper functions `windows_native_paste` and `macos_native_paste`.

This refactor significantly simplifies the main `paste` method, making it much shorter and easier to read, without changing any underlying functionality.

Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 3 commits August 27, 2026 04:46
- Fixed a new rust 1.98.0 Clippy warning (`clippy::chunks-exact-to-as-chunks`) in `src/cdp.rs` by replacing `.chunks_exact(8)` and `.chunks_exact(TCP_ROW_BYTES)` with `.as_chunks::<8>().0` and `.as_chunks::<TCP_ROW_BYTES>().0.iter()`.
- Updated `event-listener` from v5.4.1 to v5.4.2 to resolve `cargo audit` vulnerability (RUSTSEC-2026-0221) which caused the Release sanity CI job to fail.

Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com>
- Fixed a new rust 1.98.0 Clippy warning (\`clippy::chunks-exact-to-as-chunks\`) in \`src/cdp.rs\` by replacing \`.chunks_exact(8)\` and \`.chunks_exact(TCP_ROW_BYTES)\` with \`.as_chunks::<8>().0\` and \`.as_chunks::<TCP_ROW_BYTES>().0.iter()\`.
- Updated \`event-listener\` from v5.4.1 to v5.4.2 to resolve \`cargo audit\` vulnerability (RUSTSEC-2026-0221) which caused the Release sanity CI job to fail.

Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@undivisible
undivisible merged commit 0bd4ebc into main Sep 2, 2026
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