substance / lens

Lens - open science content creation and display
http://substance.io/lens
MIT License
124 stars 20 forks source link

Write proper selection handling code #19

Closed obuchtala closed 9 years ago

obuchtala commented 9 years ago

As here: https://github.com/substance/science-writer/blob/2d906772519e939bbaf665e1617cd818fcc84715/src/state_handlers.js#L20

It is not a sufficient treatment of selections. There are now 4 categories: sel.isNull() sel.isPropertySelection() sel.isContainerSelection() sel.isTableSelection()

As in the above case, the code suggests that you want to have property selections only. A good way is to do either

if (sel.isPropertySelection()) {
...
} else {
 ...
}

or using a guard:

if (!sel.isPropertySelection()) {
  return;
}