Skip to content

Commit

Permalink
Fix editor line number spacing when padding disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBatdorf committed Nov 17, 2022
1 parent 2876fec commit bfef041
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
5 changes: 5 additions & 0 deletions src/editor/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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]);
};
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ registerBlockType<Attributes>(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' },
Expand Down

0 comments on commit bfef041

Please sign in to comment.