grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Can't select the model using editor.select()

Open naveen-15697 opened this issue 7 years ago • 7 comments

I am trying to select the first component in the editor by using editor.select(editor.DomComponents.getComponents().models[0]). It is not working.

naveen-15697 avatar Nov 11 '19 07:11 naveen-15697

select the first component in the editor

editor.select(editor.getComponents().models[0])

cheers!

pouyamiralayi avatar Nov 11 '19 08:11 pouyamiralayi

select the first component in the editor

editor.select(editor.getComponents().models[0])

cheers!

@pouyamiralayi , I tried this too. But it is not working.

naveen-15697 avatar Nov 11 '19 08:11 naveen-15697

@artf , @pouyamiralayi :I need this condition inside the 'canvas:drop' event editor.on('canvas:drop', ()=>{ ... ... // My code to select the first component is here //... ... })

naveen-15697 avatar Nov 11 '19 08:11 naveen-15697

@naveen-15697 you can achieve this with:

editor.on('block:drag:stop', (m) => {
    if(m){
       editor.select(editor.getComponents().models[0])
    }
})

cheers!

pouyamiralayi avatar Nov 11 '19 09:11 pouyamiralayi

@pouyamiralayi Thanks! It's working now.

@artf , But, Why it is not working in 'canvas:drop' event?

naveen-15697 avatar Nov 11 '19 09:11 naveen-15697

I think the selection is cleared somewhere after canvas:drop, I'll try to check it later

artf avatar Nov 16 '19 14:11 artf

i want to append dropped block at specific index. for example I want to append it at top of everything else. currently, I am doing this. but it is not working. Can anybody help? I am new to this.

editor.on('canvas:drop',(DataTransfer, model)=> { if (model.is('header')) { var index = 0; editor.getComponents().add(model, {at: index}); }
})

RutujaBadbe avatar Jan 29 '21 12:01 RutujaBadbe