Skip to content

Add keyboard shortcuts display and copy-to-clipboard with visual feedback for Image Beautifier#1

Merged
dipeshsingh253 merged 6 commits into
mainfrom
copilot/add-keyboard-shortcuts-and-copy-button
Jan 26, 2026
Merged

Add keyboard shortcuts display and copy-to-clipboard with visual feedback for Image Beautifier#1
dipeshsingh253 merged 6 commits into
mainfrom
copilot/add-keyboard-shortcuts-and-copy-button

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 26, 2026

Implementation Complete ✅

Features Implemented

1. Keyboard Shortcuts (Ctrl+1-9, Ctrl+0)

  • Fixed bug in existing keyboard shortcuts where Ctrl+0 wasn't working properly
  • Added keyboard shortcut indicators in sidebar:
    • Collapsed state: Shows in tooltips (e.g., "Config Formatter (Ctrl+1)")
    • Expanded state: Shows next to tool names (e.g., "⌃1", "⌃2", etc.)
  • Tested all shortcuts (Ctrl+1 through Ctrl+0) - working correctly

2. Copy Button in Image Beautifier

  • Added Copy button next to Download button
  • Implemented using Clipboard API for direct image copying
  • Added browser compatibility checks using window.ClipboardItem
  • Included proper error handling with user-friendly messages
  • Added visual feedback: Button displays "Copied!" with checkmark icon for 2 seconds after successful copy
  • Tested functionality - working correctly

Technical Changes

  • src/App.tsx: Fixed keyboard shortcut logic for Ctrl+0
  • src/components/Sidebar/Sidebar.tsx: Added shortcut indicators
  • src/components/ImageBeautifier/ImageBeautifier.tsx:
    • Added copy functionality with robust browser compatibility
    • Added copied state to track copy success
    • Button dynamically changes to show "Copied!" with check icon and brighter green color for 2 seconds

Quality Checks

  • Linter: No errors in modified files
  • Build: Successful
  • Code Review: Completed and addressed all feedback
  • Security Scan: No vulnerabilities found

Screenshots

Sidebar with keyboard shortcuts:
Sidebar

Copy button - Before clicking:
Before copy

Copy button - After clicking (shows "Copied!" feedback):
After copy

Recent Updates

  • Fixed ClipboardItem compatibility check to use window.ClipboardItem instead of direct reference to prevent ReferenceError in browsers where ClipboardItem is not defined
  • Added visual feedback when copy button is clicked - button changes to show "Copied!" with checkmark icon for 2 seconds
Original prompt

okay I need to implement 2 things in this project.

  1. I should be able to use Ctrl+ 1,2... to switch between tools.

  2. Also in image beautifier I want to have a copy button just beside download button so I will be able to copy the beautified image without downloading.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 26, 2026 09:16
Co-authored-by: dipeshsingh253 <84814627+dipeshsingh253@users.noreply.github.com>
Co-authored-by: dipeshsingh253 <84814627+dipeshsingh253@users.noreply.github.com>
Co-authored-by: dipeshsingh253 <84814627+dipeshsingh253@users.noreply.github.com>
Copilot AI changed the title [WIP] Add keyboard shortcuts for tool switching and copy button Add keyboard shortcuts display and copy-to-clipboard for Image Beautifier Jan 26, 2026
Copilot AI requested a review from dipeshsingh253 January 26, 2026 09:25
Copy link
Copy Markdown

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

Implements keyboard shortcuts for switching tools and adds a “Copy to clipboard” action to the Image Beautifier preview, improving navigation and image export UX.

Changes:

  • Sidebar now displays keyboard shortcut hints (tooltips when collapsed and inline “⌃N” labels when expanded), with shortcut keys derived from tool order.
  • App-wide keydown handler updated to correctly support Ctrl/Cmd + 1–9 and 0 for switching between tools in a fixed order.
  • Image Beautifier gains a “Copy” button that uses the Clipboard API to copy the rendered canvas as a PNG to the clipboard, alongside the existing download button.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/components/Sidebar/Sidebar.tsx Adds index-based shortcut key mapping and visual indicators for Ctrl+1–9 / 0 tool switching in the sidebar UI.
src/components/ImageBeautifier/ImageBeautifier.tsx Introduces a canvas-to-clipboard flow and a Copy button in the preview toolbar to complement the existing Download functionality.
src/App.tsx Updates the global keyboard handler to correctly interpret Ctrl/Cmd + number keys and map them to the corresponding tool IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +121
if (!navigator.clipboard || !ClipboardItem) {
alert('Copy to clipboard is not supported in this browser. Please use the Download button instead.');
return;
}

const canvas = canvasRef.current;

// Convert canvas to blob using Promise-based approach
const blob = await new Promise<Blob | null>((resolve) => {
canvas.toBlob((blob) => resolve(blob), 'image/png');
});

if (!blob) {
throw new Error('Failed to create blob from canvas');
}

// Use Clipboard API to copy the image
await navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
]);
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The feature detection for the Clipboard API can throw a ReferenceError in browsers that don’t define ClipboardItem, because referencing ClipboardItem directly in the if (!navigator.clipboard || !ClipboardItem) check will fail before the fallback alert runs. To make this compatibility check robust, gate access to ClipboardItem via window/globalThis (for example by checking 'ClipboardItem' in window or window.ClipboardItem) and only construct a new ClipboardItem(...) after that check passes, so unsupported browsers don’t throw before you can show the intended "not supported" message.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 9dcee73. Changed both the compatibility check (line 100) and the ClipboardItem instantiation (line 118) to use window.ClipboardItem instead of direct reference, preventing ReferenceError in browsers where ClipboardItem is not defined.

@dipeshsingh253 dipeshsingh253 marked this pull request as ready for review January 26, 2026 10:33
…browsers

Co-authored-by: dipeshsingh253 <84814627+dipeshsingh253@users.noreply.github.com>
@dipeshsingh253
Copy link
Copy Markdown
Owner

@copilot when we click on the newly introduced copy button in image beautifier tool it should also do some indication, that yeah your image is copied.

Co-authored-by: dipeshsingh253 <84814627+dipeshsingh253@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot when we click on the newly introduced copy button in image beautifier tool it should also do some indication, that yeah your image is copied.

Added visual feedback in commit be8bcaf. When the copy button is clicked, it now displays "Copied!" with a checkmark icon for 2 seconds before reverting back to "Copy". The button also changes to a brighter green color (#2ea043) during the copied state.

Before clicking:
Before copy

After clicking (shows "Copied!" for 2 seconds):
After copy

Copilot AI changed the title Add keyboard shortcuts display and copy-to-clipboard for Image Beautifier Add keyboard shortcuts display and copy-to-clipboard with visual feedback for Image Beautifier Jan 26, 2026
@dipeshsingh253 dipeshsingh253 merged commit 9e25033 into main Jan 26, 2026
1 check failed
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.

3 participants