Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 45 additions & 35 deletions packages/ckeditor5/dist/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11494,14 +11494,16 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
if (!acceptedText.includes("$$")) {
return;
}
const openDelimIndex = acceptedText.indexOf("$$");
const closeDelimIndex = acceptedText.indexOf("$$", openDelimIndex + 2);
if (openDelimIndex === -1 || closeDelimIndex === -1) {
// To handle multiple LaTeX on same line.
const targetLatex = this.core.editionProperties.extractedLatex;
const fullLatex = `$$${targetLatex}$$`;
const startIndex = acceptedText.indexOf(fullLatex);
if (startIndex === -1) {
return;
}
const latexBoundaries = {
start: openDelimIndex,
end: closeDelimIndex + 2
start: startIndex,
end: startIndex + fullLatex.length
};
return this.convertAcceptedOffsetsToModelRange(textParts, latexBoundaries);
}
Expand Down Expand Up @@ -11604,41 +11606,22 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
* Handles track changes by simulating "accept all changes" before conversion.
*/ getMathmlFromTextNode(textNode, caretPosition) {
const standardResult = Latex.getLatexFromTextNode(textNode, caretPosition);
const acceptedLatex = this.extractAcceptedLatexFromDOM(textNode);
const acceptedLatex = this.extractAcceptedLatexFromDOM(textNode, caretPosition);
// Prioritize accepted LaTeX if it differs from standard extraction (for track changes compatibility).
const latex = acceptedLatex && acceptedLatex !== standardResult?.latex ? acceptedLatex : standardResult?.latex;
if (!latex && !acceptedLatex) {
return;
}
// Verify caret is inside LaTeX block for track changes edge cases.
if (!standardResult && acceptedLatex && !this.isCaretInsideLatexBlock(textNode)) {
if (!standardResult && acceptedLatex && !this.isCaretInsideLatexBlock(textNode, caretPosition)) {
return;
}
this.storeLatexRangeWithFallback(textNode, caretPosition, latex || acceptedLatex);
return Latex.getMathMLFromLatex(latex || acceptedLatex);
}
isCaretInsideLatexBlock(textNode) {
const container = this.findLatexContainerElement(textNode);
if (!container) {
return false;
}
const fullText = container.textContent || "";
const openDelim = fullText.indexOf("$$");
const closeDelim = fullText.indexOf("$$", openDelim + 2);
if (openDelim === -1 || closeDelim === -1) {
return false;
}
// Calculate text Node position within container.
let textPosition = 0;
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
let node;
while(node = walker.nextNode()){
if (node === textNode) {
return textPosition >= openDelim && textPosition <= closeDelim + 2;
}
textPosition += node.textContent?.length || 0;
}
return false;
isCaretInsideLatexBlock(textNode, caretPosition = 0) {
// If LaTeX is found, the caret is inside one.
return !!this.extractAcceptedLatexFromDOM(textNode, caretPosition);
}
/**
* Stores the LaTeX range for its replacement later.
Expand Down Expand Up @@ -11676,18 +11659,45 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
}
/**
* Extracts LaTeX from DOM, skipping track changes deletion markers.
*/ extractAcceptedLatexFromDOM(textNode) {
* @param {Node} textNode - The text node where the caret is located.
* @param {number} [caretPositionInNode=0] - The caret offset within the text node.
*/ extractAcceptedLatexFromDOM(textNode, caretPositionInNode = 0) {
const container = this.findLatexContainerElement(textNode);
if (!container) {
return;
}
const acceptedText = this.getAcceptedTextContent(container);
const openDelim = acceptedText.indexOf("$$");
const closeDelim = acceptedText.indexOf("$$", openDelim + 2);
if (openDelim === -1 || closeDelim === -1) {
return;
// Calculate caret offset that will be used later to find the correct LaTeX block.
// This includes all accepted text before textNode, plus the caret position within textNode.
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
let node = walker.nextNode();
let caretOffset = 0;
while(node && node !== textNode){
if (!node.parentElement?.classList?.contains("ck-suggestion-marker-deletion")) {
caretOffset += node.textContent?.length || 0;
}
node = walker.nextNode();
}
// Add the caret position within the text node (only if textNode is not deleted).
if (node === textNode && !textNode.parentElement?.classList?.contains("ck-suggestion-marker-deletion")) {
caretOffset += caretPositionInNode;
}
// Find the LaTeX block that contains the caret.
let searchStart = 0;
while(searchStart < acceptedText.length){
const openDelim = acceptedText.indexOf("$$", searchStart);
if (openDelim === -1) {
break;
}
const closeDelim = acceptedText.indexOf("$$", openDelim + 2);
if (closeDelim === -1) {
break;
}
if (caretOffset >= openDelim && caretOffset <= closeDelim + 2) {
return acceptedText.substring(openDelim + 2, closeDelim);
}
searchStart = closeDelim + 2;
}
return acceptedText.substring(openDelim + 2, closeDelim);
}
/**
* Recursively extracts text content, skipping track changes tags.
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5/dist/browser/index.js.map

Large diffs are not rendered by default.

80 changes: 45 additions & 35 deletions packages/ckeditor5/dist/browser/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11496,14 +11496,16 @@
if (!acceptedText.includes("$$")) {
return;
}
const openDelimIndex = acceptedText.indexOf("$$");
const closeDelimIndex = acceptedText.indexOf("$$", openDelimIndex + 2);
if (openDelimIndex === -1 || closeDelimIndex === -1) {
// To handle multiple LaTeX on same line.
const targetLatex = this.core.editionProperties.extractedLatex;
const fullLatex = `$$${targetLatex}$$`;
const startIndex = acceptedText.indexOf(fullLatex);
if (startIndex === -1) {
return;
}
const latexBoundaries = {
start: openDelimIndex,
end: closeDelimIndex + 2
start: startIndex,
end: startIndex + fullLatex.length
};
return this.convertAcceptedOffsetsToModelRange(textParts, latexBoundaries);
}
Expand Down Expand Up @@ -11606,41 +11608,22 @@
* Handles track changes by simulating "accept all changes" before conversion.
*/ getMathmlFromTextNode(textNode, caretPosition) {
const standardResult = Latex.getLatexFromTextNode(textNode, caretPosition);
const acceptedLatex = this.extractAcceptedLatexFromDOM(textNode);
const acceptedLatex = this.extractAcceptedLatexFromDOM(textNode, caretPosition);
// Prioritize accepted LaTeX if it differs from standard extraction (for track changes compatibility).
const latex = acceptedLatex && acceptedLatex !== standardResult?.latex ? acceptedLatex : standardResult?.latex;
if (!latex && !acceptedLatex) {
return;
}
// Verify caret is inside LaTeX block for track changes edge cases.
if (!standardResult && acceptedLatex && !this.isCaretInsideLatexBlock(textNode)) {
if (!standardResult && acceptedLatex && !this.isCaretInsideLatexBlock(textNode, caretPosition)) {
return;
}
this.storeLatexRangeWithFallback(textNode, caretPosition, latex || acceptedLatex);
return Latex.getMathMLFromLatex(latex || acceptedLatex);
}
isCaretInsideLatexBlock(textNode) {
const container = this.findLatexContainerElement(textNode);
if (!container) {
return false;
}
const fullText = container.textContent || "";
const openDelim = fullText.indexOf("$$");
const closeDelim = fullText.indexOf("$$", openDelim + 2);
if (openDelim === -1 || closeDelim === -1) {
return false;
}
// Calculate text Node position within container.
let textPosition = 0;
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
let node;
while(node = walker.nextNode()){
if (node === textNode) {
return textPosition >= openDelim && textPosition <= closeDelim + 2;
}
textPosition += node.textContent?.length || 0;
}
return false;
isCaretInsideLatexBlock(textNode, caretPosition = 0) {
// If LaTeX is found, the caret is inside one.
return !!this.extractAcceptedLatexFromDOM(textNode, caretPosition);
}
/**
* Stores the LaTeX range for its replacement later.
Expand Down Expand Up @@ -11678,18 +11661,45 @@
}
/**
* Extracts LaTeX from DOM, skipping track changes deletion markers.
*/ extractAcceptedLatexFromDOM(textNode) {
* @param {Node} textNode - The text node where the caret is located.
* @param {number} [caretPositionInNode=0] - The caret offset within the text node.
*/ extractAcceptedLatexFromDOM(textNode, caretPositionInNode = 0) {
const container = this.findLatexContainerElement(textNode);
if (!container) {
return;
}
const acceptedText = this.getAcceptedTextContent(container);
const openDelim = acceptedText.indexOf("$$");
const closeDelim = acceptedText.indexOf("$$", openDelim + 2);
if (openDelim === -1 || closeDelim === -1) {
return;
// Calculate caret offset that will be used later to find the correct LaTeX block.
// This includes all accepted text before textNode, plus the caret position within textNode.
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
let node = walker.nextNode();
let caretOffset = 0;
while(node && node !== textNode){
if (!node.parentElement?.classList?.contains("ck-suggestion-marker-deletion")) {
caretOffset += node.textContent?.length || 0;
}
node = walker.nextNode();
}
// Add the caret position within the text node (only if textNode is not deleted).
if (node === textNode && !textNode.parentElement?.classList?.contains("ck-suggestion-marker-deletion")) {
caretOffset += caretPositionInNode;
}
// Find the LaTeX block that contains the caret.
let searchStart = 0;
while(searchStart < acceptedText.length){
const openDelim = acceptedText.indexOf("$$", searchStart);
if (openDelim === -1) {
break;
}
const closeDelim = acceptedText.indexOf("$$", openDelim + 2);
if (closeDelim === -1) {
break;
}
if (caretOffset >= openDelim && caretOffset <= closeDelim + 2) {
return acceptedText.substring(openDelim + 2, closeDelim);
}
searchStart = closeDelim + 2;
}
return acceptedText.substring(openDelim + 2, closeDelim);
}
/**
* Recursively extracts text content, skipping track changes tags.
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5/dist/browser/index.umd.js.map

Large diffs are not rendered by default.

80 changes: 45 additions & 35 deletions packages/ckeditor5/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ckeditor5/dist/index.js.map

Large diffs are not rendered by default.

Loading
Loading