Skip to content

Problem with 2 editors on one html page #110

@atatanasov

Description

@atatanasov

Replication steps:

  1. Format a text in editor 1 in bold
  2. Move the mouse to editor 2

Actual Result: Bold button in the second editor is selected
Expected Results: only the bold button in the first editor is selected

I added the following code in order to fix this:

getSelectedNode = function ()
{
	if (document.selection) {
	    return document.selection.createRange().parentElement();
	}
	else
	{
	    var selection = window.getSelection();
	    if (selection.rangeCount > 0) {
	        return selection.getRangeAt(0).startContainer.parentNode;
	    }
	}
},
updateToolbar = function () {
	if (options.activeToolbarClass) {
		$(options.toolbarSelector).find(toolbarBtnSelector).each(function () {
			var commandArr = $(this).data(options.commandRole).split(' '),
				command = commandArr[0];

			// If the command has an argument and its value matches this button. == used for string/number comparison
			if (commandArr.length > 1 && document.queryCommandEnabled(command) && document.queryCommandValue(command) === commandArr[1]) {
				$(this).addClass(options.activeToolbarClass);
			// Else if the command has no arguments and it is active
			} else if (commandArr.length === 1 && document.queryCommandEnabled(command) && document.queryCommandState(command) && $.contains($(this).closest('.bs-editor')[0], getSelectedNode())) {
				$(this).addClass(options.activeToolbarClass);
			// Else the command is not active
			} else {
				$(this).removeClass(options.activeToolbarClass);
			}
		});
	}
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions