Skip to content

Commit

Permalink
feat(core): handle deleteContentBackward
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 committed Mar 20, 2023
1 parent 386b523 commit 117b941
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
12 changes: 0 additions & 12 deletions demo/app/richtext/richtext.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,5 @@ const initialValue = [
{
type: 'heading-one',
children: [{ text: 'This is h1 ' }]
},
{
type: 'heading-three',
children: [{ text: 'This is h3 ' }]
},
{
type: 'paragraph',
children: [
{
text: `Since`
}
]
}
];
20 changes: 13 additions & 7 deletions packages/src/components/editable/editable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,18 @@ export class SlateEditableComponent implements OnInit, OnChanges, OnDestroy, Aft
}
return;
}
if (type === 'deleteContentBackward') {
const range = window.getSelection();
// Gboard can not prevent default action, so must use restoreDom, Sougou Keyboard can prevent default action.
// In order to avoid weird action in Sougou Keyboard, use resotreDom only range's isCollapsed is false (recognize gboard)
if (range.isCollapsed === false) {
range.removeAllRanges();
restoreDom(editor, () => {
Editor.deleteBackward(editor);
});
return;
}
}
}
if (
!this.readonly &&
Expand Down Expand Up @@ -610,13 +622,7 @@ export class SlateEditableComponent implements OnInit, OnChanges, OnDestroy, Aft
}

case 'deleteContentBackward': {
if (IS_ANDROID) {
restoreDom(editor, () => {
Editor.deleteBackward(editor);
});
} else {
Editor.deleteBackward(editor);
}
Editor.deleteBackward(editor);
break;
}

Expand Down

0 comments on commit 117b941

Please sign in to comment.