diff --git a/demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx b/demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx index 76e92e813c2..06f81255bd1 100644 --- a/demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx +++ b/demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx @@ -132,13 +132,57 @@ export class Plugins extends PluginsBase { private tableMenu = React.createRef(); private imageMenu = React.createRef(); private watermarkText = React.createRef(); + private autoBullet = React.createRef(); + private autoNumbering = React.createRef(); + private autoLink = React.createRef(); + private autoUnlink = React.createRef(); + private autoHyphen = React.createRef(); + private markdownBold = React.createRef(); + private markdownItalic = React.createRef(); + private markdownStrikethrough = React.createRef(); + private markdownCode = React.createRef(); private linkTitle = React.createRef(); render(): JSX.Element { return ( - {this.renderPluginItem('autoFormat', 'AutoFormat')} + {this.renderPluginItem( + 'autoFormat', + 'AutoFormat', + <> + {this.renderCheckBox( + 'Bullet', + this.autoBullet, + this.props.state.autoFormatOptions.autoBullet, + (state, value) => (state.autoFormatOptions.autoBullet = value) + )} + {this.renderCheckBox( + 'Numbering', + this.autoNumbering, + this.props.state.autoFormatOptions.autoNumbering, + (state, value) => (state.autoFormatOptions.autoNumbering = value) + )} + {this.renderCheckBox( + 'Link', + this.autoLink, + this.props.state.autoFormatOptions.autoLink, + (state, value) => (state.autoFormatOptions.autoLink = value) + )} + {this.renderCheckBox( + 'Unlink', + this.autoUnlink, + this.props.state.autoFormatOptions.autoUnlink, + (state, value) => (state.autoFormatOptions.autoUnlink = value) + )} + {this.renderCheckBox( + 'Hyphen', + this.autoHyphen, + this.props.state.autoFormatOptions.autoHyphen, + (state, value) => (state.autoFormatOptions.autoHyphen = value) + )} + + )} {this.renderPluginItem('edit', 'Edit')} {this.renderPluginItem( 'paste', @@ -190,6 +234,40 @@ export class Plugins extends PluginsBase { {this.renderPluginItem('emoji', 'Emoji')} {this.renderPluginItem('pasteOption', 'PasteOptions')} {this.renderPluginItem('sampleEntity', 'SampleEntity')} + {this.renderPluginItem( + 'markdown', + 'Markdown', + <> + {this.renderCheckBox( + 'Bold', + this.markdownBold, + this.props.state.markdownOptions.bold, + (state, value) => (state.markdownOptions.bold = value) + )} + {this.renderCheckBox( + 'Italic', + this.markdownItalic, + this.props.state.markdownOptions.italic, + (state, value) => (state.markdownOptions.italic = value) + )} + {this.renderCheckBox( + 'Strikethrough', + this.markdownStrikethrough, + this.props.state.markdownOptions.strikethrough, + (state, value) => (state.markdownOptions.strikethrough = value) + )} + + {this.renderCheckBox( + 'Code', + this.markdownCode, + this.props.state.markdownOptions.codeFormat !== undefined, + (state, value) => + value + ? (state.markdownOptions.codeFormat = {}) + : (state.markdownOptions.codeFormat = undefined) + )} + + )} {this.renderPluginItem( 'hyperlink', 'Hyperlink Plugin', diff --git a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts index 2f983dee8ce..bc8ff453042 100644 --- a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts @@ -131,7 +131,7 @@ export class AutoFormatPlugin implements EditorPlugin { case ' ': formatTextSegmentBeforeSelectionMarker( editor, - (model, previousSegment, paragraph, context) => { + (model, previousSegment, paragraph, _markerFormat, context) => { const { autoBullet, autoNumbering, diff --git a/packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts b/packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts index c314ca66601..efb6a333d9a 100644 --- a/packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts +++ b/packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts @@ -18,9 +18,15 @@ export function setFormat( ) { formatTextSegmentBeforeSelectionMarker( editor, - (_model, previousSegment, paragraph, context) => { + (_model, previousSegment, paragraph, markerFormat, context) => { if (previousSegment.text[previousSegment.text.length - 1] == character) { const textBeforeMarker = previousSegment.text.slice(0, -1); + context.newPendingFormat = { + ...markerFormat, + strikethrough: !!markerFormat.strikethrough, + italic: !!markerFormat.italic, + fontWeight: markerFormat?.fontWeight ? 'bold' : undefined, + }; if (textBeforeMarker.indexOf(character) > -1) { const lastCharIndex = previousSegment.text.length; const firstCharIndex = previousSegment.text diff --git a/packages/roosterjs-content-model-plugins/lib/pluginUtils/formatTextSegmentBeforeSelectionMarker.ts b/packages/roosterjs-content-model-plugins/lib/pluginUtils/formatTextSegmentBeforeSelectionMarker.ts index 62814ba6dff..d5a23a0c663 100644 --- a/packages/roosterjs-content-model-plugins/lib/pluginUtils/formatTextSegmentBeforeSelectionMarker.ts +++ b/packages/roosterjs-content-model-plugins/lib/pluginUtils/formatTextSegmentBeforeSelectionMarker.ts @@ -2,6 +2,7 @@ import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom'; import type { ContentModelDocument, ContentModelParagraph, + ContentModelSegmentFormat, ContentModelText, FormatContentModelContext, IEditor, @@ -16,6 +17,7 @@ export function formatTextSegmentBeforeSelectionMarker( model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, + markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext ) => boolean ) { @@ -32,7 +34,7 @@ export function formatTextSegmentBeforeSelectionMarker( if (marker.segmentType === 'SelectionMarker' && markerIndex > 0) { const previousSegment = paragraph.segments[markerIndex - 1]; if (previousSegment && previousSegment.segmentType === 'Text') { - return callback(model, previousSegment, paragraph, context); + return callback(model, previousSegment, paragraph, marker.format, context); } } } diff --git a/packages/roosterjs-content-model-plugins/test/pluginUtils/formatTextSegmentBeforeSelectionMarkerTest.ts b/packages/roosterjs-content-model-plugins/test/pluginUtils/formatTextSegmentBeforeSelectionMarkerTest.ts index 056199897f7..b032e57de5b 100644 --- a/packages/roosterjs-content-model-plugins/test/pluginUtils/formatTextSegmentBeforeSelectionMarkerTest.ts +++ b/packages/roosterjs-content-model-plugins/test/pluginUtils/formatTextSegmentBeforeSelectionMarkerTest.ts @@ -5,6 +5,7 @@ import { transformHyphen } from '../../lib/autoFormat/hyphen/transformHyphen'; import { ContentModelDocument, ContentModelParagraph, + ContentModelSegmentFormat, ContentModelText, FormatContentModelContext, } from 'roosterjs-content-model-types'; @@ -16,6 +17,7 @@ describe('formatTextSegmentBeforeSelectionMarker', () => { model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, + markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext ) => boolean, expectedModel: ContentModelDocument, @@ -203,7 +205,7 @@ describe('formatTextSegmentBeforeSelectionMarker - keyboardListTrigger', () => { focus: () => {}, formatContentModel: formatWithContentModelSpy, } as any, - (model, _previousSegment, paragraph, context) => { + (model, _previousSegment, paragraph, _markerFormat, context) => { return keyboardListTrigger(model, paragraph, context, autoBullet, autoNumbering); } ); @@ -1260,7 +1262,7 @@ describe('formatTextSegmentBeforeSelectionMarker - createLinkAfterSpace', () => focus: () => {}, formatContentModel: formatWithContentModelSpy, } as any, - (_model, previousSegment, paragraph, context) => { + (_model, previousSegment, paragraph, _markerFormat, context) => { return createLinkAfterSpace(previousSegment, paragraph, context); } ); @@ -1586,7 +1588,7 @@ describe('formatTextSegmentBeforeSelectionMarker - transformHyphen', () => { focus: () => {}, formatContentModel: formatWithContentModelSpy, } as any, - (_model, previousSegment, paragraph, context) => { + (_model, previousSegment, paragraph, _markerFormat, context) => { return transformHyphen(previousSegment, paragraph, context); } );