Skip to content

Commit 8d37ccd

Browse files
committed
Floating comments updates and fixes
1 parent 7f94536 commit 8d37ccd

8 files changed

Lines changed: 314 additions & 454 deletions

File tree

packages/super-editor/src/core/Editor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ export class Editor extends EventEmitter {
363363
...options,
364364
};
365365

366-
if (!this.view || !this.state || this.isDestroyed) {
366+
if (this.options.isNewFile && this.options.isCommentsEnabled) {
367+
this.options.shouldLoadComments = true;
368+
}
369+
370+
if (!this.view || !this.state || this.ifsDestroyed) {
367371
return;
368372
}
369373

@@ -727,6 +731,7 @@ export class Editor extends EventEmitter {
727731
#initComments(replacedFile = false) {
728732
if (!this.options.isCommentsEnabled) return;
729733
if (this.options.isHeadless) return;
734+
if (!this.options.shouldLoadComments) return;
730735
this.emit('commentsLoaded', { editor: this, replacedFile, comments: this.converter.comments || [] });
731736

732737
setTimeout(() => {
@@ -1077,7 +1082,8 @@ export class Editor extends EventEmitter {
10771082
media,
10781083
mediaFiles,
10791084
fonts,
1080-
isNewFile: true
1085+
isNewFile: true,
1086+
shouldLoadComments: true,
10811087
});
10821088

10831089
this.#createConverter();

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommentMarkName } from './comments-constants.js';
22
import { COMMENTS_XML_DEFINITIONS } from '@converter/exporter-docx-defs.js';
3-
3+
import { CommentsPluginKey } from './comments-plugin.js';
44

55
/**
66
* Remove comment by id
@@ -274,3 +274,21 @@ export const translateFormatChangesToEnglish = (attrs = {}) => {
274274

275275
return messages.length ? messages.join('. ') : 'No formatting changes.';
276276
};
277+
278+
/**
279+
* Get the highlight color for a comment or tracked changes node
280+
*
281+
* @param {Object} param0
282+
* @param {String} param0.activeThreadId The active comment ID
283+
* @param {String} param0.threadId The current thread ID
284+
* @param {Boolean} param0.isInternal Whether the comment is internal or external
285+
* @param {EditorView} param0.editor The current editor view
286+
* @returns {String} The color to use for the highlight
287+
*/
288+
export const getHighlightColor = ({ activeThreadId, threadId, isInternal, editor }) => {
289+
if (!editor.options.isInternal && isInternal) return 'transparent';
290+
const pluginState = CommentsPluginKey.getState(editor.state);
291+
const color = isInternal ? pluginState.internalColor : pluginState.externalColor;
292+
const alpha = activeThreadId == threadId ? '44' : '22';
293+
return `${color}${alpha}`;
294+
}

0 commit comments

Comments
 (0)