From fe18f22dc685c4406d0715eb271052ec2581e0d1 Mon Sep 17 00:00:00 2001 From: Sarthak Chaturvedi <84394327+mayhemking007@users.noreply.github.com> Date: Tue, 5 May 2026 01:44:21 +0530 Subject: [PATCH] fix: prevent code block deletion when adding inline comments in read mode (#2146) --- apps/server/src/collaboration/yjs.util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/server/src/collaboration/yjs.util.ts b/apps/server/src/collaboration/yjs.util.ts index 863b149a..c79e5331 100644 --- a/apps/server/src/collaboration/yjs.util.ts +++ b/apps/server/src/collaboration/yjs.util.ts @@ -62,14 +62,14 @@ function applyMarkToYFragment( ) { let pos = 0; - const processItem = (item: any): boolean => { + const processItem = (item: any, parentNodeName?: string): boolean => { if (pos >= to) return false; if (item instanceof Y.XmlText) { const textLength = item.length; const itemEnd = pos + textLength; - if (itemEnd > from && pos < to) { + if (itemEnd > from && pos < to && parentNodeName !== 'codeBlock') { const formatFrom = Math.max(0, from - pos); const formatTo = Math.min(textLength, to - pos); const formatLength = formatTo - formatFrom; @@ -82,7 +82,7 @@ function applyMarkToYFragment( } else if (item instanceof Y.XmlElement) { pos++; // Opening tag 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 }