-
Notifications
You must be signed in to change notification settings - Fork 165
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
Port AutoFormat into content model AutoFormatPlugin #2552
Conversation
…rosoft/roosterjs into u/juliaroldi/auto-hypen-port
In old plugin, auto hyphen happens when we type anything after "--", but here it only happens when we type space. Is that expected? |
* @internal | ||
*/ | ||
export function transformHyphen(editor: IEditor) { | ||
editor.formatContentModel((model, context) => { |
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.
A little concerned about we call formatContentModel so many times for a single input. Can we just merge them into a single call?
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.
I think we can merge them. I'll create a function to format the segment before the marker that can be common to autoformat and markdown.
*/ | ||
export function transformHyphen(editor: IEditor) { | ||
editor.formatContentModel((model, context) => { | ||
const selectedAndParagraphs = getSelectedSegmentsAndParagraphs( |
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.
Then this result can also be shared.
|
I see, sounds good. |
…rosoft/roosterjs into u/juliaroldi/auto-hypen-port
/** | ||
* @internal | ||
*/ | ||
export function formatTextSegmentBeforeSelectionMarker( |
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.
this is good
keyboardListTrigger(editor, autoBullet, autoNumbering); | ||
if (autoLink) { | ||
createLinkAfterSpace(editor); | ||
} | ||
if (autoHyphen) { | ||
transformHyphen(editor); | ||
} |
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.
Can we call formatTextSegmentBeforeSelectionMarker
here, then call keyboardListTrigger
, createLinkAfterSpace
, transformHyphen
inside it? So that we only need to format with Content Model once.
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.
I created a separated PR: #2557 for it, since I needed to change a lot of files.
AutoFormat plugin is responsible for formatting two dashes into a hyphen. This feature was ported into content model AutoFormatPlugin.