FIX: clear state if selected text is empty (#24102)

This would cause a loop and some very fast flashing of the selection in safari when scrolling the selection until the bottom of the page.
This commit is contained in:
Joffrey JAFFEUX 2023-10-25 22:15:30 +02:00 committed by GitHub
parent e231ed2153
commit 619d709d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,6 +95,14 @@ export default class PostTextSelection extends Component {
const _selectedText = selectedText();
const selection = window.getSelection();
if (selection.isCollapsed || _selectedText === "") {
if (!this.menuInstance?.expanded) {
this.args.quoteState.clear();
}
return;
}
// avoid hard loops in quote selection unconditionally
// this can happen if you triple click text in firefox
// it's also generally unecessary work to go
@ -108,14 +116,6 @@ export default class PostTextSelection extends Component {
this.prevSelectedText = _selectedText;
const selection = window.getSelection();
if (selection.isCollapsed) {
if (!this.menuInstance?.expanded) {
this.args.quoteState.clear();
}
return;
}
// ensure we selected content inside 1 post *only*
let postId;
for (let r = 0; r < selection.rangeCount; r++) {