From 2da93b56c596ed10da4a9f747202768516f47f7c Mon Sep 17 00:00:00 2001 From: Anurag Vasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Tue, 16 May 2023 13:23:07 +0530 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20callback=20to=20functi?= =?UTF-8?q?on=20`hasText()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/panels/design/textStyle/useRichTextFormatting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js b/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js index 55356894d9e8..5132ff5a6157 100644 --- a/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js +++ b/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js @@ -186,7 +186,7 @@ function useRichTextFormatting(selectedElements, pushUpdate) { useGlobalKeyDownEffect( { key: ['mod+b', 'mod+u', 'mod+i'] }, ({ key }) => { - if (!hasText) { + if (!hasText()) { return; } switch (key) { From 2ea1c81b3de0080c34ba4a6e5b5cb1ae7fa0fc48 Mon Sep 17 00:00:00 2001 From: Anurag Vasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Tue, 16 May 2023 15:54:00 +0530 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8F=97=20Fix:=20Add=20`type:=20'text'?= =?UTF-8?q?`=20to=20dummy=20element?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If attribute `type: 'text'` does not present it will `hasText()` will return `false` and following three dependent test will fails: - should set the text bold when the key command is pressed - should set the text underline when the key command is pressed - should set the text italics when the key command is pressed Co-Authored-By: Pascal Birchler --- .../src/components/panels/design/textStyle/test/textStyle.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/story-editor/src/components/panels/design/textStyle/test/textStyle.js b/packages/story-editor/src/components/panels/design/textStyle/test/textStyle.js index d10619fa0bf5..dac1210f29ba 100644 --- a/packages/story-editor/src/components/panels/design/textStyle/test/textStyle.js +++ b/packages/story-editor/src/components/panels/design/textStyle/test/textStyle.js @@ -85,6 +85,7 @@ const DEFAULT_PADDING = { const textElement = { id: '1', + type: 'text', textAlign: 'normal', fontSize: 30, lineHeight: 1, From a2a96e8fd6f966d91da4a87ac0629082a42b0a88 Mon Sep 17 00:00:00 2001 From: Anurag Vasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Tue, 16 May 2023 15:54:46 +0530 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20`hasText()`?= =?UTF-8?q?=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Pascal Birchler --- .../panels/design/textStyle/useRichTextFormatting.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js b/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js index 5132ff5a6157..b27402f376a4 100644 --- a/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js +++ b/packages/story-editor/src/components/panels/design/textStyle/useRichTextFormatting.js @@ -178,15 +178,12 @@ function useRichTextFormatting(selectedElements, pushUpdate) { }; }, [hasCurrentEditor, selectionActions, push, clearEditing, queuePush]); - const hasText = useCallback(() => { - const texts = selectedElements.filter(({ type }) => type === 'text'); - return texts.length > 0; - }, [selectedElements]); + const hasText = selectedElements.find(({ type }) => type === 'text'); useGlobalKeyDownEffect( { key: ['mod+b', 'mod+u', 'mod+i'] }, ({ key }) => { - if (!hasText()) { + if (!hasText) { return; } switch (key) {