Skip to content
Open
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
6 changes: 4 additions & 2 deletions packages/super-editor/src/core/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2468,8 +2468,10 @@ export class Editor extends EventEmitter<EditorEventMap> {
updatedDocs['word/_rels/footnotes.xml.rels'] = String(footnotesRelsXml);
}

if (preparedComments.length) {
const commentsXml = this.converter.schemaToXml(this.converter.convertedXml['word/comments.xml'].elements[0]);
// Check if comment files exist in convertedXml (they're removed when cleaning or empty array)
const commentsFile = this.converter.convertedXml['word/comments.xml'];
if (commentsFile?.elements?.[0]) {
const commentsXml = this.converter.schemaToXml(commentsFile.elements[0]);
updatedDocs['word/comments.xml'] = String(commentsXml);

const commentsExtended = this.converter.convertedXml['word/commentsExtended.xml'];
Expand Down
17 changes: 8 additions & 9 deletions packages/super-editor/src/core/super-converter/SuperConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,17 +998,16 @@ class SuperConverter {
);

// Update content types and comments files as needed
// Always process comments - empty array means "export with no comments", not "preserve original"
let updatedXml = { ...this.convertedXml };
let commentsRels = [];
if (comments.length) {
const { documentXml, relationships } = this.#prepareCommentsXmlFilesForExport({
defs: params.exportedCommentDefs,
exportType: commentsExportType,
commentsWithParaIds,
});
updatedXml = { ...documentXml };
commentsRels = relationships;
}
const { documentXml, relationships } = this.#prepareCommentsXmlFilesForExport({
defs: params.exportedCommentDefs,
exportType: commentsExportType,
commentsWithParaIds,
});
updatedXml = { ...documentXml };
commentsRels = relationships;

this.convertedXml = { ...this.convertedXml, ...updatedXml };
Comment on lines +1009 to 1012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drop old comment parts when comments are empty

When commentsWithParaIds is empty, prepareCommentsXmlFilesForExport returns documentXml without comment parts, but the next assignment merges it back with this.convertedXml using a spread. Because spreads don’t delete missing keys, any existing word/comments*.xml entries remain in this.convertedXml, so exportDocx({ comments: [] }) still exports the previous comments (and Editor.ts now includes them when present). To actually remove comments, you’ll need to delete those keys or replace this.convertedXml with documentXml rather than merging.

Useful? React with 👍 / 👎.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ export const prepareCommentsXmlFilesForExport = ({
}) => {
const relationships = [];

if (exportType === 'clean') {
// Remove comment files if explicitly cleaning OR if no comments to export (empty array)
if (exportType === 'clean' || commentsWithParaIds.length === 0) {
const documentXml = removeCommentsFilesFromConvertedXml(convertedXml);
return { documentXml, relationships };
}
Expand Down
6 changes: 3 additions & 3 deletions packages/super-editor/src/extensions/search/SearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ export class SearchIndex {
* @returns {string} Regex pattern string
*/
static toFlexiblePattern(searchString) {
// Split by whitespace, escape each part, rejoin with \s+
const parts = searchString.split(/\s+/).filter((part) => part.length > 0);
// Split by whitespace (including non-breaking spaces), escape each part, rejoin with flexible whitespace pattern
const parts = searchString.split(/[\s\u00a0]+/).filter((part) => part.length > 0);
if (parts.length === 0) return '';
return parts.map((part) => SearchIndex.escapeRegex(part)).join('\\s+');
return parts.map((part) => SearchIndex.escapeRegex(part)).join('[\\s\\u00a0]+');
}

/**
Expand Down