Skip to content

Commit

Permalink
fix(core): add rewrite function deleteCutData #WIK-4877 (worktile#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Oct 13, 2021
1 parent fe09836 commit c9a26b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions packages/src/components/editable/editable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,7 @@ export class SlateEditableComponent implements OnInit, OnChanges, OnDestroy, Aft
const { selection } = this.editor;

if (selection) {
if (Range.isExpanded(selection)) {
Editor.deleteFragment(this.editor);
} else {
const node = Node.parent(this.editor, selection.anchor.path)
if (Editor.isVoid(this.editor, node)) {
Transforms.delete(this.editor);
}
}
AngularEditor.deleteCutData(this.editor);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/src/plugins/angular-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, getCardTarge
export interface AngularEditor extends BaseEditor {
insertData: (data: DataTransfer) => void;
setFragmentData: (data: DataTransfer) => void;
deleteCutData: ()=> void;
onKeydown: (event: KeyboardEvent) => void;
onClick: (event: MouseEvent) => void;
injector: Injector;
Expand Down Expand Up @@ -278,6 +279,10 @@ export const AngularEditor = {
editor.setFragmentData(data);
},

deleteCutData(editor: AngularEditor): void{
editor.deleteCutData();
},

/**
* Find the native DOM element from a Slate node.
*/
Expand Down
18 changes: 16 additions & 2 deletions packages/src/plugins/with-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,23 @@ export const withAngular = <T extends Editor>(editor: T, clipboardFormatKey = 'x
data.setData('text/html', div.innerHTML);
data.setData('text/plain', getPlainText(div));
document.body.removeChild(div);
},
};

e.deleteCutData = () => {
const { selection } = editor;
if (selection) {
if (Range.isExpanded(selection)) {
Editor.deleteFragment(editor);
} else {
const node = Node.parent(editor, selection.anchor.path);
if (Editor.isVoid(editor, node)) {
Transforms.delete(editor);
}
}
}
};

e.insertData = (data: DataTransfer) => {
e.insertData = (data: DataTransfer) => {
const fragment = data.getData(`application/${clipboardFormatKey}`);

if (fragment) {
Expand Down

0 comments on commit c9a26b5

Please sign in to comment.