简体   繁体   中英

Multiselect in fabric js without key modifier

I was wondering if there is a way to actively set multi-selection "mode" in fabric js canvas without holding down the shift?

I wish to activate multiselection by listening on a boolean value thats tied to a checkbox.

I have been reading through the fabricjs docs and haven't found anything regarding multi-select without the shift modifier key.

I'm uncertain if my request is valid but any pointers would be appreciated.

So basically I listen on the mouse:down event and checks if my boolean value is true/false, and if it's true i would like to go into multi-selection mode.

canvas.on('mouse:down', evt => {
  if(this.multiSelect) {
    // activate multi-select
 }
}

You can listen to the selection:created event and then push each new selection into an array that you will then use to create an ActiveSelection with multiple objects. When you set this.multiSelect to false you will need to also empty the multiSelection array. Something like this:

var multiSelection = [];
canvas.on('selection:created', selected => {
  if(this.multiSelect) {
    multiSelection.push(selected);
    var groupSelection = new fabric.ActiveSelection(multiSelection)
    canvas.setActiveObject(groupSelection);
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM