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

Fix AutorFormat #2549

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const initialState: OptionState = {
imageMenu: true,
tableMenu: true,
listMenu: true,
autoFormatOptions: {
autoBullet: true,
autoLink: true,
autoNumbering: true,
autoUnlink: false,
},
markdownOptions: {
bold: true,
italic: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkdownOptions } from 'roosterjs-content-model-plugins';
import { AutoFormatOptions, MarkdownOptions } from 'roosterjs-content-model-plugins';
import type { ContentEditFeatureSettings } from 'roosterjs-editor-types';
import type { SidePaneElementProps } from '../SidePaneElement';
import type { ContentModelSegmentFormat } from 'roosterjs-content-model-types';
Expand Down Expand Up @@ -36,6 +36,7 @@ export interface OptionState {
tableMenu: boolean;
imageMenu: boolean;
watermarkText: string;
autoFormatOptions: AutoFormatOptions;
markdownOptions: MarkdownOptions;

// Legacy plugin options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class OptionsPane extends React.Component<OptionPaneProps, OptionState> {
listMenu: this.state.listMenu,
tableMenu: this.state.tableMenu,
imageMenu: this.state.imageMenu,
autoFormatOptions: { ...this.state.autoFormatOptions },
markdownOptions: { ...this.state.markdownOptions },
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AutoFormatOptions } from 'roosterjs-content-model-plugins';
import { CodeElement } from './CodeElement';

export class AutoFormatCode extends CodeElement {
constructor(private options: AutoFormatOptions) {
super();
}

getCode() {
return `new roosterjs.AutoFormatPlugin({
autoBullet: ${this.options.autoBullet},
autoLink: ${this.options.autoLink},
autoNumbering: ${this.options.autoNumbering},
autoUnlink: ${this.options.autoUnlink},
})`;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AutoFormatCode } from './AutoFormatCode';
import { CodeElement } from './CodeElement';
import { ContentEditCode } from './ContentEditCode';
import { HyperLinkCode } from './HyperLinkCode';
import { MarkdownCode } from './MarkdownCode';
import { OptionState } from '../OptionState';
import { WatermarkCode } from './WatermarkCode';
import {
AutoFormatPluginCode,
CustomReplaceCode,
EditPluginCode,
ImageEditCode,
Expand Down Expand Up @@ -39,7 +39,7 @@ export class PluginsCode extends PluginsCodeBase {
const pluginList = state.pluginList;

super([
pluginList.autoFormat && new AutoFormatPluginCode(),
pluginList.autoFormat && new AutoFormatCode(state.autoFormatOptions),
pluginList.edit && new EditPluginCode(),
pluginList.paste && new PastePluginCode(),
pluginList.tableEdit && new TableEditPluginCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class SimplePluginCode extends CodeElement {
}
}

export class AutoFormatPluginCode extends SimplePluginCode {
constructor() {
super('AutoFormatPlugin');
}
}

export class EditPluginCode extends SimplePluginCode {
constructor() {
super('EditPlugin');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getListTypeStyle(
listMarkerSegment &&
listMarkerSegment.segmentType == 'Text'
) {
const listMarker = listMarkerSegment.text;
const listMarker = listMarkerSegment.text.trim();
const bulletType = bulletListType[listMarker];

if (bulletType && shouldSearchForBullet) {
Expand Down Expand Up @@ -125,7 +125,7 @@ const bulletListType: Record<string, number> = {
};

const isNewList = (listMarker: string) => {
const marker = listMarker.replace(/[^\w\s]/g, '').trim();
const marker = listMarker.replace(/[^\w\s]/g, '');
const pattern = /^[1aAiI]$/;
return pattern.test(marker);
};
Loading