Skip to content

A platform for community discussion. Free, open, simple.

PERF: attempts to resort to compute markdown in less cases (#15762)

Joffrey JAFFEUXc0e2a01d9f7c
diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js
index b4002f8604e..a8a4de73de5 100644
--- a/app/assets/javascripts/discourse/app/components/quote-button.js
+++ b/app/assets/javascripts/discourse/app/components/quote-button.js
@@ -5,6 +5,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import {
postUrl,
selectedElement,
+ selectedRange,
selectedText,
setCaretPosition,
translateModKey,
@@ -164,10 +165,14 @@ export default Component.extend(KeyEnterEscape, {
const cooked =
$selectedElement.find(".cooked")[0] ||
$selectedElement.closest(".cooked")[0];
- const postBody = toMarkdown(cooked.innerHTML);
+ // computing markdown takes a lot of time on long posts
+ // this code attempts to compute it only when we can't fast track
let opts = {
- full: _selectedText === postBody,
+ full:
+ selectedRange().startOffset > 0
+ ? false
+ : _selectedText === toMarkdown(cooked.innerHTML),
};
for (
diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js
index dff0909873a..ddb80fafb2a 100644
--- a/app/assets/javascripts/discourse/app/lib/utilities.js
+++ b/app/assets/javascripts/discourse/app/lib/utilities.js
@@ -207,9 +207,13 @@ export function selectedText() {
}
export function selectedElement() {
+ return selectedRange()?.commonAncestorContainer;
+}
+
+export function selectedRange() {
const selection = window.getSelection();
if (selection.rangeCount > 0) {
- return selection.getRangeAt(0).commonAncestorContainer;
+ return selection.getRangeAt(0);
}
}