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

[FHL] Deprecate AutoFormatList experimental feature #2062

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -29,7 +29,6 @@ const initialState: BuildInPluginState = {
watermarkText: 'Type content here ...',
forcePreserveRatio: false,
experimentalFeatures: [
ExperimentalFeatures.AutoFormatList,
ExperimentalFeatures.InlineEntityReadOnlyDelimiters,
ExperimentalFeatures.ContentModelPaste,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export interface ExperimentalFeaturesProps {

const FeatureNames: Partial<Record<ExperimentalFeatures, string>> = {
[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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export interface ExperimentalFeaturesProps {

const FeatureNames: Partial<Record<ExperimentalFeatures, string>> = {
[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]:
Expand Down
4 changes: 1 addition & 3 deletions packages/roosterjs-editor-api/lib/utils/toggleListType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 4 additions & 15 deletions packages/roosterjs-editor-api/test/utils/toggleListTypeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('toggleListTypeTest()', () => {

// Assert
expect(editor.getContent()).toBe(
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul><li>test</li></ul><div><span id="focusNode" style="font-family: &quot;Courier New&quot;; font-size: 20pt; color: rgb(208, 92, 18);"></span></div></div>'
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li></ul><div><span id="focusNode" style="font-family: &quot;Courier New&quot;; font-size: 20pt; color: rgb(208, 92, 18);"></span></div></div>'
);
});

Expand All @@ -53,7 +53,7 @@ describe('toggleListTypeTest()', () => {

// Assert
expect(editor.getContent()).toBe(
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul><li>test</li></ul><div><span id="focusNode" style="font-family: &quot;Courier New&quot;; font-size: 20pt; color: rgb(208, 92, 18);"></span></div><ul><li>test</li></ul></div>'
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li></ul><div><span id="focusNode" style="font-family: &quot;Courier New&quot;; font-size: 20pt; color: rgb(208, 92, 18);"></span></div><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li></ul></div>'
);
});

Expand All @@ -74,12 +74,7 @@ describe('toggleListTypeTest()', () => {

// Assert
expect(editor.getContent()).toBe(
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div>' +
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div>' +
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">' +
'<ul><li>test</li><li>test</li></ul>' +
'<div><br></div>' +
'</div>'
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li><li style="list-style-type: disc;">test</li></ul><div><br></div></div>'
);
});

Expand All @@ -100,13 +95,7 @@ describe('toggleListTypeTest()', () => {

// Assert
expect(editor.getContent()).toBe(
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div>' +
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div>' +
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">' +
'<ul><li>test</li></ul>' +
'<div><br></div>' +
'<ul><li>test</li></ul>' +
'</div>'
'<div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);">default format</div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><br></div><div style="font-family: Arial; font-size: 16pt; color: rgb(0, 111, 201);"><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li></ul><div><br></div><ul data-editing-info="{&quot;orderedStyleType&quot;:1,&quot;unorderedStyleType&quot;:1}"><li style="list-style-type: disc;">test</li></ul></div>'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -248,76 +248,22 @@ function isAListPattern(textBeforeCursor: string) {
}

/**
* 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<PluginKeyboardEvent> = {
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('&nbsp;');
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*/
);
},
shouldHandleEvent: (event, editor) => {},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this can pass the build. If not, just let it return false.

handleEvent: (event, editor) => {},
defaultDisabled: true,
JiuqingSong marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* 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<PluginKeyboardEvent> = {
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;
Expand Down Expand Up @@ -352,16 +298,12 @@ const AutoBulletList: BuildInEditFeature<PluginKeyboardEvent> = {
};

/**
* 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<PluginKeyboardEvent> = {
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;
Expand Down
11 changes: 6 additions & 5 deletions packages/roosterjs-editor-types/lib/enum/ExperimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ 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

/**
* Provide additional Tab Key Features. Requires Text Features Content Editable Features
*/
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
Expand Down