Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions TeXmacs/progs/texmacs/texmacs/tm-files.scm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@
(with t (tree->stree (get-style-tree))
(and (pair? t) (== (car t) 'tuple) (null? (cdr t)))))

(tm-define (sync-buffer-dark-style-with-gui-theme . opt-buf)
(with buf (if (null? opt-buf) (current-buffer) (car opt-buf))
(with-buffer buf
(if (== (get-preference "gui theme") "liii-night")
(when (not (has-style-package? "dark"))
(add-style-package "dark"))
(when (has-style-package? "dark")
(remove-style-package "dark"))))))

(tm-define (buffer-set-default-style)
(init-style "generic")
(with lan (get-preference "language")
Expand All @@ -120,9 +129,7 @@
(init-env "prog-scripts" (get-preference "scripting language")))
(add-style-package "number-europe")
(add-style-package "preview-ref")
(when (== (get-preference "gui theme") "liii-night")
(when (not (has-style-package? "dark"))
(add-style-package "dark")))
(sync-buffer-dark-style-with-gui-theme (current-buffer))
(buffer-pretend-saved (current-buffer)))

(tm-define (propose-name-buffer)
Expand Down Expand Up @@ -583,11 +590,15 @@
(let* ((path (url->system name))
(vname `(verbatim ,(utf8->cork path))))
(cond ((buffer-exists? name)
(load-buffer-open name opts))
(begin
(load-buffer-open name opts)
(sync-buffer-dark-style-with-gui-theme name)))
((url-exists? name)
(if (buffer-load name)
(set-message `(concat "Could not load " ,vname) "Load file")
(load-buffer-open name opts)))
(begin
(load-buffer-open name opts)
(sync-buffer-dark-style-with-gui-theme name))))
(else
(with msg "The file or buffer does not exist:"
(begin
Expand Down
38 changes: 38 additions & 0 deletions devel/204_30.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[204_30] 文档主题跟随软件主题,保存时不保留dark

## 如何测试

测试项一:界面主题从浅色切换为深色
1. 在浅色主题下打开任意 tmu 文件A,文档为浅色背景
2. 切换主题为深色,自动重启
3. 深色主题打开后,文件A没有自动变成深色背景,必须要重新打开 tmu 文件A,文档才应该变为深色背景

测试项二:界面主题从深色切换为浅色
1. 在深色主题下打开任意 tmu 文件B,文档为深色背景
2. 切换主题为浅色,自动重启
3. 浅色主题打开后,tmu 文件B应该自动变为浅色背景

测试项三:已经打开的文档重复打开,可以跟随主题颜色变化
1. 在深色背景下打开任意 tmu 文件C,文档为深色背景
2. 将文档切换为浅色背景,切换入口位于焦点工具栏的 “主题” 按钮
3. 通过 “最近打开” 功能,再次点击当前文档,即重复打开当前文档,文档应该从浅色变为深色

测试项四:保存到磁盘的文档不应携带 dark 的 style
1. 进入软件的深色主题
2. 在深色主题下,打开任意 tmu 文档,文档背景色应为深色
3. 触发一次保存
4. 使用 vscode 或其他纯文本编辑器,打开刚刚保存的 tmu 文档,查看 tmu 头部的 style 块,不应该携带 dark 字样

## 2026/03/31 文档主题跟随软件主题,保存时不保留dark

### What
让所有文档的背景色跟随软件主题变化,保持视觉上的一致性。
在保存文档时过滤掉 style 的影响,所有文档都应以浅色背景被保存。

### Why
目前文档主题依赖于文档本身的 style,即便在深色主题下,以浅色创建的文档不会跟随主题显示为深色

### How
TeXmacs/progs/texmacs/texmacs/tm-files.scm :108 添加 sync-buffer-dark-style-with-gui-theme 函数,根据当前主题颜色调整文档的背景色
TeXmacs/progs/texmacs/texmacs/tm-files.scm :588 load-buffer-load 函数,应用 sync-buffer-dark-style-with-gui-theme 函数

23 changes: 20 additions & 3 deletions src/Texmacs/Data/new_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,24 @@ bool
buffer_export (url name, url dest, string fm) {
tm_view vw= concrete_view (get_recent_view (name));
ASSERT (vw != NULL, "view expected");
new_data export_data;

vw->ed->get_data (vw->buf->data);
export_data->project= copy (vw->buf->data->project);
export_data->style = copy (vw->buf->data->style);
export_data->init = copy (vw->buf->data->init);
export_data->fin = copy (vw->buf->data->fin);
export_data->ref = copy (vw->buf->data->ref);
export_data->aux = copy (vw->buf->data->aux);
export_data->att = copy (vw->buf->data->att);

if (export_data->style == "dark") export_data->style= tree (TUPLE);
else if (is_func (export_data->style, TUPLE)) {
tree style (TUPLE);
for (int i= 0; i < N (export_data->style); ++i)
if (export_data->style[i] != "dark") style << export_data->style[i];
export_data->style= style;
}

if (fm == "postscript" || fm == "pdf") {
int old_stamp= last_modified (dest);
Expand All @@ -581,8 +599,7 @@ buffer_export (url name, url dest, string fm) {
// if (fm == "latex")
// body= vw->ed->exec_latex (body);

vw->ed->get_data (vw->buf->data);
tree doc= attach_data (body, vw->buf->data, !vw->ed->get_save_aux ());
tree doc= attach_data (body, export_data, !vw->ed->get_save_aux ());

if (fm == "latex")
doc= change_doc_attr (doc, "view", as_string (abstract_view (vw)));
Expand Down Expand Up @@ -680,4 +697,4 @@ move_buffer_via_index (int from, int to) {
swap (bufs[i], bufs[i - 1]);
}
}
}
}
Loading