Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clear custom formatting from selected text? #1506

Open
redfellow opened this issue Jan 28, 2025 · 1 comment
Open

How to clear custom formatting from selected text? #1506

redfellow opened this issue Jan 28, 2025 · 1 comment
Labels

Comments

@redfellow
Copy link

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?

@JiHong88
Copy link
Owner

this.nodeChange(null, null, null, null);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants