Skip to content

Commit

Permalink
Let DOM Helper return a cloned root
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Sep 24, 2024
1 parent e3bc1f3 commit e653aa2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class DOMHelperImpl implements DOMHelper {
const paddingRight = parseValueWithUnit(style?.paddingRight);
return this.contentDiv.clientWidth - (paddingLeft + paddingRight);
}

/**
* Get a deep cloned root element
*/
getClonedRoot(): HTMLElement {
return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,20 @@ describe('DOMHelperImpl', () => {
expect(domHelper.getClientWidth()).toBe(1000);
});
});

describe('getClonedRoot', () => {
it('getClonedRoot', () => {
const mockedClone = 'CLONE' as any;
const cloneSpy = jasmine.createSpy('cloneSpy').and.returnValue(mockedClone);
const mockedDiv: HTMLElement = {
cloneNode: cloneSpy,
} as any;
const domHelper = createDOMHelper(mockedDiv);

const result = domHelper.getClonedRoot();

expect(result).toBe(mockedClone);
expect(cloneSpy).toHaveBeenCalledWith(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ export interface DOMHelper {
* Get the width of the editable area of the editor content div
*/
getClientWidth(): number;

/**
* Get a deep cloned root element
*/
getClonedRoot(): HTMLElement;
}

0 comments on commit e653aa2

Please sign in to comment.