fix: improve notes rename conflicts

This commit is contained in:
mirivlad 2026-06-28 16:49:08 +08:00
parent f2e837a776
commit 10bc28cef7
2 changed files with 25 additions and 4 deletions

View File

@ -178,6 +178,7 @@
var noteActions = []; var noteActions = [];
var filterText = ''; var filterText = '';
var sortMode = 'title-asc'; var sortMode = 'title-asc';
var renameTarget = null;
function notesParent() { function notesParent() {
return workspaceRoot || ''; return workspaceRoot || '';
@ -489,7 +490,7 @@
if (disposed) return; if (disposed) return;
data = data || {}; data = data || {};
if (data.conflict) { if (data.conflict) {
showConflictModal(title, data.path); showConflictModal(title, data.path, createInput);
return; return;
} }
hideCreate(); hideCreate();
@ -540,7 +541,7 @@
if (disposed) return; if (disposed) return;
data = data || {}; data = data || {};
if (data.conflict) { if (data.conflict) {
showConflictModal(newTitle, data.path); showConflictModal(newTitle, data.path, renameInput);
return; return;
} }
hideRename(); hideRename();
@ -571,16 +572,17 @@
// ─── Conflict Modal ───────────────────────────────────── // ─── Conflict Modal ─────────────────────────────────────
function showConflictModal(title, existingPath) { function showConflictModal(title, existingPath, focusTarget) {
var overlay = el('div', { className: 'notes-modal-overlay' }); var overlay = el('div', { className: 'notes-modal-overlay' });
var modal = el('div', { className: 'notes-modal' }, [ var modal = el('div', { className: 'notes-modal' }, [
el('div', { className: 'notes-modal-title' }, ['Name Conflict']), el('div', { className: 'notes-modal-title' }, ['Name Conflict']),
el('div', { className: 'notes-modal-msg' }, [ el('div', { className: 'notes-modal-msg' }, [
'A note with the title "' + title + '" already exists.', 'A note with the title "' + title + '" already exists.',
existingPath ? ' Existing file: ' + existingPath + '.' : '',
' Please choose a different title.' ' Please choose a different title.'
].join('')), ].join('')),
el('div', { className: 'notes-modal-actions' }, [ el('div', { className: 'notes-modal-actions' }, [
el('button', { className: 'notes-modal-btn confirm', textContent: 'OK', onClick: function () { overlay.remove(); createInput.focus(); } }) el('button', { className: 'notes-modal-btn confirm', textContent: 'OK', onClick: function () { overlay.remove(); (focusTarget || createInput).focus(); } })
]) ])
]); ]);
overlay.appendChild(modal); overlay.appendChild(modal);

View File

@ -288,6 +288,25 @@ async function mountNotes(api) {
sortSelect.value = 'title-asc'; sortSelect.value = 'title-asc';
sortSelect.dispatchEvent('change'); sortSelect.dispatchEvent('change');
const renameButton = walk(container, (node) => node.getAttribute && node.getAttribute('data-note-action') === 'rename');
if (!renameButton) throw new Error('rename note button not found');
renameButton.click();
const renameInput = walk(container, (node) => node.getAttribute && node.getAttribute('data-notes-rename-input') !== undefined);
if (!renameInput) throw new Error('rename input not found');
renameInput.value = 'Second Note';
const renameConfirm = walk(container, (node) => node.tagName === 'BUTTON' && node.textContent === 'Rename');
if (!renameConfirm) throw new Error('rename confirm button not found');
renameConfirm.click();
await flush();
const conflictModal = walk(document.body, (node) => node.className === 'notes-modal-msg');
if (!conflictModal || !conflictModal.textContent.includes('Project/Notes/Second_Note.md')) {
throw new Error(`rename conflict modal should include existing path, got ${conflictModal && conflictModal.textContent}`);
}
const conflictOk = walk(document.body, (node) => node.tagName === 'BUTTON' && node.textContent === 'OK');
if (!conflictOk) throw new Error('rename conflict OK button not found');
conflictOk.click();
await flush();
const providerAction = walk(container, (node) => node.getAttribute && node.getAttribute('data-note-contribution-action') === 'provider.note.action'); const providerAction = walk(container, (node) => node.getAttribute && node.getAttribute('data-note-contribution-action') === 'provider.note.action');
if (!providerAction) throw new Error('provider note action button not found'); if (!providerAction) throw new Error('provider note action button not found');
providerAction.click(); providerAction.click();