From d5a16123296cfc0eab7398891e16fe436bb04bc8 Mon Sep 17 00:00:00 2001 From: tamakyi Date: Wed, 9 Sep 2026 20:14:20 +0800 Subject: [PATCH] =?UTF-8?q?git-sync-web=20=E8=87=AA=E5=8A=A8=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=202026-09-09=2020:14:20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/app.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/static/app.js b/static/app.js index d96f864..84909a4 100644 --- a/static/app.js +++ b/static/app.js @@ -871,6 +871,17 @@ async function loadFile(name, path) { } } +async function commitCurrentFile() { + const name = current; + const path = fileCurrent; + if (!name || !path) throw new Error('请先在左侧选择一个文件'); + await api(`/api/repos/${name}/commit`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ path, message: $('#file-msg').value }) + }); +} + async function saveFile(commit) { const name = current; const path = fileCurrent; @@ -887,16 +898,12 @@ async function saveFile(commit) { showDraftNote(false); draftServer = content; if (commit) { - await api(`/api/repos/${name}/commit`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ path, message: $('#file-msg').value }) - }); - toast('已保存并提交'); + await commitCurrentFile(); + toast('已保存并提交:' + path); } else { $('#f-diff-scope').value = 'working'; showTab('diff'); - toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动,或稍后由自动同步提交。'); + toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动;提交请用「提交」或「保存并提交」。'); } } catch (err) { toast('保存失败:' + err.message); } } @@ -944,6 +951,15 @@ $('#file-list').addEventListener('click', (e) => { }); $('#btn-file-save').addEventListener('click', () => saveFile(false)); $('#btn-file-commit').addEventListener('click', () => saveFile(true)); +$('#btn-file-commit-only').addEventListener('click', async () => { + if (!current || !fileCurrent) { toast('请先在左侧选择一个文件'); return; } + try { + await commitCurrentFile(); + toast('已提交:' + fileCurrent); + if (Editor.value === draftServer) await loadFile(current, fileCurrent); + refresh(); + } catch (err) { toast('提交失败:' + err.message, 'error'); } +}); $('#file-editor').addEventListener('input', scheduleDraft); $('#file-editor').addEventListener('keydown', (e) => {