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

Fix font size update in table selection #6046

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,6 @@ export default function ToolbarPlugin({
}
}
// Handle buttons
setFontSize(
$getSelectionStyleValueForProperty(selection, 'font-size', '15px'),
);
setFontColor(
$getSelectionStyleValueForProperty(selection, 'color', '#000'),
);
Expand Down Expand Up @@ -654,6 +651,11 @@ export default function ToolbarPlugin({
: parent?.getFormatType() || 'left',
);
}
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
setFontSize(
$getSelectionStyleValueForProperty(selection, 'font-size', '15px'),
);
}
}, [activeEditor]);

useEffect(() => {
Expand Down
9 changes: 7 additions & 2 deletions packages/lexical-selection/src/range-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
TextNode,
} from 'lexical';

import {TableSelection} from '@lexical/table';
import {
$getAdjacentNode,
$getPreviousSelection,
Expand Down Expand Up @@ -517,7 +518,7 @@ function $getNodeStyleValueForProperty(
* @returns The value of the property for the selected TextNodes.
*/
export function $getSelectionStyleValueForProperty(
selection: RangeSelection,
selection: RangeSelection | TableSelection,
styleProperty: string,
defaultValue = '',
): string {
Expand All @@ -529,7 +530,11 @@ export function $getSelectionStyleValueForProperty(
const endOffset = isBackward ? focus.offset : anchor.offset;
const endNode = isBackward ? focus.getNode() : anchor.getNode();

if (selection.isCollapsed() && selection.style !== '') {
if (
$isRangeSelection(selection) &&
selection.isCollapsed() &&
selection.style !== ''
) {
const css = selection.style;
const styleObject = getStyleObjectFromCSS(css);

Expand Down
Loading