Skip to content

Commit dde933f

Browse files
committed
タブキー有効可
1 parent 1a6c120 commit dde933f

6 files changed

Lines changed: 75 additions & 23 deletions

File tree

docs/logo.png

60.7 KB
Loading

src/App.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import UploadMarkdown from "./uploadMarkdown";
1313
import UploadImage from "./uploadImage";
1414

1515
type positionInfo = null | { top: number; left: number };
16+
type TabAreaArgs = {
17+
e: React.KeyboardEvent<HTMLTextAreaElement>;
18+
ref: React.MutableRefObject<HTMLTextAreaElement | null>;
19+
};
1620

1721
export default function App() {
1822
const [markdown, setMarkdown] = useState("");
@@ -30,6 +34,26 @@ export default function App() {
3034
const inputRef = useRef<HTMLTextAreaElement | null>(null);
3135
const previewRef = useRef<HTMLDivElement | null>(null);
3236

37+
const handleTabArea = ({ e, ref }: TabAreaArgs) => {
38+
if (e.key !== "Tab") return; // Tabキー以外は処理しない
39+
40+
e.preventDefault(); // デフォルトのタブ挿入動作を止める
41+
42+
if (!ref.current) return;
43+
44+
const textarea = ref.current;
45+
const cursorPosition = textarea.selectionStart;
46+
const cursorLeft = textarea.value.substring(0, cursorPosition);
47+
const cursorRight = textarea.value.substring(cursorPosition);
48+
49+
// タブの代わりに半角スペース3つを挿入
50+
const tabSpaces = " ";
51+
textarea.value = cursorLeft + tabSpaces + cursorRight;
52+
53+
// カーソルを3文字分進める
54+
textarea.selectionStart = textarea.selectionEnd = cursorPosition + 3;
55+
};
56+
3357
// 2/3追加・テンプレート部分
3458

3559
const [buttonName, setButtonName] = useState<string[]>([
@@ -273,6 +297,7 @@ export default function App() {
273297
onScroll={() => handleScrollSync(textAreaRef, previewRef)}
274298
onChange={(event) => setMarkdown(event.target.value)}
275299
placeholder="編集画面"
300+
onKeyDown={(e) => handleTabArea({ e, ref: textAreaRef })} // ここ
276301
onFocus={() => setIsTextAreaFocused(true)}
277302
onBlur={() => setIsTextAreaFocused(false)}
278303
/>
@@ -287,6 +312,7 @@ export default function App() {
287312
value={inputValue}
288313
ref={inputRef}
289314
onChange={handleInputChange}
315+
onKeyDown={(e) => handleTabArea({ e, ref: inputRef })} // ここ
290316
style={{
291317
position: "absolute",
292318
top: `${inputPosition.top}px`,

src/Home.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
function Home() {
22
return (
3-
<div>
4-
<h1>Mathdownへようこそ</h1>
5-
<ul>
6-
<li>
7-
<a href="/App">アプリを開く</a>
8-
</li>
9-
<li>
10-
<a href="/UserGuide/1">使い方</a>
11-
</li>
12-
</ul>
13-
</div>
3+
<>
4+
<div className="App">
5+
<a href="/home">
6+
<img src="../docs/logo.png" width="12.5%" height="12.5%" />
7+
</a>
8+
</div>
9+
<div>
10+
<h1>Mathdownへようこそ</h1>
11+
<ul>
12+
<li>
13+
<a href="/App">アプリを開く</a>
14+
</li>
15+
<li>
16+
<a href="/UserGuide/1">使い方</a>
17+
</li>
18+
</ul>
19+
</div>
20+
</>
1421
);
1522
}
1623

src/UserGuide/UserGuide.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
function UserGuide() {
22
return (
3-
<div>
4-
<h1>使い方</h1>
5-
<p>
6-
<a href="/UserGuide/1">{"<"}</a>1/2<a href="/UserGuide/2">{">"}</a>
7-
</p>
8-
</div>
3+
<>
4+
<div className="App">
5+
<a href="/home">
6+
<img src="../docs/logo.png" width="12.5%" height="12.5%" />
7+
</a>
8+
</div>
9+
<div>
10+
<h1>使い方</h1>
11+
<p>
12+
<a href="/UserGuide/1">{"<"}</a>1/2<a href="/UserGuide/2">{">"}</a>
13+
</p>
14+
</div>
15+
</>
916
);
1017
}
1118

src/UserGuide/UserGuide_2.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
function UserGuide_2() {
22
return (
3-
<div>
4-
<h1>使い方</h1>
5-
<p>
6-
<a href="/UserGuide/1">{"<"}</a>2/2<a href="/UserGuide/1">{">"}</a>
7-
</p>
8-
</div>
3+
<>
4+
<div className="App">
5+
<a href="/home">
6+
<img src="../docs/logo.png" width="12.5%" height="12.5%" />
7+
</a>
8+
</div>
9+
<div>
10+
<h1>使い方</h1>
11+
<p>
12+
<a href="/UserGuide/1">{"<"}</a>2/2<a href="/UserGuide/1">{">"}</a>
13+
</p>
14+
</div>
15+
</>
916
);
1017
}
1118

src/extractPDF.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export function ExtractPDF({
111111

112112
return (
113113
<>
114+
<div className="App">
115+
<a href="/home">
116+
<img src="../docs/logo.png" width="12.5%" height="12.5%" />
117+
</a>
118+
</div>
114119
<h2>PDFの解説表示</h2>
115120
<div className="flex">
116121
<div className="explanation">

0 commit comments

Comments
 (0)