Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore detection of text direction on Chrome #1060

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/test/unit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "test/unit/attachment_test"
import "test/unit/bidi_test"
import "test/unit/block_test"
import "test/unit/composition_test"
import "test/unit/document_test"
Expand Down
9 changes: 9 additions & 0 deletions src/test/unit/bidi_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { assert, test, testGroup } from "test/test_helper"
import { getDirection } from "trix/core/helpers"

testGroup("BIDI", () => {
test("detects text direction", () => {
assert.equal(getDirection("abc"), "ltr")
assert.equal(getDirection("אבג"), "rtl")
})
})
8 changes: 5 additions & 3 deletions src/trix/core/helpers/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const RTL_PATTERN =

export const getDirection = (function() {
const input = makeElement("input", { dir: "auto", name: "x", dirName: "x.dir" })
const textArea = makeElement("textarea", { dir: "auto", name: "y", dirName: "y.dir" })
const form = makeElement("form")
form.appendChild(input)
form.appendChild(textArea)

const supportsDirName = (function() {
try {
return new FormData(form).has(input.dirName)
return new FormData(form).has(textArea.dirName)
} catch (error) {
return false
}
Expand All @@ -27,8 +29,8 @@ export const getDirection = (function() {

if (supportsDirName) {
return function(string) {
input.value = string
return new FormData(form).get(input.dirName)
textArea.value = string
return new FormData(form).get(textArea.dirName)
}
} else if (supportsDirSelector) {
return function(string) {
Expand Down