-
Notifications
You must be signed in to change notification settings - Fork 60
[IMP] style,format: add default style & format #6762
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
base: master
Are you sure you want to change the base?
Conversation
Add style and format sheet/col/row default. This task is groundwork for the infinite viewport. Task: 4852413
0478283
to
4217257
Compare
@@ -58,8 +60,8 @@ export class CellClipboardHandler extends AbstractCellClipboardHandler< | |||
const pivotFormula = createPivotFormula(formulaPivotId, pivotCell); | |||
cell = { | |||
id: cell?.id || "", | |||
style: cell?.style, | |||
format: cell?.format, | |||
style: style, |
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.
style: style, | |
style, |
Same everywhere
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.
it is unclear to me while reading what cell.style
is supposed be when there are default values.
As a more general comment, I think now it might be a good idea to move all the style management out of the cell
core plugin to its own dedicated plugin and remove cell.style
. We could use cell ids to set a style on specific cells to avoid all range adaptations etc.)
I didn't check every use of cell.style
to see how it would change (there seems be a bit more than 40 uses)
WDYT ?
style: cell?.style, | ||
format: evaluatedCell.format, | ||
style: style, | ||
format: evaluatedCell.format ?? format, |
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 evaluatedCell.format
be the actual format (including the default format)
@@ -47,9 +47,17 @@ import { | |||
import { CorePlugin } from "../core_plugin"; | |||
import { PositionMap } from "../ui_core_views/cell_evaluation/position_map"; | |||
|
|||
interface sheetDefault<T> { |
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.
interface sheetDefault<T> { | |
interface SheetDefault<T> { |
@@ -449,9 +498,18 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState { | |||
} | |||
|
|||
getCellStyle(position: CellPosition): Style { | |||
return this.getters.getCell(position)?.style || {}; | |||
return this.getters.getCell(position)?.style || this.getDefaultCellStyle(position) || {}; |
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.
return this.getters.getCell(position)?.style || this.getDefaultCellStyle(position) || {}; | |
return this.getters.getCell(position)?.style ?? this.getDefaultCellStyle(position) ?? {}; |
this.defaultStyle[sheetId]?.cols?.[col] | ||
); | ||
this.history.update( | ||
"defaultFormat", | ||
sheetId, | ||
"cols", | ||
col, | ||
this.defaultFormat[sheetId]?.cols?.[col] |
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 it be refColumn
🤔 ? (-> tests are missing)
this.defaultStyle[sheetId]?.cols?.[col] | |
); | |
this.history.update( | |
"defaultFormat", | |
sheetId, | |
"cols", | |
col, | |
this.defaultFormat[sheetId]?.cols?.[col] | |
this.defaultStyle[sheetId]?.cols?.[refColumn] | |
); | |
this.history.update( | |
"defaultFormat", | |
sheetId, | |
"cols", | |
col, | |
this.defaultFormat[sheetId]?.cols?.[refColumn] |
for (const cell of this.getters.getCellFromZone( | ||
sheetId, | ||
this.getters.getColsZone(sheetId, refColumn, refColumn) | ||
)) { | ||
const { row } = this.getters.getCellPosition(cell.id); |
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.
for (const cell of this.getters.getCellFromZone( | |
sheetId, | |
this.getters.getColsZone(sheetId, refColumn, refColumn) | |
)) { | |
const { row } = this.getters.getCellPosition(cell.id); | |
for (let row = 0; row < this.getters.getSheetSize(sheetId).numberOfRows; row++) { |
smaller, faster ?
Or maybe it's because sheet won't have a numberOfRows
with the infinite viewport ?
In that case:
for (const cell of this.getters.getCellFromZone( | |
sheetId, | |
this.getters.getColsZone(sheetId, refColumn, refColumn) | |
)) { | |
const { row } = this.getters.getCellPosition(cell.id); | |
for (let row = 0; row < this.getters.getColsZone(sheetId, refColumn, refColumn).bottom; row++) { |
} | ||
} | ||
|
||
private updateCellStyleWithDefault(cell: Cell, style: Style | undefined) { |
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 don't understand when this method should be called. There's "default" in it's name but there's nothing related to this.defaultStyle
in here. Also, I don't understand the deepEquals(cellStyle, style) ? null : cellStyle
part where the style is reset. Why should it be reset ?
EDIT:
Also, I don't understand the
deepEquals(cellStyle, style) ? null : cellStyle
part where the style is reset. Why should it be reset ?
Ah ! is it because style
is the same as the default style and it means it can be removed from the cell ? If yes, then I think it doesn't really matter if cell.style
is equal to the default style if it simplifies the code and it avoids a deepEquals
.
It could also be named more simply to something like addStyle
sheetId, | ||
col, | ||
row, | ||
style: deepEquals(cellStyle, style) ? null : cellStyle, |
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.
at this point, we know the cell doesn't exist, so updating the style to null
is useless
defaultStyle: Record<UID, sheetDefault<Style> | undefined>; | ||
defaultFormat: Record<UID, sheetDefault<Format> | undefined>; |
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 import/export from/to json
const cells = this.getters.getRowCells(sheetId, row); | ||
let maxHeight = 0; | ||
let tallestCell: CellWithSize | undefined = undefined; | ||
for (let i = 0; i < cellIds.length; i++) { | ||
const cell = this.getters.getCellById(cellIds[i]); | ||
if (!cell) { | ||
continue; | ||
} | ||
for (const cell of cells) { |
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.
👍
@@ -173,3 +173,38 @@ describe("styles", () => { | |||
); | |||
}); | |||
}); | |||
|
|||
describe("Default Styles", () => { |
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 tests for (at least):
- copy-paste
- add/remove col/rows
- duplicate sheet
- add default on top of existing style
- add style on top of existing default
I was thinking more yesterday evening. Why do we make a difference between the global/full rows/full cols and specific cells ? Couldn't we just apply style on ranges everywhere ? (if we remove |
Description:
description of this task, what is implemented and why it is implemented that way.
Task: TASK_ID
review checklist