-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 create a command that will change text color? #481
Comments
Hi Dusan! Thanks for the kind words :) The documentation is (unfortunately) still work in progress. We first focused on generating the API docs as we had the content already (in the code) but we needed a system to present them. You can see nightly builds of them on https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/api/index.html. They are not reviewed yet, but they are pretty complete (although, we definitely need a lot more examples). As for guides on how to write commands and how to build features in general, there's nothing yet. But if you'd like to try I can give you some hints and based on the existing code you should be able to figure out the rest. First of all, some very brief introduction to the architecture of the engine. Then, the ckeditor5-basic-styles package. It contains two features – bold and italic. Text color will be pretty similar to them, so it'll be a good read. So, how to start?
This introduction is like 1/10th of what should be written in such a tutorial, but hopefully it will let you start hacking the editor. Good luck :) |
@Reinmar Thank you! One more question. Is any event raised when a text with some text color is selected? |
I assume you're asking about how to refresh your command? How to know when the selection is in a text with some color applied and when it's not? The most reliable and the simplest way to know where to refresh a state of a command is to listen to (Side note: We're planning to change this API too.) So, listening to that event is the easiest solution. And the Going to the second part of the question – how to check if some text color is selected? First of all, we need to define what "text color is selected" means? Without going into the details why, for us, a style (like text color) is selected if the selection starts inside it or right after. In the previous post I mentioned that text nodes have attributes. Guess what? Selection has attributes too :) Quick justification – how do we represent change in the model for Ctrl+B pressed on a collapsed selection? We set the What's more – document selection's ( this.value = editor.document.selection.hasAttribute( 'bold' ); See the code. Side note: Most of state changes in CKEditor 5 can be observer. Selection attributes changes fire const sel = editor.document.selection;
sel.on( 'change:attribute', () => {
console.log( sel.getAttribute( 'textColor' ) );
} ); |
I used it as above, but it didn't work... |
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue. |
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue. |
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it). |
First, thank you! CKE5 is what we all have been waiting for :) I would like to use it right now, but I don't actually understand how to build custom commands. Is it documented somewhere? Can you explain what is required to create a command that will change text color (or inline style in general)?
The text was updated successfully, but these errors were encountered: