FIX: Quoting text selection across elements (#22974)

Regressed in https://github.com/discourse/discourse/pull/22802

Tests to follow next week
This commit is contained in:
Jarek Radosz 2023-08-04 08:30:56 +02:00 committed by GitHub
parent 5d1a9a44c6
commit 28dc222e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -123,7 +123,10 @@ export function selectedText() {
const div = document.createElement("div");
for (let r = 0; r < selection.rangeCount; r++) {
const range = selection.getRangeAt(r);
const ancestor = range.commonAncestorContainer.parentElement;
const ancestor =
range.commonAncestorContainer.nodeType === Node.ELEMENT_NODE
? range.commonAncestorContainer
: range.commonAncestorContainer.parentElement;
// ensure we never quote text in the post menu area
const postMenuArea = ancestor.querySelector(".post-menu-area");