Fix size of CodeMirror to available viewport

This commit is contained in:
2025-08-24 17:15:14 -07:00
parent 7475be087e
commit f43d79769c
4 changed files with 45 additions and 17 deletions
+27
View File
@@ -0,0 +1,27 @@
body {
margin: 0;
}
.app {
height: 100vh;
display: flex;
flex-direction: column;
}
.navbar {
height: 2.5lh;
display: flex;
align-items: center;
gap: 1em;
flex-shrink: 0;
background-color: #cde;
}
.editor-component {
flex: 1;
overflow: hidden;
}
.editor-component .cm-editor {
height: 100%;
}
+1
View File
@@ -1,5 +1,6 @@
import { render } from 'solid-js/web'; import { render } from 'solid-js/web';
import App from './components/App'; import App from './components/App';
import './app.css';
const app = document.getElementById('app')!; const app = document.getElementById('app')!;
+8 -1
View File
@@ -6,13 +6,20 @@ function App() {
const [currentFile, setCurrentFile] = createSignal<string | null>(null); const [currentFile, setCurrentFile] = createSignal<string | null>(null);
return ( return (
<div class="app">
<div class="navbar">
<Show when={currentFile() !== null}>
<button onclick={() => setCurrentFile(null)}>Back</button>
</Show>
<div class="title">{currentFile() ?? 'Choose a file'}</div>
</div>
<Show <Show
when={currentFile()} when={currentFile()}
fallback={<Chooser file={currentFile} setFile={setCurrentFile} />} fallback={<Chooser file={currentFile} setFile={setCurrentFile} />}
> >
<button onclick={() => setCurrentFile(null)}>Back</button>
<Editor file={currentFile()!} /> <Editor file={currentFile()!} />
</Show> </Show>
</div>
); );
} }
+1 -8
View File
@@ -46,16 +46,9 @@ function Editor(props: EditorProps) {
}); });
return ( return (
<div>
<p>You are editing {props.file}.</p>
<Show when={syncedDoc()}> <Show when={syncedDoc()}>
<div <div ref={editorDiv} class="editor-component" />
ref={editorDiv}
class="editor-component"
style={{ border: '1px solid black' }}
/>
</Show> </Show>
</div>
); );
} }