Skip to content

Commit d6920a1

Browse files
author
ZouYingjun
committed
Markdown 主题化语法配色、大纲随光标高亮当前标题;README 卖点强化(本地优先/原生轻快/草稿不丢/买断)
1 parent 18c91a9 commit d6920a1

6 files changed

Lines changed: 84 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
# Jotpad · 跨平台记事本
1+
# Jotpad · 跨平台纯文本记事本
22

33
> 文档导航:[设计决策与功能记录](DECISIONS.md) · [路线图](ROADMAP.md) · [发布流程](.agents/skills/jotpad-release/SKILL.md)
44
55
Jotpad 是一款用 **Tauri 2 + React + TypeScript + CodeMirror 6** 构建的跨平台(macOS / Linux / Windows)纯文本记事本。
66

7-
- 左右分栏:左侧文档列表,右侧编辑区
8-
- 多标签页、草稿自动保存与恢复
9-
- 最近打开的文件(文件菜单)
7+
## 为什么选 Jotpad
8+
9+
- **本地优先,不锁数据** —— 文件就是普通 `.txt` / `.md`,存在你自己的磁盘上;随时用任何工具打开、迁移、同步(iCloud / Git 均可)
10+
- **原生轻快** —— Tauri 原生壳而非 Electron,安装包小、启动到可输入体感明显快于 IDE
11+
- **草稿永不丢** —— 未保存内容自动持久化;关掉重开,上次的标签、光标、滚动位置都在
12+
- **一次性买断** —— 无订阅、无账号、无云端
13+
14+
## 功能一览
15+
16+
- 左右分栏:左侧文档列表(可固定常用文件置顶),右侧编辑区
17+
- 多标签页、命名会话、启动恢复
18+
- **跨文件全文搜索**(`Cmd/Ctrl+Shift+H`):在打开标签 + 最近文件 + 默认保存目录中按内容检索,命中分组高亮、一键跳转
19+
- **快速打开**(`Cmd/Ctrl+P`):文件名模糊搜索,含从未打开过的保存目录文件
20+
- **文档大纲**(`Cmd/Ctrl+Shift+O`):Markdown 标题树过滤与跳转
1021
- 多编码读写(UTF-8 / UTF-16 / GBK / Big5 / Shift-JIS / EUC-KR / Windows-1252,自动检测 + BOM)
11-
- 外部文件变更检测(提示重新加载或保留)
12-
- 查找 / 替换(区分大小写、正则、匹配计数)
13-
- 字体 / 字号、缩放、自动换行、可选行号、强调色
14-
- 浅色 / 深色 / 跟随系统主题
15-
- 原生系统菜单(各平台 `muda` / `AppHandle::set_menu`)
16-
- 中文 / English 界面
17-
- 完整快捷键、拖拽打开文件、打印与页面设置
18-
- 可选系统集成:右键「新建文本文件」、使用 Jotpad 打开文本文件
22+
- 外部文件变更检测(提示重新加载或保留);与磁盘版本对比 diff
23+
- 查找 / 替换(区分大小写、正则、匹配计数);中文双击按词选中(分词感知)
24+
- 大文件自动只读(>2MB);手动只读模式(锁图标/状态栏/工具栏)
25+
- 字体 / 字号、缩放、自动换行、可选行号、拼写检查、强调色
26+
- 浅色 / 深色 / 跟随系统主题;中文 / English 界面
27+
- 完整快捷键、拖拽打开、打印与页面设置、本地历史快照
28+
- 系统托盘 + 全局唤起(`Cmd/Ctrl+Shift+J`);可选右键「新建文本文件」/「用 Jotpad 打开」
29+
- **实验特性**:Markdown 语法高亮 + 分栏实时预览(设置中开启,默认关)
1930

2031
## 开发
2132

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@codemirror/search": "^6.5.11",
2222
"@codemirror/state": "^6.5.2",
2323
"@codemirror/view": "^6.36.4",
24+
"@lezer/highlight": "^1.2.3",
2425
"@tauri-apps/api": "^2.2.0",
2526
"@tauri-apps/plugin-dialog": "^2.2.0",
2627
"@tauri-apps/plugin-opener": "^2.2.6",

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/components/Editor.tsx‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
1414
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
1515
import { languages } from "@codemirror/language-data";
16+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
17+
import { tags as t } from "@lezer/highlight";
1618
import { findNext, findPrevious, search, selectSelectionMatches } from "@codemirror/search";
1719
import { useStore } from "@/store/useStore";
1820
import { emitEditorInfo, setEditorView, viewInfo } from "@/lib/editorRef";
@@ -41,6 +43,27 @@ function markdownLang(): ReturnType<typeof markdown> {
4143
});
4244
}
4345

46+
/** Markdown 语法配色:跟随主题变量,标题加重、标记淡化、代码块/链接着色。 */
47+
const mdHighlight = HighlightStyle.define([
48+
{ tag: t.heading, fontWeight: "700", color: "var(--md-heading, var(--text))" },
49+
{ tag: t.heading1, fontSize: "1.35em" },
50+
{ tag: t.heading2, fontSize: "1.22em" },
51+
{ tag: t.heading3, fontSize: "1.1em" },
52+
{ tag: t.strong, fontWeight: "700" },
53+
{ tag: t.emphasis, fontStyle: "italic" },
54+
{ tag: t.strikethrough, textDecoration: "line-through" },
55+
{ tag: t.link, color: "var(--accent)", textDecoration: "underline" },
56+
{ tag: t.url, color: "var(--accent)", textDecoration: "underline" },
57+
{ tag: [t.monospace], color: "var(--md-code, var(--accent))" },
58+
{ tag: [t.quote], color: "var(--text-secondary)", fontStyle: "italic" },
59+
{ tag: t.list, color: "var(--accent)" },
60+
{ tag: [t.meta, t.processingInstruction], color: "var(--text-secondary)" },
61+
{ tag: t.contentSeparator, color: "var(--text-secondary)" },
62+
{ tag: [t.keyword, t.atom, t.bool, t.number], color: "var(--md-code, var(--accent))" },
63+
{ tag: t.string, color: "var(--md-str, #a66b2f)" },
64+
{ tag: t.comment, color: "var(--text-secondary)", fontStyle: "italic" },
65+
]);
66+
4467
/** 光标选区包裹 Markdown 标记(粗体/斜体/行内代码)。返回 true 表示已处理。 */
4568
function wrapSelection(view: import("@codemirror/view").EditorView, mark: string): boolean {
4669
const sel = view.state.selection.main;
@@ -93,7 +116,7 @@ export function Editor() {
93116
),
94117
langCompartment.current.of(
95118
markdownEnabled(store.settings, store.activeTab()?.filePath ?? null)
96-
? markdownLang()
119+
? [markdownLang(), syntaxHighlighting(mdHighlight)]
97120
: [],
98121
),
99122
wrapCompartment.current.of(
@@ -229,7 +252,9 @@ export function Editor() {
229252
useEffect(() => {
230253
viewRef.current?.dispatch({
231254
effects: langCompartment.current.reconfigure(
232-
markdownEnabled(settings, tab?.filePath ?? null) ? markdownLang() : [],
255+
markdownEnabled(settings, tab?.filePath ?? null)
256+
? [markdownLang(), syntaxHighlighting(mdHighlight)]
257+
: [],
233258
),
234259
});
235260
}, [settings.experimental, tab?.filePath, settings]);

‎src/components/Outline.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ export function Outline() {
4141
el?.scrollIntoView({ block: "nearest" });
4242
}, [index, filtered.length]);
4343

44+
// 打开时高亮当前光标所在的标题(跟随编辑器滚动位置)
45+
useEffect(() => {
46+
if (!open) return;
47+
const view = getEditorView();
48+
if (!view) return;
49+
const pos = view.state.selection.main.head;
50+
// 从后往前找第一个 from <= pos 的标题
51+
let hit = -1;
52+
for (let i = items.length - 1; i >= 0; i--) {
53+
if (items[i]!.from <= pos) {
54+
hit = i;
55+
break;
56+
}
57+
}
58+
if (hit >= 0 && !query.trim()) setIndex(hit);
59+
// eslint-disable-next-line react-hooks/exhaustive-deps
60+
}, [open, activeTabId, items]);
61+
4462
if (!open) return null;
4563

4664
const close = () => {

‎src/styles/app.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,18 @@ textarea {
984984
width: min(520px, calc(100vw - 32px));
985985
}
986986

987+
/* Markdown 预览(实验)变量 */
988+
[data-theme="light"] {
989+
--md-heading: #1f4e79;
990+
--md-code: #99307b;
991+
--md-str: #a66b2f;
992+
}
993+
[data-theme="dark"] {
994+
--md-heading: #7cc0ff;
995+
--md-code: #f29bc8;
996+
--md-str: #e0b07c;
997+
}
998+
987999
/* ---------- Markdown preview (experimental) ---------- */
9881000
.editor-wrap-host > .editor-wrap {
9891001
flex: 1;

0 commit comments

Comments
 (0)