-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content Model Bug fix: part 1 (#1370)
* Bug bash bug fix * fix test * improve
- Loading branch information
1 parent
86c3b2d
commit e4390e4
Showing
17 changed files
with
502 additions
and
177 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
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
22 changes: 22 additions & 0 deletions
22
packages/roosterjs-content-model/lib/modelToDom/handlers/handleBr.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,22 @@ | ||
import { applyFormat } from '../utils/applyFormat'; | ||
import { ContentModelBr } from '../../publicTypes/segment/ContentModelBr'; | ||
import { ContentModelHandler } from '../../publicTypes/context/ContentModelHandler'; | ||
import { ModelToDomContext } from '../../publicTypes/context/ModelToDomContext'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const handleBr: ContentModelHandler<ContentModelBr> = ( | ||
doc: Document, | ||
parent: Node, | ||
segment: ContentModelBr, | ||
context: ModelToDomContext | ||
) => { | ||
const br = doc.createElement('br'); | ||
const element = doc.createElement('span'); | ||
element.appendChild(br); | ||
parent.appendChild(element); | ||
|
||
context.regularSelection.current.segment = br; | ||
applyFormat(element, context.formatAppliers.segment, segment.format, context); | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/roosterjs-content-model/lib/modelToDom/handlers/handleGeneralModel.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,34 @@ | ||
import { applyFormat } from '../utils/applyFormat'; | ||
import { ContentModelGeneralBlock } from '../../publicTypes/block/group/ContentModelGeneralBlock'; | ||
import { ContentModelGeneralSegment } from '../../publicTypes/segment/ContentModelGeneralSegment'; | ||
import { ContentModelHandler } from '../../publicTypes/context/ContentModelHandler'; | ||
import { isNodeOfType } from '../../domUtils/isNodeOfType'; | ||
import { ModelToDomContext } from '../../publicTypes/context/ModelToDomContext'; | ||
import { NodeType } from 'roosterjs-editor-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const handleGeneralModel: ContentModelHandler<ContentModelGeneralBlock> = ( | ||
doc: Document, | ||
parent: Node, | ||
group: ContentModelGeneralBlock, | ||
context: ModelToDomContext | ||
) => { | ||
const newParent = group.element.cloneNode(); | ||
parent.appendChild(newParent); | ||
|
||
context.modelHandlers.blockGroupChildren(doc, newParent, group, context); | ||
|
||
if (isGeneralSegment(group) && isNodeOfType(newParent, NodeType.Element)) { | ||
if (!group.element.firstChild) { | ||
context.regularSelection.current.segment = newParent; | ||
} | ||
|
||
applyFormat(newParent, context.formatAppliers.segment, group.format, context); | ||
} | ||
}; | ||
|
||
function isGeneralSegment(block: ContentModelGeneralBlock): block is ContentModelGeneralSegment { | ||
return (block as ContentModelGeneralSegment).segmentType == 'General'; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
packages/roosterjs-content-model/lib/modelToDom/handlers/handleText.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,23 @@ | ||
import { applyFormat } from '../utils/applyFormat'; | ||
import { ContentModelHandler } from '../../publicTypes/context/ContentModelHandler'; | ||
import { ContentModelText } from '../../publicTypes/segment/ContentModelText'; | ||
import { ModelToDomContext } from '../../publicTypes/context/ModelToDomContext'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const handleText: ContentModelHandler<ContentModelText> = ( | ||
doc: Document, | ||
parent: Node, | ||
segment: ContentModelText, | ||
context: ModelToDomContext | ||
) => { | ||
const txt = doc.createTextNode(segment.text); | ||
const element = doc.createElement('span'); | ||
|
||
element.appendChild(txt); | ||
parent.appendChild(element); | ||
|
||
context.regularSelection.current.segment = txt; | ||
applyFormat(element, context.formatAppliers.segment, segment.format, context); | ||
}; |
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
Oops, something went wrong.