Skip to content

[Hot fix] Add null check to list metadata#1379

Merged
juliaroldi merged 4 commits intomasterfrom
u/juliaroldi/hot-fix-list-features
Nov 3, 2022
Merged

[Hot fix] Add null check to list metadata#1379
juliaroldi merged 4 commits intomasterfrom
u/juliaroldi/hot-fix-list-features

Conversation

@juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Nov 3, 2022

When the list does not have metadata, return previous list style as null.

@juliaroldi juliaroldi marked this pull request as ready for review November 3, 2022 17:12
@juliaroldi juliaroldi marked this pull request as draft November 3, 2022 17:12
@juliaroldi juliaroldi force-pushed the u/juliaroldi/hot-fix-list-features branch from 7e6582b to 1b5e3fe Compare November 3, 2022 17:14
@juliaroldi juliaroldi marked this pull request as ready for review November 3, 2022 17:15
@juliaroldi juliaroldi changed the title U/juliaroldi/hot fix list features [Hot fix] Add null check to list metadata Nov 3, 2022
return previousNode && getTagOfNode(previousNode) === 'LI'
return previousNode &&
getTagOfNode(previousNode) === 'LI' &&
getMetadata(previousNode.parentElement, ListStyleDefinitionMetadata)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not call getMetadata twice. It is heavy

return previousNode && getTagOfNode(previousNode) === 'LI'
return previousNode &&
getTagOfNode(previousNode) === 'LI' &&
getMetadata(previousNode.parentElement, ListStyleDefinitionMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

parentElement can be null, can we add a null check?

const getPreviousListType = (editor: IEditor, textRange: Range, listType: ListType) => {
const type = listType === ListType.Ordered ? 'orderedStyleType' : 'unorderedStyleType';
const previousNode = getPreviousList(editor, textRange);
const metadata = getMetadata(previousNode.parentElement, ListStyleDefinitionMetadata);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If previousNode or previousNode.parentElement is null, this will still be a problem.

BTW, what is the parent element here?

Copy link
Contributor Author

@juliaroldi juliaroldi Nov 3, 2022

Choose a reason for hiding this comment

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

It should to be the UL or OL element, but I noticed that the list structure can different to just <ol><li></li><ol>, then I changed the code to use findClosestElementAntecesor to find the ul or ol element that contain the metadata.

@juliaroldi juliaroldi merged commit 0ef1575 into master Nov 3, 2022
juliaroldi added a commit that referenced this pull request Nov 3, 2022
…tures

[Hot fix] Add null check to list metadata
BryanValverdeU pushed a commit that referenced this pull request Feb 10, 2023
…tures

[Hot fix] Add null check to list metadata
@JiuqingSong JiuqingSong deleted the u/juliaroldi/hot-fix-list-features branch September 8, 2023 22:31
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.

3 participants