mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
DEV: Fix triple click selection in WebKit derived browsers (#30628)
On WebKit-based browsers, triple clicking on the last paragraph of a post won't stop at the end of the paragraph, leaking the selection into the following nodes until it finds a non-empty node. This commit introduces a workaround to fix this behavior.
This commit is contained in:
@ -9,6 +9,7 @@ describe "Topic page", type: :system do
|
||||
<a name="toc-h2-testing" class="anchor" href="#toc-h2-testing">x</a>
|
||||
Testing
|
||||
</h2>
|
||||
<p id="test-last-cooked-paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempor.</p>
|
||||
HTML
|
||||
|
||||
it "allows TOC anchor navigation" do
|
||||
@ -98,4 +99,26 @@ describe "Topic page", type: :system do
|
||||
expect(find("#post_#{topic.highest_post_number}")).to be_visible
|
||||
end
|
||||
end
|
||||
|
||||
context "when triple clicking to select a paragraph" do
|
||||
it "select the last paragraph" do
|
||||
visit "/t/#{topic.slug}/#{topic.id}/1"
|
||||
|
||||
# select the last paragraph by triple clicking
|
||||
element = page.driver.browser.find_element(id: "test-last-cooked-paragraph")
|
||||
page.driver.browser.action.move_to(element).click.click.click.perform
|
||||
|
||||
# get the selected text in the browser
|
||||
select_content = page.evaluate_script("window.getSelection().toString()")
|
||||
|
||||
# the browser is returning control characters among the whiter space in the end of the text
|
||||
# this regex will work as a .rstrip on steroids and remove them
|
||||
select_content.gsub!(/[\s\p{Cf}]+$/, "")
|
||||
|
||||
# compare the selected text with the last paragraph
|
||||
expect(select_content).to eq(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempor.",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user