Skip to content

Commit b8e1178

Browse files
committed
fix: restore original editor size after resizing window in fullsize mode
Fixes #1278
1 parent 06227b9 commit b8e1178

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111

12+
## 4.12.12
13+
14+
#### :bug: Bug Fix
15+
16+
- **Fullsize**: after entering fullsize mode, resizing the browser window, and then exiting fullsize, the editor kept the fullscreen width/height instead of returning to its original size. The `resize` handler (bound to `window.resize` when `globalFullSize` is on) re-saved the "original" size on every window resize, so it captured the fullscreen size. The original size is now stored only once when entering fullsize and restored on exit. Fixes [#1278](https://github.com/xdan/jodit/issues/1278).
17+
1218
## 4.12.11
1319

1420
#### :bug: Bug Fix

src/plugins/fullsize/fullsize.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
*/
66

77
describe('Fullsize plugin', function () {
8+
describe('Resize window while in fullsize (#1278)', function () {
9+
it('Should restore the original width after exiting fullsize', () => {
10+
const editor = getJodit();
11+
12+
editor.container.style.width = '300px';
13+
const originalWidth = editor.container.offsetWidth;
14+
15+
editor.toggleFullSize(true);
16+
17+
// The window is resized while the editor is in fullsize mode.
18+
simulateEvent('resize', editor.ow);
19+
20+
editor.toggleFullSize(false);
21+
22+
expect(
23+
Math.abs(editor.container.offsetWidth - originalWidth)
24+
).is.below(3);
25+
});
26+
});
27+
828
describe('Toggle fullsize', function () {
929
it('Should resize all boxes to first state', () => {
1030
const editor = getJodit({

src/plugins/fullsize/fullsize.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,27 @@ export function fullsize(editor: IViewWithToolbar): void {
4141
}
4242

4343
if (isEnabled) {
44-
oldHeight = css(container, 'height', true) as number;
45-
oldWidth = css(container, 'width', true) as number;
44+
// Save the original size only once, when entering fullsize.
45+
// Otherwise a window resize while in fullsize would overwrite it
46+
// with the current (fullscreen) size, so exiting fullsize would
47+
// restore the wrong dimensions (#1278).
48+
if (!wasToggled) {
49+
oldHeight = css(container, 'height', true) as number;
50+
oldWidth = css(container, 'width', true) as number;
51+
wasToggled = true;
52+
}
53+
4654
css(container, {
4755
height: editor.ow.innerHeight,
4856
width: editor.ow.innerWidth
4957
});
50-
51-
wasToggled = true;
5258
} else if (wasToggled) {
5359
css(container, {
5460
height: oldHeight || 'auto',
5561
width: oldWidth || 'auto'
5662
});
63+
64+
wasToggled = false;
5765
}
5866
},
5967
/**

0 commit comments

Comments
 (0)