mirror of
https://github.com/docmost/docmost.git
synced 2026-05-06 22:03:06 +08:00
fix: prevent code block deletion when adding inline comments in read mode (#2146)
This commit is contained in:
committed by
GitHub
parent
fcef0c6b96
commit
fe18f22dc6
@@ -62,14 +62,14 @@ function applyMarkToYFragment(
|
|||||||
) {
|
) {
|
||||||
let pos = 0;
|
let pos = 0;
|
||||||
|
|
||||||
const processItem = (item: any): boolean => {
|
const processItem = (item: any, parentNodeName?: string): boolean => {
|
||||||
if (pos >= to) return false;
|
if (pos >= to) return false;
|
||||||
|
|
||||||
if (item instanceof Y.XmlText) {
|
if (item instanceof Y.XmlText) {
|
||||||
const textLength = item.length;
|
const textLength = item.length;
|
||||||
const itemEnd = pos + textLength;
|
const itemEnd = pos + textLength;
|
||||||
|
|
||||||
if (itemEnd > from && pos < to) {
|
if (itemEnd > from && pos < to && parentNodeName !== 'codeBlock') {
|
||||||
const formatFrom = Math.max(0, from - pos);
|
const formatFrom = Math.max(0, from - pos);
|
||||||
const formatTo = Math.min(textLength, to - pos);
|
const formatTo = Math.min(textLength, to - pos);
|
||||||
const formatLength = formatTo - formatFrom;
|
const formatLength = formatTo - formatFrom;
|
||||||
@@ -82,7 +82,7 @@ function applyMarkToYFragment(
|
|||||||
} else if (item instanceof Y.XmlElement) {
|
} else if (item instanceof Y.XmlElement) {
|
||||||
pos++; // Opening tag
|
pos++; // Opening tag
|
||||||
for (let i = 0; i < item.length; i++) {
|
for (let i = 0; i < item.length; i++) {
|
||||||
if (!processItem(item.get(i))) return false;
|
if (!processItem(item.get(i), item.nodeName)) return false;
|
||||||
}
|
}
|
||||||
pos++; // Closing tag
|
pos++; // Closing tag
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user