Skip to content

Commit 37cc17b

Browse files
committed
エディターのサイズを修正、ブラウザーの1remにあわせる
1 parent 2406184 commit 37cc17b

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

app/terminal/editor.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const AceEditor = dynamic(
2222
},
2323
{ ssr: false }
2424
);
25-
import { useEffect } from "react";
25+
import { useEffect, useState } from "react";
2626
import clsx from "clsx";
2727
import { useChangeTheme } from "../[docs_id]/themeToggle";
2828
import { useEmbedContext } from "./embedContext";
@@ -88,6 +88,13 @@ export function EditorComponent(props: EditorProps) {
8888
}
8989
}, [files, props.filename, props.initContent, writeFile]);
9090

91+
const [fontSize, setFontSize] = useState(16);
92+
useEffect(() => {
93+
setFontSize(
94+
parseFloat(getComputedStyle(document.documentElement).fontSize)
95+
); // 1rem
96+
}, []);
97+
9198
return (
9299
<div className="border border-accent border-2 shadow-md m-2 rounded-box overflow-hidden">
93100
<div className="flex flex-row items-center">
@@ -133,11 +140,12 @@ export function EditorComponent(props: EditorProps) {
133140
tabSize={langConstants(props.language || "text").tabSize}
134141
width="100%"
135142
height={
136-
Math.max((props.initContent.split("\n").length + 2) * 14, 128) + "px"
143+
Math.max((props.initContent.split("\n").length + 2) * fontSize, 128) +
144+
"px"
137145
}
138146
className="font-mono!" // Aceのデフォルトフォントを上書き
139147
readOnly={props.readonly}
140-
fontSize={16}
148+
fontSize={fontSize}
141149
enableBasicAutocompletion={true}
142150
enableLiveAutocompletion={true}
143151
enableSnippets={false}

app/terminal/terminal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ export function useTerminal(props: TerminalProps) {
8888
convertEol: true,
8989
cursorStyle: "bar",
9090
cursorInactiveStyle: "none",
91-
fontSize: 16,
91+
fontSize: parseFloat(
92+
getComputedStyle(document.documentElement).fontSize
93+
), // 1rem
9294
lineHeight: 1.2,
9395
letterSpacing: 0,
9496
fontFamily: "'Inconsolata Variable','Noto Sans JP Variable'",

0 commit comments

Comments
 (0)