Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Bob Ippolito <[email protected]>
  • Loading branch information
citruscai and etrepum authored Dec 8, 2024
1 parent bdc7f34 commit b969c97
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ export class ListItemNode extends ParagraphNode {

const parent = this.getParent();
if ($isListNode(parent) && parent.getListType() === 'check') {
const listItemNode = $isListItemNode(prevNode) ? prevNode : null;
updateListItemChecked(dom, this, listItemNode, parent);
updateListItemChecked(dom, this, prevNode, parent);
}
// @ts-expect-error - this is always HTMLListItemElement
dom.value = this.__value;
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-list/src/formatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export function $handleListInsertParagraph(): boolean {
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
return false;
}
//Only run this code on empty list items
// Only run this code on empty list items

const anchor = selection.anchor.getNode();

Expand Down Expand Up @@ -526,7 +526,7 @@ export function $handleListInsertParagraph(): boolean {
newList.append(sibling);
});
}
//Don't leave hanging nested empty lists
// Don't leave hanging nested empty lists
$removeHighestEmptyListParent(anchor);
return true;
}
2 changes: 1 addition & 1 deletion packages/lexical-table/src/LexicalTableSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class TableSelection implements BaseSelection {
cellNodes.forEach((cellNode: TableCellNode) => {
const paragraph = cellNode.getFirstChild();
if ($isParagraphNode(paragraph)) {
format |= paragraph.getTextFormat() || 0;
format |= paragraph.getTextFormat();
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ function onSelectionChange(
lastNode instanceof ParagraphNode &&
lastNode.getChildrenSize() === 0
) {
selection.format = lastNode.getTextFormat() || 0;
selection.style = lastNode.getTextStyle() || '';
selection.format = lastNode.getTextFormat();
selection.style = lastNode.getTextStyle();
} else {
selection.format = 0;
}
Expand Down
26 changes: 9 additions & 17 deletions packages/lexical/src/nodes/LexicalParagraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {$isTextNode, TextFormatType} from './LexicalTextNode';

export type SerializedParagraphNode = Spread<
{
textFormat?: number;
textStyle?: string;
textFormat: number;
textStyle: string;
},
SerializedElementNode
>;
Expand All @@ -48,8 +48,8 @@ export type SerializedParagraphNode = Spread<
export class ParagraphNode extends ElementNode {
['constructor']!: KlassConstructor<typeof ParagraphNode>;
/** @internal */
__textFormat?: number;
__textStyle?: string;
__textFormat: number;
__textStyle: string;

constructor(key?: NodeKey) {
super(key);
Expand All @@ -63,7 +63,7 @@ export class ParagraphNode extends ElementNode {

getTextFormat(): number {
const self = this.getLatest();
return self.__textFormat || 0;
return self.__textFormat;
}

setTextFormat(type: number): this {
Expand All @@ -74,13 +74,7 @@ export class ParagraphNode extends ElementNode {

hasTextFormat(type: TextFormatType): boolean {
const formatFlag = TEXT_TYPE_TO_FORMAT[type];
const textFormat = this.getTextFormat() || 0;

if (textFormat === 0) {
return false;
}

return (textFormat & formatFlag) !== 0;
return (this.getTextFormat() & formatFlag) !== 0;
}

/**
Expand All @@ -91,12 +85,12 @@ export class ParagraphNode extends ElementNode {
getFormatFlags(type: TextFormatType, alignWithFormat: null | number): number {
const self = this.getLatest();
const format = self.__textFormat;
return toggleTextFormatType(format || 0, type, alignWithFormat);
return toggleTextFormatType(format, type, alignWithFormat);
}

getTextStyle(): string {
const self = this.getLatest();
return self.__textStyle || '';
return self.__textStyle;
}

setTextStyle(style: string): this {
Expand Down Expand Up @@ -194,9 +188,7 @@ export class ParagraphNode extends ElementNode {
const direction = this.getDirection();
newElement.setDirection(direction);
newElement.setFormat(this.getFormatType());
if (typeof this.getStyle() === 'string') {
newElement.setStyle(this.getStyle());
}
newElement.setStyle(this.getStyle());

this.insertAfter(newElement, restoreSelection);
return newElement;
Expand Down

0 comments on commit b969c97

Please sign in to comment.