Skip to content

Commit

Permalink
fix(dia.ToolsView): make sure tools are rendered before the first update
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus committed Dec 1, 2024
1 parent 66ab6b7 commit 49f7913
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/joint-core/src/dia/ToolsView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,7 @@ export const ToolsView = mvc.View.extend({
const tool = tools[i];
tool.updateVisibility();
if (!tool.isVisible()) continue;
if (!this.isRendered) {
// There is at least one visible tool
this.isRendered = Array(n).fill(false);
}
if (!this.isRendered[i]) {
// First update executes render()
tool.render();
this.isRendered[i] = true;
} else if (opt.tool !== tool.cid) {
if (this.ensureToolRendered(tools, i) && opt.tool !== tool.cid) {
tool.update();
}
}
Expand All @@ -79,6 +71,20 @@ export const ToolsView = mvc.View.extend({
return this;
},

ensureToolRendered(tools, i) {
if (!this.isRendered) {
// There is at least one visible tool
this.isRendered = Array(tools.length).fill(false);
}
if (!this.isRendered[i]) {
// First update executes render()
tools[i].render();
this.isRendered[i] = true;
return false;
}
return true;
},

focusTool: function(focusedTool) {

var tools = this.tools;
Expand All @@ -103,7 +109,7 @@ export const ToolsView = mvc.View.extend({
tool.show();
// Check if the tool is conditionally visible too
if (tool.isVisible()) {
tool.update();
this.ensureToolRendered(tools, i) && tool.update();
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions packages/joint-core/test/jointjs/dia/linkTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ QUnit.module('linkTools', function(hooks) {
button2UpdateSpy.restore();
});
});


QUnit.test('show()', function(assert) {
paper.freeze();
const remove = new joint.linkTools.Vertices();
const toolsView = new joint.dia.ToolsView({ tools: [remove] });
linkView.addTools(toolsView);
linkView.hideTools();
paper.unfreeze();
assert.notOk(toolsView.isRendered);
linkView.showTools();
assert.ok(toolsView.isRendered);
});
});

QUnit.module('RotateLabel', function() {
Expand Down

0 comments on commit 49f7913

Please sign in to comment.