From 4c48082472e51c35a685227d489a6bb9a6a4672c Mon Sep 17 00:00:00 2001 From: luolonghao Date: Sat, 25 May 2024 15:38:07 +0800 Subject: [PATCH] refactor(editor): rename method from rectifyContent to fixContent --- src/editor.ts | 4 ++-- src/plugins/backspace-key.ts | 2 +- src/plugins/delete-key.ts | 2 +- src/plugins/enter-key.ts | 2 +- src/plugins/shift-enter-key.ts | 2 +- tests/editor.test.ts | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/editor.ts b/src/editor.ts index 510f08f3..303696b3 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -302,7 +302,7 @@ export class Editor { }); private emitChangeEvent = (value: string) => { - this.rectifyContent(); + this.fixContent(); this.emitStateChangeEvent(); this.togglePlaceholderClass(value); this.scrollToCaret(); @@ -436,7 +436,7 @@ export class Editor { } // Fixes wrong content, especially empty tag. - public rectifyContent(): void { + public fixContent(): void { let children = this.container.children(); for (const child of children) { if ((child.isBlock || child.isMark) && child.html() === '') { diff --git a/src/plugins/backspace-key.ts b/src/plugins/backspace-key.ts index 18ff9782..42344ca8 100644 --- a/src/plugins/backspace-key.ts +++ b/src/plugins/backspace-key.ts @@ -49,7 +49,7 @@ export default (editor: Editor) => { if (range.isInsideBox) { return; } - editor.rectifyContent(); + editor.fixContent(); if (range.isBoxStart) { const boxNode = range.startNode.closest('lake-box'); const prevNode = boxNode.prev(); diff --git a/src/plugins/delete-key.ts b/src/plugins/delete-key.ts index 80fdfe9a..e1714aef 100644 --- a/src/plugins/delete-key.ts +++ b/src/plugins/delete-key.ts @@ -40,7 +40,7 @@ export default (editor: Editor) => { if (range.isInsideBox) { return; } - editor.rectifyContent(); + editor.fixContent(); if (range.isBoxEnd) { const boxNode = range.startNode.closest('lake-box'); const nextNode = boxNode.next(); diff --git a/src/plugins/enter-key.ts b/src/plugins/enter-key.ts index b54f6548..0b066154 100644 --- a/src/plugins/enter-key.ts +++ b/src/plugins/enter-key.ts @@ -58,7 +58,7 @@ export default (editor: Editor) => { return; } event.preventDefault(); - editor.rectifyContent(); + editor.fixContent(); if (range.isBox) { addBlockOrSplitBlockForBox(editor); editor.history.save(); diff --git a/src/plugins/shift-enter-key.ts b/src/plugins/shift-enter-key.ts index 0e9ed0cb..73c86fd2 100644 --- a/src/plugins/shift-enter-key.ts +++ b/src/plugins/shift-enter-key.ts @@ -54,7 +54,7 @@ export default (editor: Editor) => { if (range.isInsideBox) { return; } - editor.rectifyContent(); + editor.fixContent(); event.preventDefault(); if (range.isBox) { addBlockOrLineBreakForBox(editor); diff --git a/tests/editor.test.ts b/tests/editor.test.ts index c4e437ea..3c2ea049 100644 --- a/tests/editor.test.ts +++ b/tests/editor.test.ts @@ -195,7 +195,7 @@ describe('editor', () => { expect(value).to.equal(output); }); - it('rectifyContent method: no content', () => { + it('fixContent method: no content', () => { const input = ''; const output = '


'; const editor = new Editor({ @@ -211,7 +211,7 @@ describe('editor', () => { expect(value).to.equal(output); }); - it('rectifyContent method: br', () => { + it('fixContent method: br', () => { const input = '
'; const output = '


'; const editor = new Editor({ @@ -227,7 +227,7 @@ describe('editor', () => { expect(value).to.equal(output); }); - it('rectifyContent method: br and empty mark', () => { + it('fixContent method: br and empty mark', () => { const input = '
'; const output = '


'; const editor = new Editor({ @@ -243,7 +243,7 @@ describe('editor', () => { expect(value).to.equal(output); }); - it('rectifyContent method: br and empty block', () => { + it('fixContent method: br and empty block', () => { const input = '

'; const output = '


'; const editor = new Editor({