Skip to content

Commit

Permalink
Fix logic error in UI event emit code (bokeh#14059)
Browse files Browse the repository at this point in the history
* Fix logic error in UI event emit code

* Add unit regression tests
  • Loading branch information
mattpap authored Sep 12, 2024
1 parent 360e38e commit f1824dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bokehjs/src/lib/core/ui_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ export class UIEventBus {
} else {
let result = false
for (const tool of this._tools.keys()) {
result ||= emit(tool)
// don't conflate these lines because of short circuiting nature of ||= operator
const emitted = emit(tool)
result ||= emitted
}
return result
}
Expand Down
22 changes: 22 additions & 0 deletions bokehjs/test/unit/regressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {gridplot} from "@bokehjs/api/gridplot"
import {Spectral11, Viridis11, Viridis256} from "@bokehjs/api/palettes"
import {defer, paint, poll} from "@bokehjs/core/util/defer"
import type {Field} from "@bokehjs/core/vectorization"
import type {ToolName} from "@bokehjs/api/figure"

import {UIElement, UIElementView} from "@bokehjs/models/ui/ui_element"
import type {GlyphRendererView} from "@bokehjs/models/renderers/glyph_renderer"
Expand Down Expand Up @@ -1664,4 +1665,25 @@ describe("Bug", () => {
}
})
})

describe("in issue #14058", () => {
it("doesn't allow emitting UI events for all but the first tool", async () => {
async function test(tools: ToolName[], active_drag: ToolName) {
const p = fig([200, 200], {tools, active_drag})
const gr = p.scatter([1, 2, 3], [1, 2, 3], {size: 20})
gr.data_source.selected.indices = [1]
const {view} = await display(p)
expect(gr.data_source.selected.indices).to.be.equal([1])
const ev = new KeyboardEvent("keyup", {key: "Escape"})
document.dispatchEvent(ev)
await view.ready
expect(gr.data_source.selected.indices).to.be.equal([])
}

await test(["box_select", "lasso_select"], "box_select")
await test(["box_select", "lasso_select"], "lasso_select")
await test(["lasso_select", "box_select"], "box_select")
await test(["lasso_select", "box_select"], "lasso_select")
})
})
})

0 comments on commit f1824dc

Please sign in to comment.