Skip to content

MudMask: Fix shortcuts on MacOS & cut shortcut in general#11366

Merged
ScarletKuro merged 9 commits intoMudBlazor:devfrom
igotinfected:fix/copy-paste-macos-mudmask
May 26, 2025
Merged

MudMask: Fix shortcuts on MacOS & cut shortcut in general#11366
ScarletKuro merged 9 commits intoMudBlazor:devfrom
igotinfected:fix/copy-paste-macos-mudmask

Conversation

@igotinfected
Copy link
Member

@igotinfected igotinfected commented May 19, 2025

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 the MetaKey (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 the MetaKey the same way we treat the CtrlKey in the OnKeyDown logic of the mask.

Another issue with MudMask was that it didn't handle cuts correctly. When the cut event 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 the OnCopy logic 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, and Windows+Firefox, here's a clip on MacOS+Chrome:

Screen.Cast.2025-05-19.at.11.10.18.PM.mp4

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added bug Unexpected behavior or functionality not working as intended PR: needs review labels May 19, 2025
@igotinfected igotinfected changed the title MudMask: Fix ⌘+<key> shortcuts on MacOS & copy/paste/cut shortcuts in general MudMask: Fix shortcuts on MacOS & cut shortcut in general May 19, 2025
@codecov
Copy link

codecov bot commented May 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.12%. Comparing base (aa7af8f) to head (6e196be).
Report is 3 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielchalmers danielchalmers requested a review from Copilot May 19, 2025 22:35
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 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 as CtrlKey in HandleKeyDown.
  • Extract copy logic into CopySelectionToClipboard and call it for both copy and cut.
  • Update OnCut signature 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 obj to something more descriptive like args or eventArgs for 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 MetaKey handling in HandleKeyDown or the updated cut logic; consider adding tests for both scenarios.
if (e.CtrlKey && e.Key != "Backspace"

@Etzix
Copy link
Contributor

Etzix commented May 22, 2025

Looks like this would solve the issue. Thanks 👍 Was just about to look into it myself.

@igotinfected igotinfected requested a review from ScarletKuro May 26, 2025 07:15
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a Mask to MudTextField breaks copy behaviour. Copy and Paste does not work as intended on Mac

4 participants