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

Position table cell properties balloon in relation to multiple-cell #6357

Closed
Reinmar opened this issue Feb 28, 2020 · 3 comments · Fixed by ckeditor/ckeditor5-table#291
Closed
Assignees
Labels
domain:ui/ux This issue reports a problem related to UI or UX. intro Good first ticket. package:table type:improvement This issue reports a possible enhancement of an existing feature.

Comments

@Reinmar
Copy link
Member

Reinmar commented Feb 28, 2020

📝 Provide a description of the improvement

Right now we position the balloon relatively to the first selected cell (getTableCellAtPosition() in ui/utils.js). Position utils accept rects, DOM elements or DOM ranges. We can easily create a DOM range which starts before the first selected cell and ends after the last selected cell.


If you'd like to see this improvement implemented, add a 👍 reaction to this post.

@Reinmar Reinmar added type:improvement This issue reports a possible enhancement of an existing feature. package:table domain:ui/ux This issue reports a problem related to UI or UX. labels Feb 28, 2020
@remigasas
Copy link

A welcome improvement.

Could this "Table properties" balloon be improved ? Right now, when clicked at the top of table it will be displayed on top, and in case, when table is first thing inside page it will overflow.

table_properties_overflow2

Also, in large tables ( when table top/bottom is not visible ) it is not possible to change cell properties without scrolling ( it is also not clear from user perspective, how to, as controls are not visible )

@Reinmar Reinmar added this to the iteration 31 milestone Mar 26, 2020
@Reinmar Reinmar added the intro Good first ticket. label Mar 26, 2020
@oleq
Copy link
Member

oleq commented Mar 26, 2020

Cake recipe

export function getBalloonCellPositionData( editor ) {
	const modelRanges = [ ...editor.model.document.selection.getRanges() ];

	// Multi-cell selection.
	if ( modelRanges.length > 1 ) {
		// A range enclosing all cells.
		const scopeRange = editor.model.createRange( modelRanges[ 0 ].start, modelRanges[ modelRanges.length - 1 ].end );
		const viewRange = editor.editing.mapper.toViewRange( scopeRange );
		const domRange = editor.editing.view.domConverter.viewRangeToDom( viewRange );

		return {
			target: () => {
				const domRangeRect = domRange.getBoundingClientRect();
				const rect = new Rect( domRangeRect );

				return rect;
			},
			positions: BALLOON_POSITIONS
		};
	}

	// Selection in a table cell.
	else {
		const modelTableCell = getTableCellAtPosition( editor.model.document.selection.getFirstPosition() );
		const viewTableCell = editor.editing.mapper.toViewElement( modelTableCell );

		return {
			target: editor.editing.view.domConverter.viewToDom( viewTableCell ),
			positions: BALLOON_POSITIONS
		};
	}
}

@oleq
Copy link
Member

oleq commented Mar 26, 2020

The recipe works but it's not elegant. The thing is that instead of

const domRange = editor.editing.view.domConverter.viewRangeToDom( viewRange );

return {
	target: () => {
		const domRangeRect = domRange.getBoundingClientRect();
		const rect = new Rect( domRangeRect );

		return rect;
	},
	positions: BALLOON_POSITIONS
};

it should be

const domRange = editor.editing.view.domConverter.viewRangeToDom( viewRange );

return {
	target: domRange,
	positions: BALLOON_POSITIONS
};

but ATM the Rect class that would normally accept the DOMRange does it in a wrong way, which results in a Rect of (most likely) the first cell only (because there are multiple DOMRects in domRect.getClientRects()).

It's been year since I wrote this Rect.getDomRangeRects( source )[ 0 ] in Rect#constrcutor() and something tells me that it had something to do with Safari which didn't support DOMRange#getBoundingClientRect() back then (or was it Edge?). Anyway, maybe it's time we finally figured it out in this issue because to me copyRectProperties( this, source.getBoundingClientRect() ); sounds like a natural choice.

jodator added a commit to ckeditor/ckeditor5-table that referenced this issue Mar 30, 2020
Other: The position of table cell properties balloon should be in relation to multiple selected cells. Closes ckeditor/ckeditor5#6357.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:ui/ux This issue reports a problem related to UI or UX. intro Good first ticket. package:table type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
4 participants