Compare commits
3 Commits
1aa2c3b9bf
...
003815239d
| Author | SHA1 | Date | |
|---|---|---|---|
| 003815239d | |||
| d885ca1317 | |||
| 74fa5a52ab |
11
changelog.md
11
changelog.md
@@ -17,6 +17,8 @@ All notable changes to this project will be documented in this file.
|
|||||||
- **Multi-select delete**: Double-click to enter selection mode, click to toggle selection, batch delete support
|
- **Multi-select delete**: Double-click to enter selection mode, click to toggle selection, batch delete support
|
||||||
- **Title truncation**: Long titles in the list display with ellipsis
|
- **Title truncation**: Long titles in the list display with ellipsis
|
||||||
- **Time display**: Format "time · month/day/year", e.g., "12:45 · 4/11/2026"
|
- **Time display**: Format "time · month/day/year", e.g., "12:45 · 4/11/2026"
|
||||||
|
- **Copy**: In edit mode, use Shift+Arrow to select text, then Ctrl+C to copy
|
||||||
|
- **Exit**: Press Ctrl+D to exit
|
||||||
|
|
||||||
### Technical
|
### Technical
|
||||||
|
|
||||||
@@ -33,4 +35,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
```bash
|
```bash
|
||||||
npm run dev # Development mode
|
npm run dev # Development mode
|
||||||
npm run build # Build to mio.exe
|
npm run build # Build to mio.exe
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Keyboard Shortcuts
|
||||||
|
|
||||||
|
- `Shift+Arrow` - Select text in edit mode
|
||||||
|
- `Ctrl+C` - Copy selected text (in edit mode)
|
||||||
|
- `Ctrl+D` - Exit application
|
||||||
|
- `Esc` - Exit application (alternative)
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
|
import type { TextareaRenderable } from "@opentui/core";
|
||||||
import { db, type Note } from "../db";
|
import { db, type Note } from "../db";
|
||||||
|
|
||||||
interface NoteEditorProps {
|
interface NoteEditorProps {
|
||||||
note: Note | null;
|
note: Note | null;
|
||||||
onUpdate: () => void;
|
onUpdate: () => void;
|
||||||
onDelete: (id: number) => void;
|
onDelete: (id: number) => void;
|
||||||
|
onCopySelected: () => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMarkdown(content: string): any {
|
function renderMarkdown(content: string): any {
|
||||||
@@ -58,11 +60,11 @@ function renderMarkdown(content: string): any {
|
|||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NoteEditor({ note, onUpdate, onDelete }: NoteEditorProps) {
|
export function NoteEditor({ note, onUpdate, onDelete, onCopySelected }: NoteEditorProps) {
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [content, setContent] = useState("");
|
const [content, setContent] = useState("");
|
||||||
const textareaRef = useRef<{ plainText: string } | null>(null);
|
const textareaRef = useRef<TextareaRenderable | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (note) {
|
if (note) {
|
||||||
@@ -75,6 +77,14 @@ export function NoteEditor({ note, onUpdate, onDelete }: NoteEditorProps) {
|
|||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
}, [note?.id]);
|
}, [note?.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onCopySelected) {
|
||||||
|
(window as any).__getSelectedText = () => {
|
||||||
|
return textareaRef.current?.getSelectedText() ?? "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [onCopySelected]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (note) {
|
if (note) {
|
||||||
const finalContent = textareaRef.current?.plainText ?? content;
|
const finalContent = textareaRef.current?.plainText ?? content;
|
||||||
@@ -85,6 +95,10 @@ export function NoteEditor({ note, onUpdate, onDelete }: NoteEditorProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSelectedText = (): string => {
|
||||||
|
return textareaRef.current?.getSelectedText() ?? "";
|
||||||
|
};
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return (
|
return (
|
||||||
<box flexGrow={1} justifyContent="center" alignItems="center">
|
<box flexGrow={1} justifyContent="center" alignItems="center">
|
||||||
|
|||||||
@@ -77,10 +77,20 @@ function App() {
|
|||||||
|
|
||||||
const selectedNote = selectedId ? notes.find((n) => n.id === selectedId) : null;
|
const selectedNote = selectedId ? notes.find((n) => n.id === selectedId) : null;
|
||||||
|
|
||||||
|
const handleCopySelected = (): string => {
|
||||||
|
return (window as any).__getSelectedText?.() ?? "";
|
||||||
|
};
|
||||||
|
|
||||||
useKeyboard((key) => {
|
useKeyboard((key) => {
|
||||||
if (key.name === "escape") {
|
if (key.ctrl && key.name === "d") {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
if (key.ctrl && key.name === "c") {
|
||||||
|
const text = handleCopySelected();
|
||||||
|
if (text) {
|
||||||
|
process.stdout.write('\x1b]52;c;' + btoa(text) + '\x07');
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -98,11 +108,11 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
</box>
|
</box>
|
||||||
<box flexGrow={1}>
|
<box flexGrow={1}>
|
||||||
<NoteEditor note={selectedNote || null} onUpdate={handleUpdate} onDelete={handleDelete} />
|
<NoteEditor note={selectedNote || null} onUpdate={handleUpdate} onDelete={handleDelete} onCopySelected={handleCopySelected} />
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderer = await createCliRenderer();
|
const renderer = await createCliRenderer({ exitOnCtrlC: false });
|
||||||
createRoot(renderer).render(<App />);
|
createRoot(renderer).render(<App />);
|
||||||
Reference in New Issue
Block a user