MudMask: Fix ⌘ shortcuts on MacOS & cut shortcut in general#11366
MudMask: Fix ⌘ shortcuts on MacOS & cut shortcut in general#11366ScarletKuro merged 9 commits intoMudBlazor:devfrom
⌘ shortcuts on MacOS & cut shortcut in general#11366Conversation
⌘+<key> shortcuts on MacOS & copy/paste/cut shortcuts in general⌘ shortcuts on MacOS & cut shortcut in general
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #11366 +/- ##
==========================================
+ Coverage 91.10% 91.12% +0.01%
==========================================
Files 465 465
Lines 14407 14408 +1
Branches 2788 2788
==========================================
+ Hits 13126 13129 +3
+ Misses 642 641 -1
+ Partials 639 638 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes shortcut handling in MudMask so that the macOS Command key (MetaKey) is treated like CtrlKey, and it corrects the cut event logic by reusing the copy implementation before clearing the selection.
- Treat
MetaKey(⌘) same asCtrlKeyinHandleKeyDown. - Extract copy logic into
CopySelectionToClipboardand call it for both copy and cut. - Update
OnCutsignature and remove the old inline copy implementation.
Comments suppressed due to low confidence (2)
src/MudBlazor/Components/Mask/MudMask.razor.cs:462
- [nitpick] Rename the parameter
objto something more descriptive likeargsoreventArgsfor consistency with event-handler conventions.
private async void OnCut(EventArgs obj)
src/MudBlazor/Components/Mask/MudMask.razor.cs:202
- There are no unit tests validating the new
MetaKeyhandling inHandleKeyDownor the updated cut logic; consider adding tests for both scenarios.
if (e.CtrlKey && e.Key != "Backspace"
|
Looks like this would solve the issue. Thanks 👍 Was just about to look into it myself. |
|



Description
Fixes #4749, fixes #10093
The
⌘key on MacOS is generally the modifier key that triggers copy/paste/cut shortcuts on MacOS, it is also knows as theMetaKey(similar to the Windows key, or the super key on Linux). To fix the issue where using these shortcuts on MacOS would cause extra characters to be added to the input we treat theMetaKeythe same way we treat theCtrlKeyin theOnKeyDownlogic of the mask.Another issue with
MudMaskwas that it didn't handlecuts correctly. When thecutevent was triggered, we were programmatically clearing the selection from the input, only after that would the browser trigger the "copy" instruction, but the selection was no longer there to be copied. We now reuse theOnCopylogic to programmatically copy the current mask selection to the clipboard before clearing it.How Has This Been Tested?
Added basic bUnit tests and visually tested on
MacOS+Chrome,Windows+Chrome, andWindows+Firefox, here's a clip onMacOS+Chrome:Screen.Cast.2025-05-19.at.11.10.18.PM.mp4
Type of Changes
Checklist
dev).