-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
I'm wondering if we should disable heading command when selection is in the title element? The document title is always represented as a Is it possible to set some shema rules for that? Tell schema that title element cannot be renamed? |
Make sure that title integrates well with the placeholder support (https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/features/editor-placeholder.html) I think that placeholder if defined should be the placeholder for the body element. If not defined you should use "Body" as a default option. |
I think it should be disabled. During testing, I noticed that heading dropdown is active and I tried to convert the title into a heading/paragraph, so for me it indicates that if it's active, I can do something with it. |
Yep, I'm working on it. |
…oll it by schema.
Known issue ckeditor/ckeditor5#2010 |
Steps to reproduce
Current resultThe editor crashes. Error
GIF |
@oskarwrobel - from my manual tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found some things to iron out - to not block you I'll R- now and will check the tests later.
src/title.js
Outdated
} from '@ckeditor/ckeditor5-engine/src/view/placeholder'; | ||
|
||
// List of model elements that are allowed to be renamed to title element. | ||
const allowedToBeTitle = new Set( [ 'heading1', 'heading2', 'heading3', 'paragraph' ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing heading4...6
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/features/title.md
Outdated
|
||
## Keyboard navigation | ||
|
||
Title plugin lets you navigate between title and body elements using <kbd>Tab</kbd> key and back, using <kbd>Shift</kbd> + <kbd>Tab</kbd>, providing form-like experience. You can also use <kbd>Enter</kbd> and <kbd>Backspace</kbd> keys to move caret between title and body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs should be more precise. Shift+Tab works only when selection is at the beginning of the "body" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this explanation to the docs.
src/title.js
Outdated
|
||
model.schema.addChildCheck( ( context, childDefinition ) => { | ||
// Allow `title` element only directly inside a root. | ||
if ( childDefinition.name === 'title' && !context.endsWith( '$root' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be handled by: allowIn: '$root'
in schema.register()
?It bloats this check - it wis for two different items and the if below is already "big".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was afraid it won't disallow title
element inside a blockQuote
(because of inheritAllFrom: '$block'
). Works fine after the change 👌
src/title.js
Outdated
// Allow only `title-content` inside `title`. | ||
if ( | ||
context.endsWith( 'title' ) && childDefinition.name !== 'title-content' || | ||
childDefinition.name === 'title-content' && !context.endsWith( 'title' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this second check covered by schema definition allowIn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked the tests with:
model.schema.addChildCheck( ( context, childDefinition ) => {
// Allow only `title-content` inside `title`.
if ( context.endsWith( 'title' ) && childDefinition.name !== 'title-content' ) {
return false;
}
} );
and only schema rules test fails so either we can simplify this or add more tests.
ps.: I didn't read the tests yet ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.. I was wrong because of inheritAllFrom
there. So Now I'm not sure if we shouldn't make this more specific in the first place? Either by inheriting only those required options or by manually defining the title
and title-content
with full schema.
It looks like more straight-forward then allowing all there and then adding callback to check only those allowed scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'll define title
and title-content
manually.
src/title.js
Outdated
const view = editor.editing.view; | ||
const viewRoot = view.document.getRoot(); | ||
|
||
const bodyPlaceholder = editor.config.get( 'placeholder' ) || 'Body'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check this but I feel that we should make those strings ('Title'
& 'Body'
) translate-able.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No doubts. I'll change it.
src/title.js
Outdated
_getTitleElement() { | ||
const root = this.editor.model.document.getRoot(); | ||
|
||
return Array.from( root.getChildren() ).find( element => element.is( 'title' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will return undefined
not null
if element is not found in the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
src/title.js
Outdated
* @returns {String} Title of the document. | ||
*/ | ||
getTitle() { | ||
const title = this.editor.model.document.getRoot().getChild( 0 ).getChild( 0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that we have a post-fixer but I would feel safer with using getTitleElement()
, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or OTOH - maybe add a comment about that post-fixer takes care of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm..... I was thinking about using getTitleElement()
but finally decided to do it as it is. getTitleElement()
it's an additional call of Array.from
and Array.find
. As you wrote, post-fixer takes care of this structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this.
const titleChildren = Array.from( title.getChildren() ); | ||
let hasChanged = false; | ||
|
||
titleChildren.shift(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment about preserving of the first child? (I wonted to write firstborn 😆)
tests/manual/title.md
Outdated
@@ -0,0 +1,28 @@ | |||
## Title feature | |||
|
|||
- you should see `Title` and `Body` placeholders when there is no text in any of sections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- you should see `Title` and `Body` placeholders when there is no text in any of sections. | |
- you should see `Title` and `Body` placeholders when there is no text in any of the sections. |
I think mention balloon should be not displayed in the text where |
It's enabled now. |
I fixed this scenario however this error is still reproducible.
I hope I'm wrong but it can be a bug in OT. [Edit] I was debugging this for a while and I found the way to prevent this exception but this is something for the exorcist @scofalik ckeditor/ckeditor5#2022. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found that one case wasn't tested (defined). Als I would take a different approach in the post fixer as it si a quite big.
docs/features/title.md
Outdated
|
||
## Keyboard navigation | ||
|
||
Title plugin lets you navigate between title and body elements using <kbd>Tab</kbd> key and back, using <kbd>Shift</kbd> + <kbd>Tab</kbd>, providing form-like experience. You can also use <kbd>Enter</kbd> and <kbd>Backspace</kbd> keys to move caret between title and body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this explanation to the docs.
src/title.js
Outdated
const selection = model.document.selection; | ||
const selectedElements = Array.from( selection.getSelectedBlocks() ); | ||
|
||
if ( selectedElements.length === 1 && selectedElements[ 0 ].name === 'title-content' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectedElements[ 0 ].is( 'title-content' )
296820c
to
454325d
Compare
Suggested merge commit message (convention)
Feature: Introduced Title plugin. Closes ckeditor/ckeditor5#2003. Closes ckeditor/ckeditor5#2005.
Additional information
For example – encountered issues, assumptions you had to make, other affected tickets, etc.