Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit defaults #242

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ Themes are rendered inside the editor as you type or make changes, so the code b

= 1.24.0 - 2023-09-02 =
- Feature: Added Zig, mdc, Mojo, shellsession (console output), and splunk grammars
- Tweak: Combine code aliases
- Tweak: Combined confusing code aliases
- Fix: Fixed a bug where a setting would affect every block on the same page

= 1.23.0 - 2023-08-13 =
- Feature: Added Imba syntax
Expand Down
41 changes: 13 additions & 28 deletions src/hooks/useDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,112 +56,97 @@ export const useDefaults = ({

useEffect(() => {
if (once.current) return;
if (copyButtonType || !previousCopyButtonType) return;
if (copyButtonType) return;
setAttributes({ copyButtonType: previousCopyButtonType });
}, [previousCopyButtonType, copyButtonType, setAttributes]);

useEffect(() => {
if (once.current) return;
if (theme || !previousTheme) return;
if (theme) return;
setAttributes({ theme: previousTheme as Theme });
}, [previousTheme, theme, setAttributes]);

useEffect(() => {
if (once.current) return;
if (fontSize || !previousFontSize) return;
if (fontSize) return;
setAttributes({ fontSize: previousFontSize });
}, [previousFontSize, fontSize, setAttributes]);

useEffect(() => {
if (once.current) return;
if (fontFamily || fontFamily === '' || previousFontFamily === undefined)
return;
if (fontFamily || fontFamily === '') return;
setAttributes({ fontFamily: previousFontFamily });
}, [previousFontFamily, fontFamily, setAttributes]);

useEffect(() => {
if (once.current) return;
if (lineHeight || !previousLineHeight) return;
if (lineHeight) return;
setAttributes({ lineHeight: previousLineHeight });
}, [previousLineHeight, lineHeight, setAttributes]);

useEffect(() => {
if (once.current) return;
if (headerType || !previousHeaderType) return;
if (headerType) return;
setAttributes({ headerType: previousHeaderType });
}, [previousHeaderType, headerType, setAttributes]);

useEffect(() => {
if (once.current) return;
if (footerType !== undefined || previousFooterType === undefined)
return;
if (footerType !== undefined) return;
setAttributes({ footerType: previousFooterType });
}, [previousFooterType, footerType, setAttributes]);

useEffect(() => {
if (once.current) return;
if (clampFonts !== undefined || previousClampFonts === undefined)
return;
if (clampFonts !== undefined) return;
setAttributes({ clampFonts: previousClampFonts });
}, [previousClampFonts, clampFonts, setAttributes]);

useEffect(() => {
if (once.current) return;
if (
disablePadding !== undefined ||
previousDisablePadding === undefined
)
return;
if (disablePadding !== undefined) return;
setAttributes({ disablePadding: previousDisablePadding });
}, [previousDisablePadding, disablePadding, setAttributes]);

useEffect(() => {
if (once.current) return;
if (lineNumbers !== undefined || previousLineNumbers === undefined)
return;
if (lineNumbers !== undefined) return;
setAttributes({ lineNumbers: previousLineNumbers });
}, [previousLineNumbers, lineNumbers, setAttributes]);

useEffect(() => {
if (once.current) return;
if (tabSize !== undefined || previousTabSize === undefined) return;
if (tabSize !== undefined) return;
setAttributes({ tabSize: previousTabSize });
}, [previousTabSize, tabSize, setAttributes]);

useEffect(() => {
if (once.current) return;
if (useTabs !== undefined || previousUseTabs === undefined) return;
if (useTabs !== undefined) return;
setAttributes({ useTabs: previousUseTabs });
}, [previousUseTabs, useTabs, setAttributes]);

useEffect(() => {
if (once.current) return;
if (seeMoreType !== undefined) return;
if (previousSeeMoreType === undefined) return;
setAttributes({ seeMoreType: previousSeeMoreType });
}, [previousSeeMoreType, seeMoreType, setAttributes]);

useEffect(() => {
if (once.current) return;
if (seeMoreString !== undefined) return;
if (previousSeeMoreString === undefined) return;
setAttributes({ seeMoreString: previousSeeMoreString });
}, [previousSeeMoreString, seeMoreString, setAttributes]);

useEffect(() => {
if (once.current) return;
if (seeMoreTransition !== undefined) return;
if (previousSeeMoreTransition === undefined) return;
setAttributes({ seeMoreTransition: previousSeeMoreTransition });
}, [previousSeeMoreTransition, seeMoreTransition, setAttributes]);

useEffect(() => {
if (once.current) return;
if (
highlightingHover !== undefined ||
previousHighlightingHover === undefined
)
return;
if (highlightingHover !== undefined) return;
setAttributes({ highlightingHover: previousHighlightingHover });
}, [previousHighlightingHover, highlightingHover, setAttributes]);

Expand Down
18 changes: 9 additions & 9 deletions src/state/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ const defaultSettings = {
previousFontFamily: 'Code-Pro-JetBrains-Mono',
previousFontSize: '.875rem',
previousHeaderType: 'headlights',
previousFooterType: undefined,
previousClampFonts: undefined,
previousDisablePadding: undefined,
previousLineNumbers: undefined,
previousHighlightingHover: undefined,
previousFooterType: 'none',
previousClampFonts: false,
previousDisablePadding: false,
previousLineNumbers: false,
previousHighlightingHover: false,
previousCopyButton: true,
previousCopyButtonType: 'heroicons',
previousTabSize: 2,
previousUseTabs: undefined,
previousUseTabs: false,
// TODO: maybe impliment these with an extra UI to make them optional
// previousEnableMaxHeight: undefined,
// previousSeeMoreAfterLine: undefined,
previousSeeMoreType: undefined,
previousSeeMoreString: undefined,
previousSeeMoreTransition: undefined,
previousSeeMoreType: '',
previousSeeMoreString: '',
previousSeeMoreTransition: false,
};
const storage = {
getItem: async (name: string) => {
Expand Down