diff --git a/demo/scripts/controls/sidePane/editorOptions/ContentModelEditorOptionsPlugin.ts b/demo/scripts/controls/sidePane/editorOptions/ContentModelEditorOptionsPlugin.ts index 36c0169e7b5..78d964f43d7 100644 --- a/demo/scripts/controls/sidePane/editorOptions/ContentModelEditorOptionsPlugin.ts +++ b/demo/scripts/controls/sidePane/editorOptions/ContentModelEditorOptionsPlugin.ts @@ -29,7 +29,6 @@ const initialState: BuildInPluginState = { watermarkText: 'Type content here ...', forcePreserveRatio: false, experimentalFeatures: [ - ExperimentalFeatures.AutoFormatList, ExperimentalFeatures.InlineEntityReadOnlyDelimiters, ExperimentalFeatures.ContentModelPaste, ], diff --git a/demo/scripts/controls/sidePane/editorOptions/ContentModelExperimentalFeatures.tsx b/demo/scripts/controls/sidePane/editorOptions/ContentModelExperimentalFeatures.tsx index bcb2cabe1b6..97f1f8df0b6 100644 --- a/demo/scripts/controls/sidePane/editorOptions/ContentModelExperimentalFeatures.tsx +++ b/demo/scripts/controls/sidePane/editorOptions/ContentModelExperimentalFeatures.tsx @@ -10,8 +10,6 @@ export interface ExperimentalFeaturesProps { const FeatureNames: Partial> = { [ExperimentalFeatures.TabKeyTextFeatures]: 'Additional functionality to Tab Key', - [ExperimentalFeatures.AutoFormatList]: - 'Trigger formatting by a especial characters. Ex: (A), 1. i).', [ExperimentalFeatures.ReuseAllAncestorListElements]: "Reuse ancestor list elements even if they don't match the types from the list item.", [ExperimentalFeatures.DeleteTableWithBackspace]: diff --git a/demo/scripts/controls/sidePane/editorOptions/EditorOptionsPlugin.ts b/demo/scripts/controls/sidePane/editorOptions/EditorOptionsPlugin.ts index 3deb1f82968..efc0aa9a051 100644 --- a/demo/scripts/controls/sidePane/editorOptions/EditorOptionsPlugin.ts +++ b/demo/scripts/controls/sidePane/editorOptions/EditorOptionsPlugin.ts @@ -28,10 +28,7 @@ const initialState: BuildInPluginState = { linkTitle: 'Ctrl+Click to follow the link:' + UrlPlaceholder, watermarkText: 'Type content here ...', forcePreserveRatio: false, - experimentalFeatures: [ - ExperimentalFeatures.AutoFormatList, - ExperimentalFeatures.InlineEntityReadOnlyDelimiters, - ], + experimentalFeatures: [ExperimentalFeatures.InlineEntityReadOnlyDelimiters], isRtl: false, tableFeaturesContainerSelector: '#' + 'EditorContainer', }; diff --git a/demo/scripts/controls/sidePane/editorOptions/ExperimentalFeatures.tsx b/demo/scripts/controls/sidePane/editorOptions/ExperimentalFeatures.tsx index 31fed768291..21bbb750c59 100644 --- a/demo/scripts/controls/sidePane/editorOptions/ExperimentalFeatures.tsx +++ b/demo/scripts/controls/sidePane/editorOptions/ExperimentalFeatures.tsx @@ -10,8 +10,6 @@ export interface ExperimentalFeaturesProps { const FeatureNames: Partial> = { [ExperimentalFeatures.TabKeyTextFeatures]: 'Additional functionality to Tab Key', - [ExperimentalFeatures.AutoFormatList]: - 'Trigger formatting by a especial characters. Ex: (A), 1. i).', [ExperimentalFeatures.ReuseAllAncestorListElements]: "Reuse ancestor list elements even if they don't match the types from the list item.", [ExperimentalFeatures.DeleteTableWithBackspace]: diff --git a/packages/roosterjs-editor-api/lib/utils/toggleListType.ts b/packages/roosterjs-editor-api/lib/utils/toggleListType.ts index 4ce85d3aa84..e268bf7deba 100644 --- a/packages/roosterjs-editor-api/lib/utils/toggleListType.ts +++ b/packages/roosterjs-editor-api/lib/utils/toggleListType.ts @@ -64,9 +64,7 @@ export default function toggleListType( if (vList && start && end) { vList.changeListType(start, end, listType); - if (editor.isFeatureEnabled(ExperimentalFeatures.AutoFormatList)) { - vList.setListStyleType(orderedStyle, unorderedStyle); - } + vList.setListStyleType(orderedStyle, unorderedStyle); vList.writeBack( editor.isFeatureEnabled(ExperimentalFeatures.ReuseAllAncestorListElements), editor.isFeatureEnabled(ExperimentalFeatures.DisableListChain) diff --git a/packages/roosterjs-editor-api/test/utils/toggleListTypeTest.ts b/packages/roosterjs-editor-api/test/utils/toggleListTypeTest.ts index 4321b3066eb..db43cb22ac7 100644 --- a/packages/roosterjs-editor-api/test/utils/toggleListTypeTest.ts +++ b/packages/roosterjs-editor-api/test/utils/toggleListTypeTest.ts @@ -32,7 +32,7 @@ describe('toggleListTypeTest()', () => { // Assert expect(editor.getContent()).toBe( - '
default format

  • test
' + '
default format

  • test
' ); }); @@ -53,7 +53,7 @@ describe('toggleListTypeTest()', () => { // Assert expect(editor.getContent()).toBe( - '
default format

  • test
  • test
' + '
default format

  • test
  • test
' ); }); @@ -74,12 +74,7 @@ describe('toggleListTypeTest()', () => { // Assert expect(editor.getContent()).toBe( - '
default format
' + - '

' + - '
' + - '
  • test
  • test
' + - '

' + - '
' + '
default format

  • test
  • test

' ); }); @@ -100,13 +95,7 @@ describe('toggleListTypeTest()', () => { // Assert expect(editor.getContent()).toBe( - '
default format
' + - '

' + - '
' + - '
  • test
' + - '

' + - '
  • test
' + - '
' + '
default format

  • test

  • test
' ); }); }); diff --git a/packages/roosterjs-editor-plugins/lib/plugins/ContentEdit/features/listFeatures.ts b/packages/roosterjs-editor-plugins/lib/plugins/ContentEdit/features/listFeatures.ts index 0b262fd1970..80533c6c19b 100644 --- a/packages/roosterjs-editor-plugins/lib/plugins/ContentEdit/features/listFeatures.ts +++ b/packages/roosterjs-editor-plugins/lib/plugins/ContentEdit/features/listFeatures.ts @@ -34,13 +34,11 @@ import { Keys, PluginKeyboardEvent, QueryScope, - RegionBase, ListType, ExperimentalFeatures, PositionType, NumberingListType, BulletListType, - IPositionContentSearcher, } from 'roosterjs-editor-types'; const PREVIOUS_BLOCK_CACHE_KEY = 'previousBlock'; @@ -237,87 +235,24 @@ const OutdentWhenEnterOnEmptyLine: BuildInEditFeature = { }; /** - * Validate if a block of text is considered a list pattern - * The regex expression will look for patterns of the form: - * 1. 1> 1) 1- (1) - * @returns if a text is considered a list pattern - */ -function isAListPattern(textBeforeCursor: string) { - const REGEX: RegExp = /^(\*|-|[0-9]{1,2}\.|[0-9]{1,2}\>|[0-9]{1,2}\)|[0-9]{1,2}\-|\([0-9]{1,2}\))$/; - return REGEX.test(textBeforeCursor); -} - -/** - * AutoBullet edit feature, provides the ability to automatically convert current line into a list. - * When user input "1. ", convert into a numbering list - * When user input "- " or "* ", convert into a bullet list + * @deprecated Use AutoBulletList and AutoNumberingList instead */ const AutoBullet: BuildInEditFeature = { keys: [Keys.SPACE], shouldHandleEvent: (event, editor) => { - let searcher: IPositionContentSearcher | null; - if ( - !cacheGetListElement(event, editor) && - !editor.isFeatureEnabled(ExperimentalFeatures.AutoFormatList) && - (searcher = editor.getContentSearcherOfCursor(event)) - ) { - let textBeforeCursor = searcher.getSubStringBefore(4); - - // Auto list is triggered if: - // 1. Text before cursor exactly matches '*', '-' or '1.' - // 2. There's no non-text inline entities before cursor - return isAListPattern(textBeforeCursor) && !searcher.getNearestNonTextInlineElement(); - } return false; }, - handleEvent: (event, editor) => { - editor.insertContent(' '); - event.rawEvent.preventDefault(); - editor.addUndoSnapshot( - () => { - let regions: RegionBase[]; - let searcher = editor.getContentSearcherOfCursor(); - if (!searcher) { - return; - } - let textBeforeCursor = searcher.getSubStringBefore(4); - let textRange = searcher.getRangeFromText(textBeforeCursor, true /*exactMatch*/); - - if (!textRange) { - // no op if the range can't be found - } else if ( - textBeforeCursor.indexOf('*') == 0 || - textBeforeCursor.indexOf('-') == 0 - ) { - prepareAutoBullet(editor, textRange); - toggleBullet(editor); - } else if (isAListPattern(textBeforeCursor)) { - prepareAutoBullet(editor, textRange); - toggleNumbering(editor); - } else if ((regions = editor.getSelectedRegions()) && regions.length == 1) { - const num = parseInt(textBeforeCursor); - prepareAutoBullet(editor, textRange); - toggleNumbering(editor, num); - } - searcher.getRangeFromText(textBeforeCursor, true /*exactMatch*/)?.deleteContents(); - }, - undefined /*changeSource*/, - true /*canUndoByBackspace*/ - ); - }, + handleEvent: (event, editor) => {}, + defaultDisabled: true, }; /** - * Requires @see ExperimentalFeatures.AutoFormatList to be enabled * AutoBulletList edit feature, provides the ability to automatically convert current line into a bullet list. */ const AutoBulletList: BuildInEditFeature = { keys: [Keys.SPACE], shouldHandleEvent: (event, editor) => { - if ( - !cacheGetListElement(event, editor) && - editor.isFeatureEnabled(ExperimentalFeatures.AutoFormatList) - ) { + if (!cacheGetListElement(event, editor)) { return shouldTriggerList(event, editor, getAutoBulletListStyle, ListType.Unordered); } return false; @@ -352,16 +287,12 @@ const AutoBulletList: BuildInEditFeature = { }; /** - * Requires @see ExperimentalFeatures.AutoFormatList to be enabled * AutoNumberingList edit feature, provides the ability to automatically convert current line into a numbering list. */ const AutoNumberingList: BuildInEditFeature = { keys: [Keys.SPACE], shouldHandleEvent: (event, editor) => { - if ( - !cacheGetListElement(event, editor) && - editor.isFeatureEnabled(ExperimentalFeatures.AutoFormatList) - ) { + if (!cacheGetListElement(event, editor)) { return shouldTriggerList(event, editor, getAutoNumberingListStyle, ListType.Ordered); } return false; diff --git a/packages/roosterjs-editor-plugins/test/ContentEdit/features/listFeaturesTest.ts b/packages/roosterjs-editor-plugins/test/ContentEdit/features/listFeaturesTest.ts index 6699268a8b1..3240773bc73 100644 --- a/packages/roosterjs-editor-plugins/test/ContentEdit/features/listFeaturesTest.ts +++ b/packages/roosterjs-editor-plugins/test/ContentEdit/features/listFeaturesTest.ts @@ -37,18 +37,6 @@ describe('listFeatures | AutoBullet', () => { editor.dispose(); }); - function runListPatternTest(text: string, expectedResult: boolean) { - const root = document.createElement('div'); - const mockedPosition = new PositionContentSearcher(root, new Position(root, 4)); - spyOn(mockedPosition, 'getSubStringBefore').and.returnValue(text); - editorSearchCursorSpy.and.returnValue(mockedPosition); - editorIsFeatureEnabled.and.returnValue(false); - const isAutoBulletTriggered = ListFeatures.autoBullet.shouldHandleEvent(null, editor, false) - ? true - : false; - expect(isAutoBulletTriggered).toBe(expectedResult); - } - function runTestWithNumberingStyles(text: string, expectedResult: boolean) { const wrapper = document.createElement('div'); const root = document.createElement('div'); @@ -100,20 +88,6 @@ describe('listFeatures | AutoBullet', () => { expect(isAutoBulletTriggered).toBe(expectedResult); } - it('AutoBullet detects the correct patterns', () => { - runListPatternTest('1.', true); - runListPatternTest('2.', true); - runListPatternTest('1)', true); - runListPatternTest('2)', true); - runListPatternTest('90)', true); - runListPatternTest('1-', true); - runListPatternTest('2-', true); - runListPatternTest('90-', true); - runListPatternTest('(1)', true); - runListPatternTest('(2)', true); - runListPatternTest('(90)', true); - }); - it('AutoBulletList detects the correct patterns', () => { runTestWithBulletStyles('*', true); runTestWithBulletStyles('-', true); @@ -148,14 +122,6 @@ describe('listFeatures | AutoBullet', () => { runTestWithNumberingStyles('(a)', true); }); - it('AutoBullet with ignores incorrect not valid patterns', () => { - runListPatternTest('1=', false); - runListPatternTest('1/', false); - runListPatternTest('1#', false); - runListPatternTest(' ', false); - runListPatternTest('', false); - }); - it('AutoBulletList with ignores incorrect not valid patterns', () => { runTestWithBulletStyles('1=', false); runTestWithBulletStyles('1/', false); diff --git a/packages/roosterjs-editor-types/lib/enum/ExperimentalFeatures.ts b/packages/roosterjs-editor-types/lib/enum/ExperimentalFeatures.ts index 410fa620c0a..c1efaa5fec3 100644 --- a/packages/roosterjs-editor-types/lib/enum/ExperimentalFeatures.ts +++ b/packages/roosterjs-editor-types/lib/enum/ExperimentalFeatures.ts @@ -136,6 +136,12 @@ export const enum ExperimentalFeatures { */ EditWithContentModel = 'EditWithContentModel', + /** + * @deprecated This feature is always enabled + * Trigger formatting by a especial characters. Ex: (A), 1. i). + */ + AutoFormatList = 'AutoFormatList', + //#endregion /** @@ -143,11 +149,6 @@ export const enum ExperimentalFeatures { */ TabKeyTextFeatures = 'TabKeyTextFeatures', - /** - * Trigger formatting by a especial characters. Ex: (A), 1. i). - */ - AutoFormatList = 'AutoFormatList', - /** * With this feature enabled, when writing back a list item we will re-use all * ancestor list elements, even if they don't match the types currently in the