From d3d0845fda23b7fa895f49a716fdee3e67d854a6 Mon Sep 17 00:00:00 2001 From: xdan Date: Sat, 4 Jun 2022 13:30:25 +0300 Subject: [PATCH] All added videos are deleted when you click Delete or Backspace #847 Issue: https://github.com/xdan/jodit/issues/847 --- CHANGELOG.MD | 1 + src/core/selection/select.ts | 5 +++-- src/jodit.ts | 12 ++++++++++-- src/plugins/keyboard/backspace/backspace.ts | 2 +- .../keyboard/backspace/cases/check-not-collapsed.ts | 1 + src/types/jodit.d.ts | 6 ++++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 2c13b18fe..ceb38b6ee 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -14,6 +14,7 @@ #### :bug: Bug Fix - [Multiple modals 'Paste as HTML' after longer pressing ctrl+v #849](https://github.com/xdan/jodit/issues/849) +- [All added videos are deleted when you click Delete or Backspace #847](https://github.com/xdan/jodit/issues/847) ## 3.18.6 diff --git a/src/core/selection/select.ts b/src/core/selection/select.ts index 2a36d2ca6..bc337ff60 100644 --- a/src/core/selection/select.ts +++ b/src/core/selection/select.ts @@ -623,7 +623,7 @@ export class Select implements ISelect { } if (fireChange && this.j.events) { - this.j.e.fire('synchro'); + this.j.__imdSynchronizeValues(); } if (this.j.events) { @@ -692,7 +692,8 @@ export class Select implements ISelect { } } - this.j.synchronizeValues(); + // There is no need to use synchronizeValues because you need to apply the changes immediately + this.j.__imdSynchronizeValues(); } /** diff --git a/src/jodit.ts b/src/jodit.ts index 8da34172a..c85613df2 100644 --- a/src/jodit.ts +++ b/src/jodit.ts @@ -440,6 +440,14 @@ export class Jodit extends ViewWithToolbar implements IJodit { @throttle() synchronizeValues(): void { + this.__imdSynchronizeValues(); + } + + /** + * This is an internal method, do not use it in your applications. + * @private + */ + __imdSynchronizeValues(): void { this.setEditorValue(); } @@ -549,7 +557,7 @@ export class Jodit extends ViewWithToolbar implements IJodit { throw error('value must be string'); } - if (value !== undefined && this.getNativeEditorValue() !== value) { + if (!isVoid(value) && this.getNativeEditorValue() !== value) { this.setNativeEditorValue(value); } @@ -604,7 +612,7 @@ export class Jodit extends ViewWithToolbar implements IJodit { /** * @deprecated Use `Jodit.value` instead */ - setElementValue(value?: string): CanPromise { + protected setElementValue(value?: string): CanPromise { const oldValue = this.getElementValue(); if (value === undefined || (isString(value) && value !== oldValue)) { diff --git a/src/plugins/keyboard/backspace/backspace.ts b/src/plugins/keyboard/backspace/backspace.ts index ab4f1788b..f341f00d5 100644 --- a/src/plugins/keyboard/backspace/backspace.ts +++ b/src/plugins/keyboard/backspace/backspace.ts @@ -90,7 +90,7 @@ export class Backspace extends Plugin { if ( !trim(jodit.editor.textContent || '') && - !jodit.editor.querySelector('img') && + !jodit.editor.querySelector('img,table,jodit,iframe,hr') && (!current || !Dom.closest(current, 'table', jodit.editor)) ) { jodit.editor.innerHTML = ''; diff --git a/src/plugins/keyboard/backspace/cases/check-not-collapsed.ts b/src/plugins/keyboard/backspace/cases/check-not-collapsed.ts index cec50c53c..16cbe4d32 100644 --- a/src/plugins/keyboard/backspace/cases/check-not-collapsed.ts +++ b/src/plugins/keyboard/backspace/cases/check-not-collapsed.ts @@ -3,6 +3,7 @@ * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2022 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ + import type { IJodit } from 'jodit/types'; /** diff --git a/src/types/jodit.d.ts b/src/types/jodit.d.ts index 12ae9461e..9df33300a 100644 --- a/src/types/jodit.d.ts +++ b/src/types/jodit.d.ts @@ -45,7 +45,13 @@ interface IJodit extends IViewWithToolbar { getNativeEditorValue(): string; getEditorValue(removeSelectionMarkers?: boolean, consumer?: string): string; setEditorValue(value?: string): void; + synchronizeValues(): void; + /** + * This is an internal method, do not use it in your applications. + * @private + */ + __imdSynchronizeValues(): void; /** * Only getter