Skip to content

Commit

Permalink
keep selection style when clicking empty editor (#5292)
Browse files Browse the repository at this point in the history
Co-authored-by: keumky2 <[email protected]>
  • Loading branch information
youngkyo0504 and kyo-young authored Dec 4, 2023
1 parent 9836d54 commit 7753924
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ function onSelectionChange(
const [lastFormat, lastStyle, lastOffset, lastKey, timeStamp] =
collapsedSelectionFormat;

const root = $getRoot();
const isRootTextContentEmpty =
editor.isComposing() === false && root.getTextContent() === '';

if (
currentTimeStamp < timeStamp + 200 &&
anchor.offset === lastOffset &&
Expand All @@ -334,7 +338,7 @@ function onSelectionChange(
if (anchor.type === 'text') {
selection.format = anchorNode.getFormat();
selection.style = anchorNode.getStyle();
} else if (anchor.type === 'element') {
} else if (anchor.type === 'element' && !isRootTextContentEmpty) {
selection.format = 0;
selection.style = '';
}
Expand Down

2 comments on commit 7753924

@vercel
Copy link

@vercel vercel bot commented on 7753924 Dec 4, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

www.lexical.dev
lexicaljs.com
lexical.dev
lexical-fbopensource.vercel.app
lexical-git-main-fbopensource.vercel.app
lexicaljs.org

@vercel
Copy link

@vercel vercel bot commented on 7753924 Dec 4, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground-git-main-fbopensource.vercel.app
playground.lexical.dev
lexical-playground.vercel.app
lexical-playground-fbopensource.vercel.app

Please sign in to comment.