Compare commits

..
4 Commits
2 changed files with 26 additions and 9 deletions
+23 -7
View File
@@ -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) => {
+1
View File
@@ -117,6 +117,7 @@
<div class="file-actions" data-page-node-id="GAMAnkYKeMi93EVEx8eYOn">
<input id="file-msg" class="file-msg" placeholder="提交说明(可选)" data-page-node-id="aS2jRAr1kAkqElk1T4Cldz">
<button class="btn btn-sm" id="btn-file-save" data-page-node-id="gaVGyD6YkFFElkXJFBtLk5">保存</button>
<button class="btn btn-sm" id="btn-file-commit-only" title="提交当前文件在磁盘上的改动(不含编辑器里尚未保存的修改)">提交</button>
<button class="btn btn-sm btn-primary" id="btn-file-commit" data-page-node-id="1VDju8pdiboyM0zBgwff21">保存并提交</button>
</div>
</div>