Skip to content

Copy text without dismissing the selection #15371

Closed

Description

In Notepad, if there is a selection, pressing Ctrl+C, the text will be copied to the clipboard, otherwise nothing happens. This is the same in other edit boxes and controls
...
I would like Terminal/PowerShell to behave exactly like Notepad

This seems like a reasonable property to add to the copy action.

class CopyActionArgs {
  singleLine: bool = false;
  copyFormatting = false;
  dismissSelection: bool = false;
}

Originally suggested by gaberiel44 in #15349

Note

Walkthrough

  • Add a Boolean DismissSelection to CopyTextArgs in src\cascadia\TerminalSettingsModel\ActionArgs.idl
  • Add DismissSelection to COPY_TEXT_ARGS in ActionArgs.h
  • The actual copy args are retrieved in TerminalPage::_HandleCopyText (in AppActionHandlers.cpp), and passed to TerminalPage::_CopyText, which calls down to TermControl::CopySelectionToClipboard.
    • In CopySelectionToClipboard, just don't ClearSelection.
  • This arg will also need localization, in ActionArgs.cpp, CopyTextArgs::GenerateName, and src\cascadia\TerminalSettingsModel\Resources\en-US\Resources.resw

Activity

  1. added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    Needs-Tag-FixDoesn't match tag requirements
    on May 17, 2023
  2. added
    Area-TerminalControlIssues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)
    Area-SettingsIssues related to settings and customizability, for console or terminal
    Issue-TaskIt's a feature request, but it doesn't really need a major design.
    and removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on May 17, 2023
  3. added
    Help WantedWe encourage anyone to jump in on these.
    good first issueThis is a fix that might be easier for someone to do as a first contribution
    on May 17, 2023
  4. moved this from Should be written to Walkthrough in issue in Terminal Walkthroughson May 17, 2023
  5. horrificCoder commented on May 18, 2023

    @horrificCoder

    Mike Griese (@zadjii-msft) Can I work on this?

  6. zadjii-msft commented on May 18, 2023

    @zadjii-msft
    MemberAuthor

    Absolutely!

  7. Sayan505 commented on May 18, 2023

    @Sayan505

    I've got a fix working. I've removed _core.ClearSelection(); from TermControl.cpp which leads to the intended behaviour. Is this correct?
    Looking for feedback on my first ever PR on GitHub. #15383

  8. Sayan505 commented on May 20, 2023

    @Sayan505

    Mike Griese (@zadjii-msft) Hi, could you please explain me the point of bool dismissSelection?

  9. zadjii-msft commented on May 23, 2023

    @zadjii-msft
    MemberAuthor

    could you please explain me the point of bool dismissSelection?

    Sure - by making this a setting, then users can choose which behavior they want. They could even have both! Like, a user could have the following settings:

    "actions":
    [
        { "keys": "ctrl+c", "command": { "action": "copy", "dismissSelection": "true" }, },
        { "keys": "ctrl+d", "command": { "action": "copy", "dismissSelection": "false" }, },
    ]

    And then

    • ctrl+c would copy and dismiss the selection (as it currently does)
    • ctrl+d would copy and leave the selection unchanged (as in Notepad et al.)

    Or a user could just rebind ctrl+c to "action": "copy", "dismissSelection": "false", or whatever!

    Does that make sense?

  10. code-krishna commented on May 28, 2023

    @code-krishna

    Mike Griese (@zadjii-msft) can I kindly work on this issue?

  11. Delano5000 commented on Jun 16, 2023

    @Delano5000

    @/class CopyActionArgs {
    singleLine: bool = false;
    copyFormatting = false;
    dismissSelection: bool = false;
    }

  12. rifat01mahmud commented on Jun 19, 2023

    @rifat01mahmud

    function copyText() {
    var selectedText = window.getSelection().toString();
    var tempInput = document.createElement("textarea");
    tempInput.value = selectedText;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand("copy");
    document.body.removeChild(tempInput);
    }

    // Call the function when the copy button or any trigger event is activated
    copyText();

    Rifat Mahmud (Ovronormal)

  13. moved this from Walkthrough in issue to Done in Terminal Walkthroughson Jul 6, 2023
  14. added a commit that references this issue on Jul 6, 2023
    0c64b8a
  15. added a commit that references this issue on Jul 12, 2023
    b37dc8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-SettingsIssues related to settings and customizability, for console or terminalArea-TerminalControlIssues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)Help WantedWe encourage anyone to jump in on these.In-PRThis issue has a related PRIssue-TaskIt's a feature request, but it doesn't really need a major design.Product-TerminalThe new Windows Terminal.good first issueThis is a fix that might be easier for someone to do as a first contribution

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions