Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

I/6150: Make table cell properties UI aware of mult-cell selection. #253

Merged
merged 78 commits into from
Feb 28, 2020

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Feb 24, 2020

Suggested merge commit message (convention)

Enhancement: Add multi-cell selection to table cell properties UI. Closes ckeditor/ckeditor5#6150.


Additional information

This PR adds the ability to style selected table cells with basic logic for command value. I've extracted a follow for for multi-cell values handling as it looks optional and requires decisions.

@Reinmar: is this follow up OK? ckeditor/ckeditor5#6320

@coveralls
Copy link

coveralls commented Feb 24, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 3713344 on i/6150 into 379c022 on master.

@Reinmar
Copy link
Member

Reinmar commented Feb 26, 2020

cc @ckeditor/qa-team I'd love to have your 👀 on this

@oleq oleq self-requested a review February 27, 2020 09:25
@Mgsy
Copy link
Member

Mgsy commented Feb 27, 2020

Looks good, we haven't found any issues 👍

src/ui/utils.js Outdated
@@ -81,8 +81,7 @@ export function getBalloonTablePositionData( editor ) {
* @returns {module:utils/dom/position~Options}
*/
export function getBalloonCellPositionData( editor ) {
const firstPosition = editor.model.document.selection.getFirstPosition();
const modelTableCell = findAncestor( 'tableCell', firstPosition );
const modelTableCell = getSelectedTableCell( editor.model.document.selection.getFirstPosition() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the first range and adding there getSelectedElement()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you refer to the selection.getSelectedElement() (https://github.com/ckeditor/ckeditor5-engine/blob/bb4def6aac9d221034045f96c1be1f422ff67393/src/model/selection.js#L613-L623) then it is only checking for nodeAfter or nodeBefore whereas in table UI case we have two cases:

  1. A collapsed selection inside tableCell (here findAncestor( position ) works fine
  2. A multi-range selection in which ranges are set 'on' a tableCell - here it is the nodeAfter first position - but I can lookup API for an existing method on Range/Selection.

}

// Returns all selected table cells.
function getSelectedTableCells( model ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about this. What if there are two paragraphs in one td? Won't it return this cell twice?

Also, I don't like that there are actually two helper functions introduced in this single PR. Can't we have one, generic enough to cover all those cases? Optionally, two functions getSelectedTableCell( range ) and getSelectedTableCells( selection ) next to each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have a different purpose so renaming them might be better.

The getSelectedTableCell (described below) is used because selection might be collapsed inside table cell or set as a range on a table cell.

The getSelectedTableCells( selection ) is used to get all selected table cells from a document.selection and might be worth to revisit it for the cases found yesteraday for the purpose of TableSelection#hasMultiRangeSelection.

ps.: I'm going to revist those later today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so this one could be removed in favor of TableSelection.getSelectedTableCells() - I think that would be OK to use TableSelection plugin for this. The getSelecteTableCells() can be improved then (ie. in the ticke that touches undo problems).

buuut this would make TableSelection obligatory for TableProperties which I'm not sure how to handle.

Probably a generally accessible util method which all commands/plugins could use to get selected table cells (I'm thinking about other commands that should be now aware of the new option of selecting table cells (collapsed selection in TC or multi-range selection on TCs).

This way we will be having one way to get selected TC as an util (independent of loaded plugins) which will work both cases of selection. This could also invalidate need for getSelectedTableCell() which returns only one - you can always get one from all selected.

Copy link
Member

@Reinmar Reinmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented. I think we need more ordnung with these methods.


const everyCellHasAttribute = tableCell.every( tableCell => this._getAttribute( tableCell ) === firstCellValue );

return everyCellHasAttribute ? firstCellValue : undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is that somewhere in ckeditor/ckeditor5#6320 this helper will return 'multiple'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to have another property for multiple values (Command#values). But I didn't give a second thought to the 6320.

So this method might not change for the multiple display. I think that we should expose multiple values (or some getter to check for that case) in the command and implement how to show this in the UI. Command#values might be usable for other features and showing "multiple" in the form looks like a narrow case of the UI.

@oleq
Copy link
Member

oleq commented Feb 27, 2020

Committing all these suggestions will make my GH contribution graph black for the day :P

@jodator
Copy link
Contributor Author

jodator commented Feb 28, 2020

I've removed the export and made that utility method private in the UI tools where it belongs.

@Reinmar
Copy link
Member

Reinmar commented Feb 28, 2020

I reported followups for the mentioned issues in ckeditor/ckeditor5#6358 and ckeditor/ckeditor5#6357.

@Reinmar Reinmar merged commit 52acb0c into master Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align table properties UI to multi-range selection
5 participants