chatwoot/app/javascript/shared/helpers/specs
Sivin Varghese 437dd9d38c
fix: prevent Ctrl+Enter adding extra line break on send (Windows) (#14077)
# Pull Request Template

## Description

This PR includes,
On Windows, pressing **Ctrl+Enter** in the reply editor was inserting an
unintended line break before sending. This led to two issues:

* **Unexpected blank lines**
After adding a line break with Shift+Enter and removing it with
Backspace, the editor looked correct. However, sending with Ctrl+Enter
reintroduced a hidden break, resulting in an extra blank line in the
final message.

* **Selected text being replaced**
When text was selected and Ctrl+Enter was pressed, the selection was
replaced with a line break instead of being sent.

Fixes
https://linear.app/chatwoot/issue/CW-6840/newline-bug-in-the-editor


### **Cause**

Two keyboard handlers responded to **Ctrl+Enter** on Windows:

* ProseMirror (`Mod-Enter`) inserted a hard break
* ReplyBox (`$mod+Enter`) triggered send

The existing guard only checked `metaKey` (Cmd), so it never worked on
Windows. As a result, a line break was inserted just before sending.

### **Solution**

Make the modifier check platform-aware so the editor correctly
intercepts the send shortcut:

* Added `detectOS`, `isMac`, and `OS` constants
* Introduced `hasPressedMod` (uses `metaKey` on macOS, `ctrlKey`
elsewhere)

This ensures Ctrl+Enter sends the message without modifying content,
while keeping existing behavior unchanged.


**NB:** macOS behavior with Cmd+Enter remains unchanged



## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

**Case 1: line break**

1. Type `hello`
2. Press Shift+Enter, then Backspace
3. Press Ctrl+Enter
   → Message contains an unexpected blank new line

**Case 2: Selection replaced**

1. Type two lines using Shift+Enter
2. Select text on the second line
3. Press Ctrl+Enter
   → Selected text is replaced and not sent

### Screencast

**Before**


https://github.com/user-attachments/assets/d6d285a9-260b-4711-8bbd-d0c8519e8d20

**After**



https://github.com/user-attachments/assets/c0ace1f7-5d22-44a2-8e08-22190ee21e61



## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2026-04-20 18:16:41 +05:30
..
cache.spec.js chore: Add cache to improve widget performance (#11163) 2025-03-24 16:04:49 -07:00
clipboard.spec.js feat: Add the frontend support for MFA (#12372) 2025-09-18 21:16:06 +05:30
colorHelper.spec.js feat: Update public portal colors with new design (#8230) 2023-11-23 08:16:52 +05:30
CustomErrors.spec.js feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722) 2024-07-10 08:32:16 -07:00
CustomEventHelper.spec.js feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722) 2024-07-10 08:32:16 -07:00
DateHelper.spec.js chore: Remove older UI (#11720) 2025-07-01 09:43:44 +05:30
documentHelper.spec.js feat: add FE changes for captain pdf support for faq generation (#12115) 2025-09-02 19:01:16 +05:30
Emoji.spec.js fix: Avatar renders an incorrect symbol if it has emoji (#5184) 2022-08-03 14:11:33 +05:30
FileHelper.spec.js fix: Prevent unsupported file types on clipboard paste (#13182) 2026-01-14 13:07:46 +04:00
KeyboardHelpers.spec.js fix: prevent Ctrl+Enter adding extra line break on send (Windows) (#14077) 2026-04-20 18:16:41 +05:30
localStorage.spec.js feat: Implement reply to for reply editor (#8063) 2023-10-10 19:13:12 +05:30
MessageFormatter.spec.js fix: Prevent template variables from becoming links (#10725) 2025-01-23 18:18:14 +05:30
MessageTypeHelper.spec.js Chore: View form responses as user messages (#876) 2020-05-17 22:49:45 +05:30
mitt.spec.js feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722) 2024-07-10 08:32:16 -07:00
platform.spec.js fix: prevent Ctrl+Enter adding extra line break on send (Windows) (#14077) 2026-04-20 18:16:41 +05:30
portalHelper.spec.js feat: Sync Popular Articles locale with widget locale (#11754) 2025-06-24 19:52:44 +05:30
ReportsDataHelper.spec.js feat: update tool-chain to latest (#7975) 2023-09-27 14:02:34 +05:30
sanitizeData.spec.js feat: multiple UX improvements to labels (#7358) 2023-06-25 18:49:49 +05:30
sessionStorage.spec.js feat: Prevent saving preferences and status when impersonating (#11164) 2025-05-20 17:34:30 -07:00
timeHelper.spec.js fix: normalize "in less than a minute" to "now" in chat list timestamp (#13874) 2026-03-24 15:40:31 +05:30
ValidatorsHelper.spec.js fix: Handle slug validation errors in Help Center (#11368) 2025-04-24 16:58:05 +05:30