Skip to content

Commit 8fded65

Browse files
Update vendored trix version to 2.1.8 (rails#53493)
This updates Trix to 2.1.8, which includes a patch for a dictation issue in iOS 18+ where it garbles newlines when dictation ends. See basecamp/trix#1196
1 parent c303185 commit 8fded65

File tree

1 file changed

+22
-8
lines changed
  • actiontext/app/assets/javascripts

1 file changed

+22
-8
lines changed

actiontext/app/assets/javascripts/trix.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Trix 2.1.7
2+
Trix 2.1.8
33
Copyright © 2024 37signals, LLC
44
*/
55
(function (global, factory) {
@@ -9,7 +9,7 @@ Copyright © 2024 37signals, LLC
99
})(this, (function () { 'use strict';
1010

1111
var name = "trix";
12-
var version = "2.1.7";
12+
var version = "2.1.8";
1313
var description = "A rich text editor for everyday writing";
1414
var main = "dist/trix.umd.min.js";
1515
var module = "dist/trix.esm.min.js";
@@ -1089,6 +1089,19 @@ $\
10891089
return event => event.ctrlKey;
10901090
}
10911091
}();
1092+
function shouldRenderInmmediatelyToDealWithIOSDictation(inputEvent) {
1093+
if (/iPhone|iPad/.test(navigator.userAgent)) {
1094+
// Handle garbled content and duplicated newlines when using dictation on iOS 18+. Upon dictation completion, iOS sends
1095+
// the list of insertText / insertParagraph events in a quick sequence. If we don't render
1096+
// the editor synchronously, the internal range fails to update and results in garbled content or duplicated newlines.
1097+
//
1098+
// This workaround is necessary because iOS doesn't send composing events as expected while dictating:
1099+
// https://bugs.webkit.org/show_bug.cgi?id=261764
1100+
return !inputEvent.inputType || inputEvent.inputType === "insertParagraph";
1101+
} else {
1102+
return false;
1103+
}
1104+
}
10921105

10931106
const defer = fn => setTimeout(fn, 1);
10941107

@@ -10651,14 +10664,15 @@ $\
1065110664
},
1065210665
beforeinput(event) {
1065310666
const handler = this.constructor.inputTypes[event.inputType];
10654-
10655-
// Handles bug with Siri dictation on iOS 18+.
10656-
if (!event.inputType) {
10657-
this.render();
10658-
}
10667+
const immmediateRender = shouldRenderInmmediatelyToDealWithIOSDictation(event);
1065910668
if (handler) {
1066010669
this.withEvent(event, handler);
10661-
this.scheduleRender();
10670+
if (!immmediateRender) {
10671+
this.scheduleRender();
10672+
}
10673+
}
10674+
if (immmediateRender) {
10675+
this.render();
1066210676
}
1066310677
},
1066410678
input(event) {

0 commit comments

Comments
 (0)