www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit f773af1b8acd152ed4fe20e8cc43ff4017d81992
parent c9176ce3d6772a59f3f8380eea449040ba419cd6
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Thu, 17 Oct 2024 10:05:09 -0700

Separate selection concatnation into it's own function

It will be used in the future somewhere else, and also it's just
easier to read.

Diffstat:
Mfiles/floorplans/floorplan/main.js | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -562,13 +562,7 @@ function selectionHandler(event, editor) { if (!State.selectMode) { sel.select() } else { - let selection = editor.draw.find(".selected") - let i = selection.indexOf(sel) - if (i >= 0) { - selection.splice(i, 1) - } else { - selection.push(sel) - } + let selection = addSelection(editor, sel, true) if (selection.length === 0) { editor.draw.select() } else { @@ -610,6 +604,25 @@ function keyHandler(ev, editor) { handled(ev) } +function addSelection(editor, objects, flip) { + if (!Array.isArray(objects)) { + objects = [objects] + } + + let sel = editor.draw.find(".selected") + for (let i = 0; i < objects.length; ++i) { + let si = sel.indexOf(objects[i]) + if (si >= 0) { + if (flip) { + sel.splice(si, 1) + } + } else { + sel.push(objects[i]) + } + } + return sel +} + function radioMenu(editor, key, values, initial, options) { options = options ?? {} options.callbacks = options.callbacks ?? {}