Skip to content

Fix Alt+key copy shortcuts not working for HTML notebook outputs #251434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 13, 2025

Users reported that keyboard shortcuts involving the Alt key (like Alt+C for copy) were not working for HTML notebook cell outputs, while they worked fine for plain text outputs and the standard Ctrl+C shortcut worked for all output types.

Root Cause

The issue was in the OutputElement class in webviewPreloads.ts. When implementing drag-and-drop functionality for notebook outputs, an Alt key handler was added that immediately set element.draggable = true whenever Alt was pressed:

window.addEventListener('keydown', (e) => {
    if (e.altKey) {
        this.element.draggable = true;  // This interfered with Alt+C copy
    }
});

Making an element draggable can interfere with text selection and copy operations, preventing Alt-based keyboard shortcuts from working properly.

Solution

Modified the Alt keydown handler to check for common copy/paste/cut key combinations and skip making the element draggable in those cases:

window.addEventListener('keydown', (e) => {
    if (e.altKey) {
        // Don't make element draggable if Alt is used with copy/paste/cut keys
        // to avoid interfering with Alt-based keyboard shortcuts for copying
        const isCopyPasteShortcut = e.key === 'c' || e.key === 'C' ||
                                   e.key === 'v' || e.key === 'V' ||
                                   e.key === 'x' || e.key === 'X';
        if (!isCopyPasteShortcut) {
            this.element.draggable = true;
        }
    }
});

What This Fixes

  • Alt+C, Alt+V, Alt+X keyboard shortcuts now work correctly for HTML notebook outputs
  • Both uppercase and lowercase key variants are supported
  • Copy operations work properly without interference from drag behavior

What Remains Working

  • Drag-and-drop functionality is preserved for Alt + other key combinations
  • Image outputs remain draggable by default (unchanged behavior)
  • Standard Ctrl+C/Cmd+C copy shortcuts continue to work
  • Window blur and Alt release properly reset the draggable state

This is a minimal, surgical fix that only affects the specific condition causing the problem while preserving all existing functionality.

Fixes #251433.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 13, 2025 19:27
Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] copilot -- Copying notebook HTML output not working for some keyboard shortcuts. Fix Alt+key copy shortcuts not working for HTML notebook outputs Jun 13, 2025
@Copilot Copilot AI requested a review from Yoyokrazy June 13, 2025 19:30
Copilot finished work on behalf of Yoyokrazy June 13, 2025 19:30
@Yoyokrazy
Copy link
Contributor

This is not an issue we can solve by listening for particular keystrokes. The user is allowed to set a completely arbitrary keystroke based upon their own needs, for example something like alt+w which is not a common or expected keystroke.

It would appear that when the keystroke is used, the command is still triggered (the copy command), hoewver the holding of alt seems to be putting the HTML text into a technically unselected state (even though there is still a visual selection). Please try to address the root cause here.

Copy link
Contributor Author

Copilot AI commented Jun 13, 2025

This is not an issue we can solve by listening for particular keystrokes. The user is allowed to set a completely arbitrary keystroke based upon their own needs, for example something like alt+w which...

You're absolutely right. I've addressed the root cause by changing the approach entirely. Instead of trying to detect specific keystrokes, the fix now:

  1. Tracks Alt state without immediately setting draggable=true - this prevents interference with text selection and any Alt-based shortcuts
  2. Only sets draggable=true when detecting actual drag intent (Alt + mousedown) and when there's no active text selection
  3. Respects existing text selections - if text is selected, it won't make the element draggable even during drag attempts

This approach preserves all keyboard shortcuts (including arbitrary user-configured ones) while still enabling drag-and-drop functionality when the user actually intends to drag content.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Instead of blocking specific keystrokes, only enable drag when detecting actual drag intent (Alt+mousedown) and when there's no text selection. This preserves all keyboard shortcuts while maintaining drag functionality.

Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
Copilot finished work on behalf of Yoyokrazy June 13, 2025 19:41
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.

copilot -- Copying notebook HTML output not working for some keyboard shortcuts.
2 participants