Voog / wysihtml

Open source rich text editor for the modern web
http://wysihtml.com
MIT License
3.36k stars 337 forks source link

Keep cells selection #280

Open Oviglo opened 8 years ago

Oviglo commented 8 years ago

Hi, I my editor I have a bootstrap dropdown for add cells (above, before etc.) the selected cells. But when un click on the drop down I wysihtml leave the cell selection, I set the cursor at the good position but the class "wysiwyg-tmp-selected-cell" is removing and the command don't work.

Can you help me please ? Thanks.

Oviglo commented 8 years ago

Hello, do you have informations about this ? I need to fix it for my client.

pulges commented 8 years ago

What do you mean by un-clicking dropdown.

Usually the logic of menus is that whole menu and action buttons should catch click events by event.stopPropagation() and event.preventDefault(), so the selection does not get removed from editable area. If selection removal is needed (ex. user has to write something to input). Then the previous selection must be saved before focus is lost/menu with input is opened:

var bookmark =  editor.composer.selection.getBookmark();

and later before command is triggered the selection is restored:

editor.composer.selection.serBookmark(bookmark);
Oviglo commented 8 years ago

I try to save bookmark but it unselect cells:

kepp_cell_1 kepp_cell_2

If I select text it works, just the "wysiwyg-tmp-selected-cell" is removed

Oviglo commented 8 years ago

OK it work after add this function:

[code] $('.dropdown-toggle').click(function(event) { event.preventDefault(); var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end); setTimeout(function() { composer.tableSelection.select(tableSelect.start, tableSelect.end); },0); });[/code]

pulges commented 8 years ago

Does it not work this way?

 $('.dropdown-toggle').click(function(event) {
    event.preventDefault();
    event.stopPropagation();
 });
Oviglo commented 8 years ago

The dropdown menu don't work with the stopPropagation function.

pulges commented 8 years ago

if toggle button parents need to listen to the click events of toggle buttons you must do the stopPropagation of click on parent elements, so the click bubbles to the listener but not further to document body.

http://www.quirksmode.org/js/events_order.html