Skip to content

Commit bcc4933

Browse files
cammarosanoFrancoisGe
authored andcommitted
Fix toolbar open in extended mode
Upon opening, the toolbar should be displayed in its compact form. Before this commmit, extending the toolbar followed by closing and reopening it would (incorrectely) result in its extended form.
1 parent 595a347 commit bcc4933

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

addons/html_editor/static/src/main/toolbar/toolbar_plugin.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class ToolbarPlugin extends Plugin {
134134
static shared = ["getToolbarInfo"];
135135
resources = {
136136
selectionchange_handlers: this.handleSelectionChange.bind(this),
137-
selection_leave_handlers: () => this.overlay.close(),
137+
selection_leave_handlers: () => this.closeToolbar(),
138138
step_added_handlers: () => this.updateToolbar(),
139139
user_commands: {
140140
id: "expandToolbar",
@@ -210,7 +210,7 @@ export class ToolbarPlugin extends Plugin {
210210
// Mouse interaction behavior:
211211
// Close toolbar on mousedown and prevent it from opening until mouseup.
212212
this.addDomListener(this.editable, "mousedown", () => {
213-
this.overlay.close();
213+
this.closeToolbar();
214214
this.debouncedUpdateToolbar.cancel();
215215
this.onSelectionChangeActive = false;
216216
});
@@ -235,7 +235,7 @@ export class ToolbarPlugin extends Plugin {
235235
// sequential keystrokes.
236236
this.addDomListener(this.editable, "keydown", (ev) => {
237237
if (ev.key.startsWith("Arrow")) {
238-
this.overlay.close();
238+
this.closeToolbar();
239239
this.onSelectionChangeActive = false;
240240
}
241241
});
@@ -303,10 +303,14 @@ export class ToolbarPlugin extends Plugin {
303303
}
304304

305305
updateToolbar(selectionData = this.dependencies.selection.getSelectionData()) {
306-
this.updateToolbarVisibility(selectionData);
307-
if (this.overlay.isOpen || this.config.disableFloatingToolbar) {
308-
this.updateButtonsStates(selectionData.editableSelection);
306+
this.updateNamespace();
307+
if (!this.config.disableFloatingToolbar) {
308+
this.updateToolbarVisibility(selectionData);
309+
if (!this.overlay.isOpen) {
310+
return;
311+
}
309312
}
313+
this.updateButtonsStates(selectionData.editableSelection);
310314
}
311315

312316
getFilterTraverseNodes() {
@@ -316,21 +320,12 @@ export class ToolbarPlugin extends Plugin {
316320
}
317321

318322
updateToolbarVisibility(selectionData) {
319-
this.updateNamespace();
320-
if (this.config.disableFloatingToolbar) {
321-
return;
322-
}
323-
324323
if (this.shouldBeVisible(selectionData)) {
325324
// Open toolbar or update its position
326325
const props = { toolbar: this.getToolbarInfo(), class: "shadow rounded my-2" };
327-
if (!this.overlay.isOpen) {
328-
// Open toolbar in compact mode
329-
this.isToolbarExpanded = false;
330-
}
331326
this.overlay.open({ props });
332327
} else if (this.overlay.isOpen && !this.shouldPreventClosing()) {
333-
this.overlay.close();
328+
this.closeToolbar();
334329
}
335330
}
336331

@@ -406,6 +401,11 @@ export class ToolbarPlugin extends Plugin {
406401
}
407402
this.updateSelection = null;
408403
}
404+
405+
closeToolbar() {
406+
this.overlay.close();
407+
this.isToolbarExpanded = false;
408+
}
409409
}
410410

411411
class MobileToolbarOverlay {

addons/html_editor/static/tests/toolbar.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,22 @@ test("toolbar opens in 'compact' namespace by default", async () => {
667667
expect(".o-we-toolbar").toHaveAttribute("data-namespace", "expanded");
668668
});
669669

670+
test.tags("desktop");
671+
test("expanded toolbar reopens in 'compact' namespace by default after closing", async () => {
672+
const { el } = await setupEditor("<p>[test]</p>");
673+
await waitFor(".o-we-toolbar");
674+
expect(".o-we-toolbar").toHaveAttribute("data-namespace", "compact");
675+
await expandToolbar();
676+
expect(".o-we-toolbar").toHaveAttribute("data-namespace", "expanded");
677+
// Collapse selection
678+
setContent(el, "<p>test[]</p>");
679+
await waitForNone(".o-we-toolbar");
680+
// Reopen toolbar
681+
setContent(el, "<p>[test]</p>");
682+
await waitFor(".o-we-toolbar");
683+
expect(".o-we-toolbar").toHaveAttribute("data-namespace", "compact");
684+
});
685+
670686
test("toolbar items without namespace default to 'expanded'", async () => {
671687
class TestPlugin extends Plugin {
672688
static id = "TestPlugin";

0 commit comments

Comments
 (0)