Skip to content

Commit

Permalink
Merge pull request #62 from KevinBatdorf/fix-line-number-spacing-on-e…
Browse files Browse the repository at this point in the history
…ditor

Fix editor line number spacing when padding disabled
  • Loading branch information
KevinBatdorf committed Nov 17, 2022
2 parents 8586b5b + 10e2dcc commit a72ccbd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
"fontFamily": { "type": "string" },
"lineHeight": { "type": "string" },
"lineNumbers": { "type": "boolean" },
"clampFonts": { "type": "boolean", "default": false },
"clampFonts": { "type": "boolean" },
"headerType": { "type": "string" },
"footerType": { "type": "string" },
"headerString": { "type": "string" },
"disablePadding": { "type": "boolean" },
"footerString": { "type": "string" },
"footerLink": { "type": "string" },
"footerLinkTarget": { "type": "boolean" },
"disablePadding": { "type": "boolean", "default": false },
"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 @@ -34,7 +34,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 @@ -69,17 +69,17 @@ export const useDefaults = ({
}, [previousFooterType, footerType, 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]);
};
5 changes: 2 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createBlock, registerBlockType } from '@wordpress/blocks';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import { colord, AnyColor } from 'colord';
import { Lang } from 'shiki';
import blockConfig from './block.json';
import { Edit } from './editor/Edit';
Expand Down Expand Up @@ -34,15 +33,15 @@ 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' },
footerType: { type: 'string' },
footerString: { type: 'string' },
footerLink: { type: 'string' },
footerLinkTarget: { type: 'boolean' },
disablePadding: { type: 'boolean', default: false },
startingLineNumber: { type: 'string' },
lineNumbersWidth: { type: 'number' },
frame: { type: 'boolean' },
Expand Down

0 comments on commit a72ccbd

Please sign in to comment.