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) {
|
async function saveFile(commit) {
|
||||||
const name = current;
|
const name = current;
|
||||||
const path = fileCurrent;
|
const path = fileCurrent;
|
||||||
@@ -887,16 +898,12 @@ async function saveFile(commit) {
|
|||||||
showDraftNote(false);
|
showDraftNote(false);
|
||||||
draftServer = content;
|
draftServer = content;
|
||||||
if (commit) {
|
if (commit) {
|
||||||
await api(`/api/repos/${name}/commit`, {
|
await commitCurrentFile();
|
||||||
method: 'POST',
|
toast('已保存并提交:' + path);
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ path, message: $('#file-msg').value })
|
|
||||||
});
|
|
||||||
toast('已保存并提交');
|
|
||||||
} else {
|
} else {
|
||||||
$('#f-diff-scope').value = 'working';
|
$('#f-diff-scope').value = 'working';
|
||||||
showTab('diff');
|
showTab('diff');
|
||||||
toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动,或稍后由自动同步提交。');
|
toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动;提交请用「提交」或「保存并提交」。');
|
||||||
}
|
}
|
||||||
} catch (err) { toast('保存失败:' + err.message); }
|
} catch (err) { toast('保存失败:' + err.message); }
|
||||||
}
|
}
|
||||||
@@ -944,6 +951,15 @@ $('#file-list').addEventListener('click', (e) => {
|
|||||||
});
|
});
|
||||||
$('#btn-file-save').addEventListener('click', () => saveFile(false));
|
$('#btn-file-save').addEventListener('click', () => saveFile(false));
|
||||||
$('#btn-file-commit').addEventListener('click', () => saveFile(true));
|
$('#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('input', scheduleDraft);
|
||||||
$('#file-editor').addEventListener('keydown', (e) => {
|
$('#file-editor').addEventListener('keydown', (e) => {
|
||||||
|
|||||||
+3
-2
@@ -116,8 +116,9 @@
|
|||||||
<textarea id="file-editor" class="file-editor" placeholder="选择左侧文件进行编辑(Ctrl/Cmd + S 保存)" spellcheck="false"></textarea>
|
<textarea id="file-editor" class="file-editor" placeholder="选择左侧文件进行编辑(Ctrl/Cmd + S 保存)" spellcheck="false"></textarea>
|
||||||
<div class="file-actions" data-page-node-id="GAMAnkYKeMi93EVEx8eYOn">
|
<div class="file-actions" data-page-node-id="GAMAnkYKeMi93EVEx8eYOn">
|
||||||
<input id="file-msg" class="file-msg" placeholder="提交说明(可选)" data-page-node-id="aS2jRAr1kAkqElk1T4Cldz">
|
<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-save" data-page-node-id="gaVGyD6YkFFElkXJFBtLk5">保存</button>
|
||||||
<button class="btn btn-sm btn-primary" id="btn-file-commit" data-page-node-id="1VDju8pdiboyM0zBgwff21">保存并提交</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user