Skip to content

Commit

Permalink
refactor(editor): rename method from rectifyContent to fixContent
Browse files Browse the repository at this point in the history
  • Loading branch information
luolonghao committed May 25, 2024
1 parent 12511ff commit 4c48082
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class Editor {
});

private emitChangeEvent = (value: string) => {
this.rectifyContent();
this.fixContent();
this.emitStateChangeEvent();
this.togglePlaceholderClass(value);
this.scrollToCaret();
Expand Down Expand Up @@ -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() === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/backspace-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/delete-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/enter-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default (editor: Editor) => {
return;
}
event.preventDefault();
editor.rectifyContent();
editor.fixContent();
if (range.isBox) {
addBlockOrSplitBlockForBox(editor);
editor.history.save();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/shift-enter-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default (editor: Editor) => {
if (range.isInsideBox) {
return;
}
editor.rectifyContent();
editor.fixContent();
event.preventDefault();
if (range.isBox) {
addBlockOrLineBreakForBox(editor);
Expand Down
8 changes: 4 additions & 4 deletions tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<p><br /><focus /></p>';
const editor = new Editor({
Expand All @@ -211,7 +211,7 @@ describe('editor', () => {
expect(value).to.equal(output);
});

it('rectifyContent method: br', () => {
it('fixContent method: br', () => {
const input = '<br />';
const output = '<p><br /><focus /></p>';
const editor = new Editor({
Expand All @@ -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 = '<br /><span></span>';
const output = '<p><br /><focus /></p>';
const editor = new Editor({
Expand All @@ -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 = '<br /><p></p>';
const output = '<p><br /><focus /></p>';
const editor = new Editor({
Expand Down

0 comments on commit 4c48082

Please sign in to comment.