-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Calling editor.setSelectedText in system test #1109
Comments
@jcbpl no changes that I'm aware of. Hard to say what's going on, but if there has been a regression a failing test might help to pinpoint the issue. |
Thanks. I'm not very familiar with Trix's tests, but I'm able to reproduce in Chrome using a simple Stimulus controller: // trix_debug.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
ready() {
this.element.editor.loadHTML("Hello world")
this.element.editor.setSelectedRange([0,5])
}
} Included via: <%= form.rich_text_area :content, data: { controller: "trix-debug", action: "trix-initialize->trix-debug#ready" } %> "Hello" is selected when using 1.3.1 but not when using 2.0.7. As an additional clue, I discovered that adding this.element.editor.loadHTML("Hello world")
this.element.focus()
this.element.editor.setSelectedRange([0,5]) Adding |
Our team is updating our Rails 7.0.8 app to Trix 2.0.7 from 1.3.1, which introduced a failure in one of our system tests that calls
setSelectedRange
:On 1.3.1, this worked as expected; the text area was filled and then selection was moved to the end. On 2.0.7, the
setSelectedRange
call doesn't work; the selection stays at [0,0].I haven't been able to find the root cause, and haven't found a way to get
setSelectedRange
working, but replacingfill_in_rich_text_area
with Capybara'sset
method works around the issue:I'm curious if there's a known change to
loadHTML
(called byfill_in_rich_text_area
) orsetSelectedRange
in 2.x that might have caused this behavior, but I understand this isn't necessarily a Trix bug, so feel free to close this as you see fit. I mainly wanted to note the issue and workaround for anyone else who might encounter it.Details
The text was updated successfully, but these errors were encountered: