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

ContextualToolbar doesn't respect viewportTopOffset #5412

Closed
fredck opened this issue Sep 28, 2017 · 7 comments
Closed

ContextualToolbar doesn't respect viewportTopOffset #5412

fredck opened this issue Sep 28, 2017 · 7 comments
Labels
package:ui resolution:duplicate This issue is a duplicate of another issue and was merged into it. type:feature This issue reports a feature request (an idea for a new functionality or a missing option).

Comments

@fredck
Copy link
Contributor

fredck commented Sep 28, 2017

Just like the StickyToolbarView, ContextualToolbar should use viewportTopOffset to calculate the position of the toolbar and avoid displaying it above (or bellow) page elements that define top boundaries.

This happens in the documentation, for example:

image

@Reinmar
Copy link
Member

Reinmar commented Sep 28, 2017

Is this critical enough to fix it in it12?

@fredck
Copy link
Contributor Author

fredck commented Sep 29, 2017

I don't feel that this is extremely critical. Maybe @oleq consider this an easy fix.

@oleq
Copy link
Member

oleq commented Sep 29, 2017

Truth to tell, it's all about setting the ContextualBalloon#positionLimiter to a function that returns a Rect that excludes the top bar's height from the editor.editing.view.selection.editableElement's rect.

@oskarwrobel
Copy link
Contributor

@oleq
Copy link
Member

oleq commented Sep 29, 2017

A quick workaround:

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';

const offset = 100;

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		plugins: [ ArticlePluginSet, ContextualToolbar ],
		toolbar: {
			items: [ 'bold', 'link' ]
		},
		contextualToolbar: [ 'bold', 'link' ]
	} )
	.then( editor => {
		editor.plugins.get( 'ContextualBalloon' ).positionLimiter = () => {
			const view = editor.editing.view;
			const editableElement = view.selection.editableElement;

			if ( editableElement ) {
				const rect = new Rect( view.domConverter.mapViewToDom( editableElement.root ) );
				const difference = offset - rect.top;

				if ( difference > 0 ) {
					rect.moveBy( 0, difference );
					rect.height -= difference;
					rect.bottom -= difference;
				}

				return rect;
			}

			return null;
		};

		window.editor = editor;
	} )
	.catch( err => {
		console.error( err.stack );
	} );

It will also change the behavior of the link balloon, etc.

kapture 2017-09-29 at 13 43 08

@Reinmar
Copy link
Member

Reinmar commented Sep 29, 2017

If it's not critical, why are we spending time on it now :|? All of us have more important things to do and I can see that @oleq already spent on this half an hour.

@mlewand mlewand transferred this issue from ckeditor/ckeditor5-ui Oct 9, 2019
@mlewand mlewand added this to the backlog milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:feature This issue reports a feature request (an idea for a new functionality or a missing option). package:ui labels Oct 9, 2019
@dawidurbanski dawidurbanski removed this from the backlog milestone Aug 10, 2021
@dawidurbanski dawidurbanski added the resolution:duplicate This issue is a duplicate of another issue and was merged into it. label Aug 10, 2021
@dawidurbanski
Copy link
Contributor

It's a duplicate of #9892

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:ui resolution:duplicate This issue is a duplicate of another issue and was merged into it. type:feature This issue reports a feature request (an idea for a new functionality or a missing option).
Projects
None yet
Development

No branches or pull requests

6 participants