Skip to content

Commit

Permalink
Update vendored trix version to 2.1.8
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jorgemanrubia committed Oct 30, 2024
1 parent d610c17 commit 4dfb095
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions actiontext/app/assets/javascripts/trix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Trix 2.1.7
Trix 2.1.8
Copyright © 2024 37signals, LLC
*/
(function (global, factory) {
Expand All @@ -9,7 +9,7 @@ Copyright © 2024 37signals, LLC
})(this, (function () { 'use strict';

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

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

Expand Down Expand Up @@ -10651,14 +10664,15 @@ $\
},
beforeinput(event) {
const handler = this.constructor.inputTypes[event.inputType];

// Handles bug with Siri dictation on iOS 18+.
if (!event.inputType) {
this.render();
}
const immmediateRender = shouldRenderInmmediatelyToDealWithIOSDictation(event);
if (handler) {
this.withEvent(event, handler);
this.scheduleRender();
if (!immmediateRender) {
this.scheduleRender();
}
}
if (immmediateRender) {
this.render();
}
},
input(event) {
Expand Down

0 comments on commit 4dfb095

Please sign in to comment.