Compare commits
4
Commits
5f555b447d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5a1612329 | ||
|
|
2862f662c4 | ||
|
|
0ac410d954 | ||
|
|
904ddcc0ba |
+23
-7
@@ -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) => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user