Skip to content

Commit

Permalink
Fix heights/sizing on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJKL committed Aug 3, 2023
1 parent 634397c commit 5eaab2b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
19 changes: 10 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<link href="/dist/index.css"
rel="stylesheet">
<title>Prompt Crafter</title>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<link href="/dist/index.css"
rel="stylesheet">
<title>Prompt Crafter</title>
</head>

<body>
<div id="root"></div>
<script type="module"
src="/src/main.tsx"></script>
<div id="root"
class="contents"></div>
<script type="module"
src="/src/main.tsx"></script>
</body>

</html>
23 changes: 16 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AppBar, CssBaseline, Paper, Toolbar, Typography } from '@mui/material';
import { Editor } from './components/Editor';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useMonaco } from '@monaco-editor/react';
import { conf, language } from './common/sdprompt_monaco';
import monaco from 'monaco-editor';
function App() {
const [promptText, setPromptText] = useState(
localStorage.getItem('pc.active_prompt') ?? '',
Expand All @@ -22,6 +23,12 @@ function App() {
localStorage.setItem('pc.active_prompt', promptText);
}, [promptText]);

const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);

function handleEditorDidMount(editor: monaco.editor.IStandaloneCodeEditor) {
editorRef.current = editor;
}

function handleEditorTextChange(value: string | undefined) {
if (value) {
setPromptText(value);
Expand All @@ -31,11 +38,13 @@ function App() {
return prompt.split(/\s*,\s*/);
}

editorRef.current?.layout();

return (
<>
<CssBaseline />
<div className="grid grid-cols-1 grid-rows-[auto_1fr]">
<AppBar classes="grid">
<div className="h-full grid grid-cols-1 grid-rows-[auto_minmax(0,_1fr)]">
<AppBar>
<Toolbar className="flex flex-auto justify-between">
<Typography
className="flex-auto select-none"
Expand All @@ -55,15 +64,15 @@ function App() {
<main className="grid grid-cols-2 grid-rows-1 p-4 gap-4">
<Paper elevation={16}>
<Editor
options={{ padding: { top: 1 }, automaticLayout: true }}
onMount={handleEditorDidMount}
defaultValue={promptText}
onChange={handleEditorTextChange}
/>
</Paper>
<Paper elevation={16}>
<div className="whitespace-pre-wrap p-4">
{splitOnCommas(promptText).map((segment) => (
<div>{segment}</div>
<div className="overflow-y-auto h-full whitespace-pre-wrap p-4">
{splitOnCommas(promptText).map((segment, idx) => (
<div key={`segment-${idx}`}>{segment}</div>
))}
</div>
</Paper>
Expand Down
11 changes: 8 additions & 3 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import MonacoEditor, { EditorProps } from '@monaco-editor/react';
import MonacoEditor, { EditorProps, useMonaco } from '@monaco-editor/react';
import _ from 'lodash';

const DEFAULT_OPTIONS: EditorProps = {
theme: 'vs-dark',
options: { minimap: { enabled: false }, wordWrap: 'wordWrapColumn' },
options: {
padding: { top: 16 },
minimap: { enabled: false },
automaticLayout: true,
scrollBeyondLastLine: false,
wordWrap: 'wordWrapColumn',
},
language: 'sdprompt',
};

export function Editor(props: EditorProps = {}) {
const withDefaults = _.merge({}, DEFAULT_OPTIONS, props);

return (
<>
<MonacoEditor {...withDefaults}></MonacoEditor>
Expand Down
2 changes: 0 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ body {
}

#root {
display: grid;
grid-template: 1fr / 1fr;
height: 100%;
min-height: 100%;
}
Expand Down

0 comments on commit 5eaab2b

Please sign in to comment.