Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

feat(advancedpaste): add auto-copy selection for custom action hotkeys#44767

Merged
yeelam-gordon merged 6 commits intomainfrom
user/yeelam/SingleCopyAndPaste
Feb 6, 2026
Merged

feat(advancedpaste): add auto-copy selection for custom action hotkeys#44767
yeelam-gordon merged 6 commits intomainfrom
user/yeelam/SingleCopyAndPaste

Conversation

@yeelam-gordon
Copy link
Contributor

Summary of the Pull Request

Boosting productivity #2x. Customer mentioned with Custom Action (Shortcut trigger) "We should not need to do two keyboard actions to finish this awesome AI data transformation, instead, just single shortcut should do copy + advanced paste."

This pull request introduces a new feature to the Advanced Paste module that allows users to automatically copy the current selection when triggering a custom action hotkey. The changes include backend logic for sending the copy command, updates to configuration and settings management, and UI additions to expose this option to users.

Feature Addition: Auto-Copy Selection for Custom Action Hotkeys

  • Added a new boolean setting, AutoCopySelectionForCustomActionHotkey, to both the backend (dllmain.cpp, AdvancedPasteProperties.cs) and the settings UI, allowing users to enable or disable automatic copying of the current selection when a custom action hotkey is pressed. [1] [2] [3] [4] [5] [6]

Backend Logic and Integration

  • Implemented the send_copy_selection() and try_send_copy_message() methods in dllmain.cpp to send a WM_COPY message or simulate a Ctrl+C keystroke, ensuring the selected content is copied before executing the custom action.
  • Integrated the new setting into the hotkey handler logic so that when a custom action hotkey is pressed and the setting is enabled, the copy operation is triggered before running the custom action.

Configuration and State Management

  • Updated serialization/deserialization and property synchronization logic to support the new setting, ensuring its value is correctly loaded, saved, and reflected in the UI and runtime behavior. [1] [2]

UI and Localization

  • Added a new checkbox to the Advanced Paste settings page in XAML to allow users to toggle the auto-copy feature.
  • Provided localized strings for the new setting, including header and description, in the resource file for user clarity.

Refactoring for Hotkey Logic

  • Refactored hotkey handling code to correctly calculate indices for additional and custom actions, supporting the new auto-copy logic and improving code clarity. [1] [2] [3]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an auto-copy feature for custom action hotkeys in Advanced Paste, enabling users to copy selected text and execute a custom action with a single keyboard shortcut instead of requiring separate copy and paste actions.

Changes:

  • Added a new configuration setting AutoCopySelectionForCustomActionHotkey to enable/disable automatic copying
  • Implemented backend logic to send WM_COPY or simulate Ctrl+C when custom action hotkeys are triggered
  • Added UI controls and localization strings for the new setting

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
dllmain.cpp Implements copy selection logic and integrates it into hotkey handling
AdvancedPasteProperties.cs Adds the new boolean property to the settings model
AdvancedPasteViewModel.cs Exposes the setting to the UI with two-way binding
AdvancedPastePage.xaml Adds a checkbox control for the new setting
Resources.resw Provides localized strings for the UI elements

@vanzue
Copy link
Contributor

vanzue commented Jan 19, 2026

The main concern is the corner case - What if copy fail for selection:
User would imagine that they are doing things toward a new selection, but if we fail, the last copied item will be sent to maybe cloud LLM, this is the main concern, and for experience, the processed item will be the last one, also causes confusion, and uncertainty.

@vanzue
Copy link
Contributor

vanzue commented Jan 19, 2026

Maybe could we stop the processing if copy failed?

@yeelam-gordon
Copy link
Contributor Author

Maybe could we stop the processing if copy failed?

Totally get it. I aware that in the 1st day since half an year ago Hao talked about it.
There is a technical complexity to check if what currently selected are in clipboard already (Even sometime Human like me "think" they copied but actually not successful at all).

What i push on recently change:
a. Set the right expectation this "option" is best effort to copy and paste, updated the "wording" for this new option which is off by default.
b. It will retry for two times, and each time fallback on two mechanisms.

@vanzue
Copy link
Contributor

vanzue commented Jan 22, 2026

Can we check clipboard sequence to check whether there is a copy happened? If copy failed, we cann stop the processing
Or we can hash the clipboard content and timestamp before copy and after copy to make sure content change?

@yeelam-gordon
Copy link
Contributor Author

Can we check clipboard sequence to check whether there is a copy happened? If copy failed, we cann stop the processing Or we can hash the clipboard content and timestamp before copy and after copy to make sure content change?

I tried the following before.
Clipboard will not have duplicate entry if I do ctrl+c multiple time, i.e. only single new entry.
As the result, even I want to do like:
a. Check current clipboard content
b. See if there is a new "content" which "we trigger"
If no, consider as failure.

The above situation make above checking not entirely correct.

@vanzue
Copy link
Contributor

vanzue commented Jan 22, 2026

Add-Type @"
using System;
using System.Runtime.InteropServices;
public static class ClipSeq {
[DllImport("user32.dll")]
public static extern uint GetClipboardSequenceNumber();
}
"@
[ClipSeq]::GetClipboardSequenceNumber()

I tried this, and it works for the case you mentioned above, would sequence number help more?

@github-actions

This comment has been minimized.

@yeelam-gordon yeelam-gordon requested a review from a team as a code owner January 31, 2026 17:27
@yeelam-gordon
Copy link
Contributor Author

Thanks for the suggestion. I’ve updated the auto-copy path to verify success using GetClipboardSequenceNumber() before/after each copy attempt and only proceed when the sequence changes (with a short poll/timeout). If it doesn’t change, we retry and skip the downstream logic. This should make the copy detection more reliable for the scenario you called out.

@yeelam-gordon
Copy link
Contributor Author

Update applied: if auto-copy fails (no clipboard sequence change after retries), on_hotkey now returns false and skips the rest of the custom action flow. See src/modules/AdvancedPaste/AdvancedPasteModuleInterface/dllmain.cpp. Please resolve the review thread in the PR UI.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@vanzue
Copy link
Contributor

vanzue commented Feb 1, 2026

Thanks!! This looks good to me!!
pr status looks weird?

@yeelam-gordon yeelam-gordon force-pushed the user/yeelam/SingleCopyAndPaste branch from 5c9c31b to 9fa44c8 Compare February 4, 2026 17:05
@yeelam-gordon
Copy link
Contributor Author

Thanks!! This looks good to me!! pr status looks weird?

The rebase doesn't work well... just do it right now...

@yeelam-gordon yeelam-gordon merged commit 914f228 into main Feb 6, 2026
15 checks passed
@vanzue vanzue added this to the PowerToys 0.97 milestone Feb 9, 2026
@vanzue vanzue added the Product-Advanced Paste Refers to the Advanced Paste module label Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Advanced Paste Refers to the Advanced Paste module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants