fix: make macOS text replacement work on contenteditable (#51289)

* fix: make macOS text replacement work on `contenteditable`

* fix: remove accidentally included patch line
This commit is contained in:
Noah Gregory
2026-04-27 12:09:47 -04:00
committed by GitHub
parent 9e7a343f39
commit 411e3be571
2 changed files with 31 additions and 0 deletions

View File

@@ -148,5 +148,6 @@ fix_fire_menu_popup_start_for_dynamically_created_aria_menus.patch
feat_allow_enabling_extensions_on_custom_protocols.patch
fix_initialize_com_on_desktopmedialistcapturethread_on_windows.patch
chore_register_node_as_a_dynamic_trace_category_prefix.patch
fix_make_macos_text_replacement_work_on_contenteditable.patch
fix_allow_reentrancy_on_downloadmanagerimpl_observer_list.patch
build_gn_arg_to_support_linker_wrapper_script_on_windows.patch

View File

@@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Noah Gregory <noahmgregory@gmail.com>
Date: Thu, 23 Apr 2026 11:11:44 -0400
Subject: fix: make macOS text replacement work on `contenteditable`
Text-editor libraries like `lexical` don't use `input` elements,
but instead use `contenteditable` elements. macOS text replacement
is currently bugged on these elements. This patch fixes that.
1. Backspace now rejects the replacement instead of accepting it.
2. Space now adds a space after accepting the replacement.
diff --git a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
index 38159d146cdf71f84611d58e2983418a1a365911..c256a5a98cd93bdcf69190ee3ae083b8a6daedc4 100644
--- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
+++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
@@ -532,6 +532,13 @@ - (void)didAcceptReplacementString:(NSString*)acceptedString
if (acceptedString == nil)
return;
+ if (changeNumber != _availableTextChangeCounter) {
+ if (!_textSelectionRange.is_empty() ||
+ _textSelectionRange.start() <= NSMaxRange(correction.range)) {
+ return;
+ }
+ }
+
NSRange availableTextRange =
NSMakeRange(_availableTextOffset, _availableText.length());