Skip to content

Commit d24ce86

Browse files
committed
fix: refactor code fix
1 parent 4f283b6 commit d24ce86

1 file changed

Lines changed: 3 additions & 18 deletions

File tree

packages/super-editor/src/extensions/comment/comments-plugin.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Plugin, PluginKey } from 'prosemirror-state';
2-
import { TextSelection } from 'prosemirror-state';
1+
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
32
import { Extension } from '@core/Extension.js';
43
import { Decoration, DecorationSet } from 'prosemirror-view';
54
import { removeCommentsById, getHighlightColor } from './comments-helpers.js';
@@ -237,28 +236,21 @@ export const CommentsPlugin = Extension.create({
237236
shouldUpdate = true;
238237
}
239238

240-
if (prevActiveThreadId !== currentActiveThreadId) {
241-
shouldUpdate = true;
242-
prevActiveThreadId = currentActiveThreadId;
243-
}
244-
245239
// Check if document changed
246240
if (prevDoc && !prevDoc.eq(doc)) shouldUpdate = true;
247241

248-
// Check if active thread changed - this is the key fix
242+
// Check if active thread changed
249243
if (prevActiveThreadId !== currentActiveThreadId) {
250244
shouldUpdate = true;
251245
prevActiveThreadId = currentActiveThreadId;
252246
}
253247

254248
if (!shouldUpdate) return;
255-
256249
prevDoc = doc;
257250
shouldUpdate = false;
258251

259252
const decorations = [];
260253
const allCommentPositions = {};
261-
262254
doc.descendants((node, pos) => {
263255
const { marks = [] } = node;
264256
const commentMarks = marks.filter((mark) => mark.type.name === CommentMarkName);
@@ -289,11 +281,6 @@ export const CommentsPlugin = Extension.create({
289281
editor,
290282
});
291283

292-
// Debug logging to verify color calculation
293-
if (currentActiveThreadId === threadId) {
294-
console.log('Active comment color:', { threadId, color, isInternal, currentActiveThreadId });
295-
}
296-
297284
const deco = Decoration.inline(pos, pos + node.nodeSize, {
298285
style: `background-color: ${color};`,
299286
'data-thread-id': threadId,
@@ -321,7 +308,7 @@ export const CommentsPlugin = Extension.create({
321308
currentBounds,
322309
node,
323310
});
324-
// Add decoration for tracked changes
311+
// Add decoration for tracked changes when activated
325312
const isActiveTrackedChange = currentActiveThreadId === id;
326313
if (isActiveTrackedChange) {
327314
const trackedChangeDeco = Decoration.inline(pos, pos + node.nodeSize, {
@@ -674,13 +661,11 @@ function findRangeById(doc, id) {
674661
let from = null,
675662
to = null;
676663
doc.descendants((node, pos) => {
677-
// Check for tracked change marks
678664
const trackedMark = node.marks.find((m) => TRACK_CHANGE_MARKS.includes(m.type.name) && m.attrs.id === id);
679665
if (trackedMark) {
680666
if (from === null || pos < from) from = pos;
681667
if (to === null || pos + node.nodeSize > to) to = pos + node.nodeSize;
682668
}
683-
// Check for comment marks
684669
const commentMark = node.marks.find(
685670
(m) => m.type.name === CommentMarkName && (m.attrs.commentId === id || m.attrs.importedId === id),
686671
);

0 commit comments

Comments
 (0)