Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Apr 2, 2024

AutoFormat plugin is responsible for formatting two dashes into a hyphen. This feature was ported into content model AutoFormatPlugin.
autoHyphen

@juliaroldi juliaroldi changed the title Port Auto Hyphen Port AutoFormat into content model AutoFormatPlugin Apr 3, 2024
@juliaroldi juliaroldi marked this pull request as ready for review April 3, 2024 16:54
@JiuqingSong
Copy link
Collaborator

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) => {
Copy link
Collaborator

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?

Copy link
Contributor Author

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(
Copy link
Collaborator

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.

@juliaroldi
Copy link
Contributor Author

In old plugin, auto hyphen happens when we type anything after "--", but here it only happens when we type space. Is that expected?
I changed the behavior to match word behavior, that only transforms the hyphen after space.

@JiuqingSong
Copy link
Collaborator

In old plugin, auto hyphen happens when we type anything after "--", but here it only happens when we type space. Is that expected?
I changed the behavior to match word behavior, that only transforms the hyphen after space.

I see, sounds good.

/**
* @internal
*/
export function formatTextSegmentBeforeSelectionMarker(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good

Comment on lines 132 to +138
keyboardListTrigger(editor, autoBullet, autoNumbering);
if (autoLink) {
createLinkAfterSpace(editor);
}
if (autoHyphen) {
transformHyphen(editor);
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@juliaroldi juliaroldi closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants