From bfef0410e54e613a8bb457a08e55c8c052fcfd84 Mon Sep 17 00:00:00 2001 From: Kevin Batdorf Date: Thu, 17 Nov 2022 02:50:52 -0500 Subject: [PATCH] Fix editor line number spacing when padding disabled --- src/block.json | 4 ++-- src/editor/editor.css | 5 +++++ src/hooks/useDefaults.ts | 8 ++++---- src/index.tsx | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/block.json b/src/block.json index 3331293..bf4ef75 100644 --- a/src/block.json +++ b/src/block.json @@ -18,10 +18,10 @@ "fontFamily": { "type": "string" }, "lineHeight": { "type": "string" }, "lineNumbers": { "type": "boolean" }, - "clampFonts": { "type": "boolean", "default": false }, + "clampFonts": { "type": "boolean" }, "headerType": { "type": "string" }, "headerString": { "type": "string" }, - "disablePadding": { "type": "boolean", "default": false }, + "disablePadding": { "type": "boolean" }, "startingLineNumber": { "type": "number", "default": 1 }, "lineNumbersWidth": { "type": "number" }, "frame": { "type": "boolean" }, diff --git a/src/editor/editor.css b/src/editor/editor.css index a4a01c3..377e62c 100644 --- a/src/editor/editor.css +++ b/src/editor/editor.css @@ -50,6 +50,11 @@ position: absolute; left: 18px; } + +.code-block-pro-editor.cbp-has-line-numbers.padding-disabled pre .line:not(.cbp-line-number-disabled)::before { + @apply static; +} + /* Will make sure the line numbers are full width before calculating */ .code-block-pro-editor.cbp-has-line-numbers pre .line.cbp-line-number-width-forced::before { width: auto !important; diff --git a/src/hooks/useDefaults.ts b/src/hooks/useDefaults.ts index 00404eb..5473023 100644 --- a/src/hooks/useDefaults.ts +++ b/src/hooks/useDefaults.ts @@ -32,7 +32,7 @@ export const useDefaults = ({ } = useThemeStore(); useEffect(() => { - if (copyButton || !previousSettings.copyButton) return; + if (copyButton !== undefined || !previousSettings.copyButton) return; setAttributes({ copyButton: previousSettings.copyButton }); }, [previousSettings, copyButton, setAttributes]); @@ -62,17 +62,17 @@ export const useDefaults = ({ }, [previousHeaderType, headerType, setAttributes]); useEffect(() => { - if (clampFonts || !previousClampFonts) return; + if (clampFonts !== undefined || !previousClampFonts) return; setAttributes({ clampFonts: previousClampFonts }); }, [previousClampFonts, clampFonts, setAttributes]); useEffect(() => { - if (disablePadding || !previousDisablePadding) return; + if (disablePadding !== undefined || !previousDisablePadding) return; setAttributes({ disablePadding: previousDisablePadding }); }, [previousDisablePadding, disablePadding, setAttributes]); useEffect(() => { - if (lineNumbers || !previousLineNumbers) return; + if (lineNumbers !== undefined || !previousLineNumbers) return; setAttributes({ lineNumbers: previousLineNumbers }); }, [previousLineNumbers, lineNumbers, setAttributes]); }; diff --git a/src/index.tsx b/src/index.tsx index d1a3f2c..082364f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -33,11 +33,11 @@ registerBlockType(blockConfig.name, { fontSize: { type: 'string' }, fontFamily: { type: 'string' }, lineHeight: { type: 'string' }, - clampFonts: { type: 'boolean', default: false }, + clampFonts: { type: 'boolean' }, lineNumbers: { type: 'boolean' }, headerType: { type: 'string' }, headerString: { type: 'string' }, - disablePadding: { type: 'boolean', default: false }, + disablePadding: { type: 'boolean' }, startingLineNumber: { type: 'string' }, lineNumbersWidth: { type: 'number' }, frame: { type: 'boolean' },