Browse Source

Imporved ContextualToolbar manual test.

Oskar Wróbel 8 years ago
parent
commit
0f68ac361a

+ 2 - 1
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.html

@@ -1,5 +1,6 @@
 <div id="editor">
-	<p><i>This</i> is a <strong>first line</strong> of text.</p>
+	<p><em>ContextualToolbar</em> won't show for the first block element.</p>
+	<p><em>This</em> is a <strong>first line</strong> of text.</p>
 	<p><em>This</em> is a <strong>second line</strong> of text.</p>
 	<p><em>This</em> is the <strong>end</strong> of text.</p>
 </div>

+ 12 - 0
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.js

@@ -8,6 +8,7 @@
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
 import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
+import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 ClassicEditor.create( document.querySelector( '#editor' ), {
 	plugins: [ ArticlePresets, ContextualToolbar ],
@@ -16,6 +17,17 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
 } )
 .then( editor => {
 	window.editor = editor;
+
+	const contextualToolbar = editor.plugins.get( 'ContextualToolbar' );
+
+	contextualToolbar.on( 'show', evt => {
+		const selectionRange = editor.document.selection.getFirstRange();
+		const blockRange = Range.createOn( editor.document.getRoot().getChild( 0 ) );
+
+		if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
+			evt.stop();
+		}
+	} );
 } )
 .catch( err => {
 	console.error( err.stack );

+ 1 - 0
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.md

@@ -3,3 +3,4 @@
 1. Create a non–collapsed selection.
 2. Create another non–collapsed selection but in another direction.
 3. For each selection, a contextual toolbar should appear and the beginning/end of the selection, duplicating main editor toolbar.
+4. Toolbar should not display when selection is placed in the first block element.