Skip to content

How to clear custom formatting from selected text? #1506

Open
@redfellow

Description

I'm using a custom plugin with active of:

		onClick: function (evt) {
			const languageMenu = this.context.languageMenu;
			const newNode = this.util.createElement('lang');
			newNode.classList.add("language");
			newNode.setAttribute("lang", languageMenu.selectedLanguage)
			this.nodeChange(newNode, null, ["lang"], null);
			this.submenuOff();
	  }

This creates a <lang lang="fi">the text that was selected</lang> in the editor. Works nicely, and changes the selected text between chosen languages.

I have another action which uses nodeChange(null, null ["lang"], null); to reset the formatting.

Case 1 (Works): Reset exact selection back to plaintext by using nodeChange with first parameter null
Image

Case 2 (Nothing happens): Reset overlapping selection back to plaintext by using nodeChange with first parameter null

Image

Case 3 (Multiple tags): Change language with overlapping selection creates two new nodes, and leaves the old node in the middle.

Image

Now I found a way to work around case 3 using mergeSameTags, so that's fine, but I might be going at it the wrong way, any input is welcome.

What I'm really struggling with is Case 2, and the only way I managed to get it to work was to manually look for lang tags and just unwrap them, losing the active selection in the process.

What would be the correct way to clear the custom formatting?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions