From 0a6a2a2ef7e51797de60691e01a25617998ef92b Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Tue, 19 Nov 2024 21:51:23 -0800 Subject: [PATCH] Chore: Desktop: Migrate from style= to SCSS for visible note pane styling --- .../NoteBody/CodeMirror/utils/useStyles.ts | 23 ---------- .../NoteBody/CodeMirror/v5/CodeMirror.tsx | 42 +++++++------------ .../NoteBody/CodeMirror/v6/CodeMirror.tsx | 40 +++++++----------- .../app-desktop/gui/NoteEditor/style.scss | 1 + .../styles/note-editor-viewer-row.scss | 37 ++++++++++++++++ 5 files changed, 67 insertions(+), 76 deletions(-) create mode 100644 packages/app-desktop/gui/NoteEditor/styles/note-editor-viewer-row.scss diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useStyles.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useStyles.ts index a46a5625b75..f92067071da 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useStyles.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useStyles.ts @@ -23,29 +23,6 @@ const useStyles = (props: NoteBodyEditorProps) => { display: 'flex', flexDirection: 'row', }, - rowEditorViewer: { - position: 'relative', - display: 'flex', - flexDirection: 'row', - flex: 1, - paddingTop: 10, - - // Allow the editor container to shrink (allowing the editor to scroll) - minHeight: 0, - }, - cellEditor: { - position: 'relative', - display: 'flex', - flex: 1, - }, - cellViewer: { - position: 'relative', - display: 'flex', - flex: 1, - borderLeftWidth: 1, - borderLeftColor: theme.dividerColor, - borderLeftStyle: 'solid', - }, viewer: { display: 'flex', overflow: 'hidden', diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/CodeMirror.tsx index e796cbd2df0..8e4f59197af 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/CodeMirror.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { useState, useEffect, useRef, forwardRef, useCallback, useImperativeHandle, useMemo, ForwardedRef, useContext } from 'react'; +import { useState, useEffect, useRef, forwardRef, useCallback, useImperativeHandle, ForwardedRef, useContext } from 'react'; // eslint-disable-next-line no-unused-vars import { EditorCommand, MarkupToHtmlOptions, NoteBodyEditorProps, NoteBodyEditorRef } from '../../../utils/types'; @@ -694,25 +694,6 @@ function CodeMirror(props: NoteBodyEditorProps, ref: ForwardedRef { - const output = { ...styles.cellEditor }; - if (!props.visiblePanes.includes('editor')) { - output.display = 'none'; // Seems to work fine since the refactoring - } - - return output; - }, [styles.cellEditor, props.visiblePanes]); - - const cellViewerStyle = useMemo(() => { - const output = { ...styles.cellViewer }; - if (!props.visiblePanes.includes('viewer')) { - output.display = 'none'; - } else if (!props.visiblePanes.includes('editor')) { - output.borderLeftStyle = 'none'; - } - return output; - }, [styles.cellViewer, props.visiblePanes]); - useEffect(() => { if (!editorRef.current) return; @@ -741,7 +722,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: ForwardedRef +
+
+ {renderEditor()} + {renderViewer()} +
+ ); + const windowId = useContext(WindowIdContext); return (
@@ -788,10 +779,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: ForwardedRef {props.noteToolbar}
-
- {renderEditor()} - {renderViewer()} -
+ {editorViewerRow}
); diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx index 460ce053fe3..15a49345bd0 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx @@ -301,25 +301,6 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef { - const output = { ...styles.cellEditor }; - if (!props.visiblePanes.includes('editor')) { - output.display = 'none'; // Seems to work fine since the refactoring - } - - return output; - }, [styles.cellEditor, props.visiblePanes]); - - const cellViewerStyle = useMemo(() => { - const output = { ...styles.cellViewer }; - if (!props.visiblePanes.includes('viewer')) { - output.display = 'none'; - } else if (!props.visiblePanes.includes('editor')) { - output.borderLeftStyle = 'none'; - } - return output; - }, [styles.cellViewer, props.visiblePanes]); - useRefocusOnVisiblePaneChange({ editorRef, webviewRef, visiblePanes: props.visiblePanes }); useEditorSearchHandler({ @@ -406,7 +387,7 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef { return ( -
+
{ return ( -
+
+ {renderEditor()} + {renderViewer()} +
+ ); + const windowId = useContext(WindowIdContext); return (
@@ -449,10 +440,7 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef {props.noteToolbar}
-
- {renderEditor()} - {renderViewer()} -
+ {editorViewerRow}
); diff --git a/packages/app-desktop/gui/NoteEditor/style.scss b/packages/app-desktop/gui/NoteEditor/style.scss index b5436a4df6f..d11f8850afa 100644 --- a/packages/app-desktop/gui/NoteEditor/style.scss +++ b/packages/app-desktop/gui/NoteEditor/style.scss @@ -4,3 +4,4 @@ @use "./styles/note-title-info-group.scss"; @use "./styles/note-title-wrapper.scss"; @use "./styles/note-editor-wrapper.scss"; +@use "./styles/note-editor-viewer-row.scss"; diff --git a/packages/app-desktop/gui/NoteEditor/styles/note-editor-viewer-row.scss b/packages/app-desktop/gui/NoteEditor/styles/note-editor-viewer-row.scss new file mode 100644 index 00000000000..c9b2645027f --- /dev/null +++ b/packages/app-desktop/gui/NoteEditor/styles/note-editor-viewer-row.scss @@ -0,0 +1,37 @@ + +.note-editor-viewer-row { + position: relative; + display: flex; + flex-direction: row; + flex: 1; + padding-top: 10px; + + // Allow the editor container to shrink (allowing the editor to scroll) + min-height: 0; + + > .editor, > .viewer { + position: relative; + display: flex; + flex: 1; + } + + > .viewer { + border-left-width: 1px; + border-left-color: var(--joplin-divider-color); + border-left-style: solid; + } + + &:not(.-show-viewer) > .viewer { + display: none; + } + + &:not(.-show-editor) { + > .editor { + display: none; + } + + > .viewer { + border-left: none; + } + } +}