Skip to content

Content Model: Improve the behavior of deleting general element#1680

Merged
JiuqingSong merged 12 commits into
masterfrom
u/jisong/deletegeneral
Apr 4, 2023
Merged

Content Model: Improve the behavior of deleting general element#1680
JiuqingSong merged 12 commits into
masterfrom
u/jisong/deletegeneral

Conversation

@JiuqingSong

@JiuqingSong JiuqingSong commented Mar 28, 2023

Copy link
Copy Markdown
Collaborator

#1662

When the deleting content is related to general element, for example:

<button>test</button>

here "button" is not supported as a special element in Content Model so we will use ContentModelGeneralBlock or ContentModelGeneralSegment to represent it, depends on its CSS display state.

When we hit a general element, we need to check if the whole element is selected, or there is potentially selected element under it. So we need to modify the API iterateSelections() to allow return the selected element or its child nodes.

In order to let it also work for existing code (mostly, format segments API), we need to introduce a new option named contentUnderSelectedGeneralElement, it has 3 values:

  • contentOnly: (Default) When the whole general element is selected, we only invoke callback for its selected content
  • generalElementOnly: When the whole general element is selected, we only invoke callback for the general element (using block or segment parameter depends on if it is a block or segment), but skip all its content.
  • both: When general element is selected, we invoke callback first for its content, then for general element itself

When we hit a general model, either segment or block, first check if it is selected, then do different handling according to this new option value:

  • If it is selected, and we want to handle general element content (contentUnderSelectedGeneralElement set to contentOnly or both), recursively iterate its child nodes. This is used for format segments and blocks
  • If it is selected, and we want to handle general element itself (contentUnderSelectedGeneralElement set to generalElementOnly or both), invoke the callback to let caller handle this element. This is used for delete
  • If it is not selected, recursively iterate its child nodes.
  • If the element is empty (no child blocks), always treat the option as generalElementOnly

With this design, we can make sure deleteSelection() API will always get the selected general element and delete it correctly.

@JiuqingSong JiuqingSong changed the title Content Model: prototype of delete general element Content Model: Improve the behavior of deleting general element Mar 29, 2023
@JiuqingSong
JiuqingSong marked this pull request as ready for review March 29, 2023 22:06
@JiuqingSong
JiuqingSong merged commit 28a5ee7 into master Apr 4, 2023
@JiuqingSong
JiuqingSong deleted the u/jisong/deletegeneral branch April 4, 2023 21:27
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