Skip to content

Content Model: Handle Delete and Backspace#1660

Merged
JiuqingSong merged 7 commits into
masterfrom
u/jisong/delete1
Mar 28, 2023
Merged

Content Model: Handle Delete and Backspace#1660
JiuqingSong merged 7 commits into
masterfrom
u/jisong/delete1

Conversation

@JiuqingSong

@JiuqingSong JiuqingSong commented Mar 24, 2023

Copy link
Copy Markdown
Collaborator

This is part of Content Model Stage 3: Handle Delete and Backspace keydown event with Content Model.

This is the first step. In this change, I separate existing deleteSelection API into 3 steps:

  1. Try to get all selected content from model, and delete them and create a new selection marker to mark where the cursor should be, except the first selection marker. Because if the first selected item is a selection marker, it is possible there is only a single collapsed selection, then we need step 2.
  2. If nothing was deleted from step 1, and we want to do delete (options.direction is forward (for DELETE key) or backward (for BACKSPACE key)), get the sibling content and delete it. This can be several different cases:
    2.1 There is text segment, we only delete one character
    2.2 There is other type of segments such as image, br, we delete the whole segment
    2.3 There is no segment in the same paragraph, then we will look for sibling block, and if there are blocks such as table, divider, ..., delete the whole block
  3. After 1 and 2, if we end up with two paragraphs impacted, we may need to merge them, unless they belong to different table cells.

During this process, if there are entities got impacted, we will trigger EntityOperation event so that plugins know entity will be deleted.

There are still some known issues that need to be solved by further changes, such as

  1. When delete a General model, need to improve the behavior (Content Model: Improve General model handling when delete #1662)
  2. The delete process is built on top of cached Content Model. And we already see there is issue with PRE tag when Content Model is cached, need to fix it separately. (Content Model: PRE tag is incorrectly cached #1661)
  3. Too many undo snapshots will be generated when keep deleting. We should follow the original behavior to only generate one. (Content Model: Merge multiple undo snapshots into one when keep deleting #1663)
  4. Take over other conflict ContentEditFeatures (Content Model: ContentModleEditPlugin needs to take over the functionalities of ContentEdit plugin #1664)

And since there are still these known issues, this new behavior is not enabled by default. To test it, need to manually turn on plugin ContentModelEditPlugin:

image

@JiuqingSong
JiuqingSong marked this pull request as ready for review March 24, 2023 18:39
@JiuqingSong JiuqingSong changed the title Content Model: Handle Delete and Backspace step 1 Content Model: Handle Delete and Backspace Mar 27, 2023
@JiuqingSong
JiuqingSong merged commit 50b599b into master Mar 28, 2023
@JiuqingSong
JiuqingSong deleted the u/jisong/delete1 branch March 28, 2023 18:36
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