-
Notifications
You must be signed in to change notification settings - Fork 152
fix: track new lines in suggested mode #3600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
harbournick
wants to merge
1
commit into
main
from
nick/it-1136-track-changes-paragraph-split-enter-and-paragraph-style
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,66 @@ | ||||||||||||||
| import { carbonCopy } from '@core/utilities/carbonCopy.js'; | ||||||||||||||
| import { translator as wPPrNodeTranslator } from '../../pPr/pPr-translator.js'; | ||||||||||||||
| import { createParagraphSplitInsertionElement, isParagraphSplitTrackFormatMark } from '../../../helpers.js'; | ||||||||||||||
|
|
||||||||||||||
| function resolveExportPartPath(params = {}) { | ||||||||||||||
| if (typeof params.currentPartPath === 'string' && params.currentPartPath.length > 0) return params.currentPartPath; | ||||||||||||||
| if (typeof params.filename === 'string' && params.filename.length > 0) { | ||||||||||||||
| return params.filename.startsWith('word/') ? params.filename : `word/${params.filename}`; | ||||||||||||||
| } | ||||||||||||||
| return 'word/document.xml'; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function findParagraphSplitTrackFormatMark(node) { | ||||||||||||||
| if (!node || typeof node !== 'object') return null; | ||||||||||||||
|
|
||||||||||||||
| const marks = Array.isArray(node.marks) ? node.marks : []; | ||||||||||||||
| const directMark = marks.find((mark) => isParagraphSplitTrackFormatMark(mark)); | ||||||||||||||
| if (directMark) return directMark; | ||||||||||||||
|
|
||||||||||||||
| if (typeof node.descendants === 'function') { | ||||||||||||||
| let found = null; | ||||||||||||||
| node.descendants((child) => { | ||||||||||||||
| const childMarks = Array.isArray(child?.marks) ? child.marks : []; | ||||||||||||||
| found = childMarks.find((mark) => isParagraphSplitTrackFormatMark(mark)) || null; | ||||||||||||||
| return !found; | ||||||||||||||
| }); | ||||||||||||||
| if (found) return found; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const content = Array.isArray(node.content) ? node.content : []; | ||||||||||||||
| for (const child of content) { | ||||||||||||||
| const childMark = findParagraphSplitTrackFormatMark(child); | ||||||||||||||
| if (childMark) return childMark; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return null; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function ensureParagraphPropertiesNode(pPr) { | ||||||||||||||
| return ( | ||||||||||||||
| pPr || { | ||||||||||||||
| type: 'element', | ||||||||||||||
| name: 'w:pPr', | ||||||||||||||
| elements: [], | ||||||||||||||
| } | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function prependParagraphSplitInsertion(pPr, insertionElement) { | ||||||||||||||
| if (!pPr || !insertionElement) return pPr; | ||||||||||||||
| if (!Array.isArray(pPr.elements)) pPr.elements = []; | ||||||||||||||
| const existingRunProperties = pPr.elements.find((element) => element?.name === 'w:rPr'); | ||||||||||||||
| const runProperties = existingRunProperties || { | ||||||||||||||
| type: 'element', | ||||||||||||||
| name: 'w:rPr', | ||||||||||||||
| elements: [], | ||||||||||||||
| }; | ||||||||||||||
| if (!Array.isArray(runProperties.elements)) runProperties.elements = []; | ||||||||||||||
| const hasParagraphInsertion = runProperties.elements.some((element) => element?.name === 'w:ins'); | ||||||||||||||
| if (!hasParagraphInsertion) runProperties.elements.unshift(insertionElement); | ||||||||||||||
| if (!existingRunProperties) pPr.elements.unshift(runProperties); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||||||||||
| return pPr; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Generate the w:pPr props for a paragraph node | ||||||||||||||
|
|
@@ -33,7 +94,23 @@ export function generateParagraphProperties(params) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const paragraphSplitTrackFormatMark = findParagraphSplitTrackFormatMark(node); | ||||||||||||||
| const paragraphSplitWordIdOptions = paragraphSplitTrackFormatMark | ||||||||||||||
| ? { | ||||||||||||||
| wordIdAllocator: params?.converter?.wordIdAllocator || null, | ||||||||||||||
| partPath: resolveExportPartPath(params), | ||||||||||||||
| } | ||||||||||||||
| : null; | ||||||||||||||
| let pPr = wPPrNodeTranslator.decode({ node: { ...node, attrs: { paragraphProperties } } }); | ||||||||||||||
| if (!params?.isFinalDoc && paragraphSplitTrackFormatMark) { | ||||||||||||||
| const insertionElement = createParagraphSplitInsertionElement( | ||||||||||||||
| paragraphSplitTrackFormatMark, | ||||||||||||||
| paragraphSplitWordIdOptions, | ||||||||||||||
| ); | ||||||||||||||
| if (insertionElement) { | ||||||||||||||
| pPr = prependParagraphSplitInsertion(ensureParagraphPropertiesNode(pPr), insertionElement); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| const sectPr = node.attrs?.paragraphProperties?.sectPr; | ||||||||||||||
| if (sectPr) { | ||||||||||||||
| if (!pPr) { | ||||||||||||||
|
|
||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Descendant traversal can clear a previously found paragraph-split mark, causing paragraph split tracking to be skipped.
Prompt for AI agents