Skip to content

Commit f257877

Browse files
committed
Size: don't subtract an external toolbar's height from the workplace
When the toolbar option points to an element outside the editor container, __getNotWorkHeight still counted the toolbar height, so the workplace was shrunk by a toolbar that wasn't in the container. Only subtract it when the toolbar actually lives inside the container. Fixes #920
1 parent 6b6f6ac commit f257877

3 files changed

Lines changed: 36 additions & 5 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.32
13+
14+
#### :bug: Bug Fix
15+
16+
- **Editor size / external toolbar**: when the `toolbar` option points to an external element (the toolbar renders outside the editor container), the workplace height was still computed as `container height − toolbar height`, so the editing area was wrongly shrunk by the height of a toolbar that wasn't inside the container. The toolbar height is now subtracted only when the toolbar actually lives inside the container. Reported in [#920](https://github.com/xdan/jodit/discussions/920).
17+
1218
## 4.12.31
1319

1420
#### :bug: Bug Fix

src/plugins/size/size.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
).equals(1);
2020
});
2121

22+
// https://github.com/xdan/jodit/discussions/920
23+
it('should not subtract an external toolbar height from the workplace (#920)', function () {
24+
const toolbarBox = appendTestDiv();
25+
const editor = getJodit({
26+
toolbar: toolbarBox,
27+
height: 400
28+
});
29+
30+
const statusbarH = editor.statusbar.getHeight();
31+
32+
// The toolbar lives outside the container, so the workplace should
33+
// fill the container minus only the statusbar — it must not be
34+
// shrunk by the (external) toolbar's height.
35+
expect(editor.workplace.offsetHeight).is.least(
36+
editor.container.offsetHeight - statusbarH - 5
37+
);
38+
});
39+
2240
it('should show resize handler with custom buttons and counters disabled (issue #1335)', function () {
2341
const editor = getJodit({
2442
controls: {

src/plugins/size/size.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,18 @@ export class size extends Plugin {
144144
* Returns service spaces: toolbar + statusbar
145145
*/
146146
private __getNotWorkHeight(): number {
147-
return (
148-
(this.j.toolbarContainer?.offsetHeight || 0) +
149-
(this.j.statusbar?.getHeight() || 0) +
150-
2
151-
);
147+
// Only a toolbar that actually lives inside the editor container takes
148+
// space away from the workplace. When the `toolbar` option points to an
149+
// external element, the toolbar is rendered outside the container, so it
150+
// must not be subtracted — otherwise the workplace is wrongly shrunk by
151+
// the toolbar's height. See https://github.com/xdan/jodit/discussions/920
152+
const toolbar = this.j.toolbarContainer;
153+
const toolbarHeight =
154+
toolbar && this.j.container.contains(toolbar)
155+
? toolbar.offsetHeight
156+
: 0;
157+
158+
return toolbarHeight + (this.j.statusbar?.getHeight() || 0) + 2;
152159
}
153160

154161
/**

0 commit comments

Comments
 (0)