Skip to content

Commit

Permalink
Edit Link bugg when there is a iframe #1176
Browse files Browse the repository at this point in the history
Issue: #1176
  • Loading branch information
xdan committed Oct 14, 2024
1 parent c38fec5 commit 20460f6
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 149 deletions.
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
> - :house: [Internal]
> - :nail_care: [Polish]
## 4.2.35

### :bug: Bug Fix

- [Edit Link bugg when there is a iframe #1176](https://github.com/xdan/jodit/issues/1176)

## 4.2.34

### :bug: Bug Fix
Expand Down Expand Up @@ -2841,11 +2847,11 @@ Related with https://github.com/xdan/jodit/issues/574. In some cases need to lim
- @property {IUIOption[]} link.selectOptionsClassName=[] The list of the option for the select (to use with
modeClassName="select")
- ex: [
- { value: "", text: "" },
- { value: "val1", text: "text1" },
- { value: "val2", text: "text2" },
- { value: "val3", text: "text3" }
- ]
- { value: "", text: "" },
- { value: "val1", text: "text1" },
- { value: "val2", text: "text2" },
- { value: "val3", text: "text3" }
- ]
PR: https://github.com/xdan/jodit/pull/577 Thanks @s-renier-taonix-fr
##### New option `statusbar: boolean = true`
Expand Down
22 changes: 12 additions & 10 deletions src/modules/history/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import type { IJodit, ISnapshot, Nullable, SnapshotType } from 'jodit/types';
import { ViewComponent } from 'jodit/core/component';
import { IS_PROD, TEMP_ATTR } from 'jodit/core/constants';
import { Dom } from 'jodit/core/dom';
import { IS_PROD } from 'jodit/core/constants';
import { Dom } from 'jodit/core/dom/dom';

/**
* Module for creating snapshot of editor which includes html content and the current selection
Expand Down Expand Up @@ -154,14 +154,16 @@ export class Snapshot extends ViewComponent<IJodit> implements ISnapshot {
}
};

snapshot.html = this.removeJoditSelection(this.j.editor);
snapshot.html = this.__getCleanedEditorValue(this.j.editor);

const sel = this.j.s.sel;

if (sel && sel.rangeCount) {
const range = sel.getRangeAt(0),
startContainer = this.calcHierarchyLadder(range.startContainer),
endContainer = this.calcHierarchyLadder(range.endContainer);
const range = sel.getRangeAt(0);
const startContainer = this.calcHierarchyLadder(
range.startContainer
);
const endContainer = this.calcHierarchyLadder(range.endContainer);

let startOffset = Snapshot.strokeOffset(
range.startContainer,
Expand Down Expand Up @@ -204,8 +206,8 @@ export class Snapshot extends ViewComponent<IJodit> implements ISnapshot {
this.transaction(() => {
const scroll = this.storeScrollState();

const value = this.j.getNativeEditorValue();
if (value !== snapshot.html) {
const html = this.__getCleanedEditorValue(this.j.editor);
if (html !== snapshot.html) {
this.j.value = snapshot.html;
}

Expand Down Expand Up @@ -270,10 +272,10 @@ export class Snapshot extends ViewComponent<IJodit> implements ISnapshot {
return (Dom.isText(node) && !node.nodeValue) || Dom.isTemporary(node);
}

private removeJoditSelection(node: HTMLElement): string {
private __getCleanedEditorValue(node: HTMLElement): string {
const clone = node.cloneNode(true) as HTMLElement;

clone.querySelectorAll(`[${TEMP_ATTR}]`).forEach(Dom.unwrap);
Dom.temporaryList(clone).forEach(Dom.unwrap);

return clone.innerHTML;
}
Expand Down
Loading

0 comments on commit 20460f6

Please sign in to comment.