-
-
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
Autoformatting styles trigger within inline code #1239
Comments
I've been thinking a bit about this and I first wanted to answer that it should be controlled by the schema. That these two attributes cannot exist at the same time. That'd disable the buttons as well as it should disable the autoformatting feature. But, we've got a problem here: autoformat was implemented incorrectly and it doesn't use commands but it set attributes directly. I even commented in the linked ticket that: "I think that the autoformat should abort doing any changes to the content if the command is disabled." One more thing that I'd like to check is whether disallowing an attribute based on another attribute works with the schema. I don't remember now what was the final decision about it. |
This check should be able to disable italic in bold: editor.model.schema.addAttributeCheck( ( context, attrName ) => {
if ( inTextWithBold( context ) && attrName == 'italic' ) {
return false;
}
} );
function inTextWithBold( context ) {
return context.endsWith( '$text' ) && context.last.getAttribute( 'bold' );
} I made a demo in https://jsfiddle.net/7Lrhxp0b/6/. It works, but only for non-collapsed selections. Which means that we've got some bug with how AttributeCommand checks |
Actually, autoformat does check the schema via: const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );
// Apply format.
formatCallback( writer, validRanges ); But it does not check whether it should remove the |
There are some more discussions about implementing this rule in https://github.com/ckeditor/ckeditor5-basic-styles/issues/77. There are some more aspects that one would need to take into consideration. That's one thing. The second thing is that we need to disable either those other inline styles in |
Please excuse my late reply, I've been on vacation for quite a while and only got to catch up open ends now.
My personal opinion is that within code, no other formatting should be possible. But I do not have much to base this opinion on, so it may be useless in this discussion. I wonder if the immediate issue could be addressed around by checking that an autoformatting character should only be triggered if it's not within a word boundary. I find it confusing that |
Side-note here. I stumbled upon this issue today. AutoFormat does not only run rogue here, if you type common variable and method names in Python (names with multiple underscores in them), then autoformat triggers sometimes (also sometimes it does not), if you keep typing, then it may also remove some characters that you typed before while you are typing new ones - even if you already finished a word like: I reported this behavior first to OpenProject, which uses ckeditor as well and recorded a video regarding this weird behavior: http://sendvid.com/p4aubuv8 |
There are two aspects to this issue:
|
I think they should ideally be available not only in inline code, but also in code blocks. This is useful for rich code snippets in tutorials — highlighting some part of the snippet for the reader, etc. |
BTW, a quick workaround is to use the schema configuration to control what styles can be applied in a // Disable italic in code:
editor.model.schema.addAttributeCheck( ( context, attrName ) => {
if ( inTextWithCode( context ) && attrName == 'italic' ) {
return false;
}
} );
function inTextWithCode( context ) {
return context.endsWith( '$text' ) && context.last.getAttribute( 'code' );
} This works fine (it also seems that we fixed the issues that I described in #1239 (comment). However, it makes italic completely disallowed in Therefore, the first point from #1239 (comment) would still help a lot. I'm adding this ticket to the current iteration with this scope:
|
I'm hoping to see this fixed soon. |
I've prepared a change that covers 1 & 2 from #1239 (comment)
But, I'm not sure if that's really enough, consider following scenario:
I'd expect it to result with <p>Text <code>code_here;</code> more text.<i>italic</i></p> , but without changing the RegExps that matches the <p>Text <code>code<i>here;</i></code><i> more text.</i>italic_</p> |
The behavior shown above is a result of Autoformatting taking the text from the entire line into consideration. At the F2F meeting with @oleq and @niegowski, we decided that the autoformatting feature, should not affect (Note: neither Github, Slack nor Notion support this) So, we would add another item to the scope: (Another rejected, but more breaking alternative was to make autoformat operate only on currently focused |
Let's make sure the feature does not collide with the |
Followup issues:
|
Fix (autoformat): Autoformatting should not occur inside an existing text with a model `code` attribute. Closes #1239.
🐞 Bug report
💻 Version of CKEditor
v11.0.1
Classic editor with at least enabled plugins:
📋 Steps to reproduce
text with _underscores_
.✅ Expected result
Autoformatting is not expanded within code element
❎ Actual result
Autoformatting rules expand within code element
📃 Other details that might be useful
This happens with all styles within autoformatting since there's no construct of where this will be disallowed. I wonder if maybe the autoformatting plugin could export an attribute that we can set to elements that will result in skipping extraction?
(It will also happen in the block code plugin elements, for example)
Add 👍 reaction to this post if you'd like to see this issue fixed.
The text was updated successfully, but these errors were encountered: