-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3bc1f3
commit 50d7834
Showing
8 changed files
with
158 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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
41 changes: 41 additions & 0 deletions
41
packages/roosterjs-content-model-dom/lib/modelToDom/handlers/handleSegments.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { ContentModelParagraph, ModelToDomContext } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function handleSegments( | ||
doc: Document, | ||
parent: Node, | ||
paragraph: ContentModelParagraph, | ||
context: ModelToDomContext | ||
) { | ||
const firstSegment = paragraph.segments[0]; | ||
|
||
if (firstSegment?.segmentType == 'SelectionMarker') { | ||
// Make sure there is a segment created before selection marker. | ||
// If selection marker is the first selected segment in a paragraph, create a dummy text node, | ||
// so after rewrite, the regularSelection object can have a valid segment object set to the text node. | ||
context.modelHandlers.text( | ||
doc, | ||
parent, | ||
{ | ||
...firstSegment, | ||
segmentType: 'Text', | ||
text: '', | ||
}, | ||
context, | ||
[] | ||
); | ||
} | ||
|
||
paragraph.segments.forEach(segment => { | ||
const newSegments: Node[] = []; | ||
context.modelHandlers.segment(doc, parent, segment, context, newSegments); | ||
|
||
newSegments.forEach(node => { | ||
context.domIndexer?.onSegment(node, paragraph, [segment]); | ||
}); | ||
}); | ||
|
||
delete context.textContext; | ||
} |
This file contains 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 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 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
26 changes: 26 additions & 0 deletions
26
packages/roosterjs-content-model-types/lib/context/ModelToDomTextContext.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ContentModelText } from '../contentModel/segment/ContentModelText'; | ||
|
||
/** | ||
* | ||
*/ | ||
export interface ModelToDomTextContextItem { | ||
/** | ||
* | ||
*/ | ||
lastSegment: ContentModelText; | ||
|
||
/** | ||
* | ||
*/ | ||
lastTextNode: Text; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
export interface ModelToDomTextContext { | ||
/** | ||
* | ||
*/ | ||
textContext?: ModelToDomTextContextItem; | ||
} |
This file contains 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