mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 05:21:50 +08:00
PERF: attempts to resort to compute markdown in less cases (#15762)
This commit is contained in:
parent
3f694e4ab5
commit
c0e2a01d9f
|
@ -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 (
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user