mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
Improve notebook path creation (#135)
Backspace on an empty sub-notebook field returns to top-level creation, and top-level names like Parent/Child now create nested notebooks in one action. Validated with pnpm build. Reviewed-on: https://codeberg.org/ArkHost/HelixNotes/pulls/135
This commit is contained in:
@@ -213,11 +213,23 @@
|
||||
await focusNewNotebookInput();
|
||||
}
|
||||
|
||||
function getNotebookNameSegments(name: string): string[] | null {
|
||||
const segments = name.split('/').map((segment) => segment.trim());
|
||||
if (segments.some((segment) => !segment || segment === '.' || segment === '..' || segment.includes('\\'))) {
|
||||
return null;
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
async function handleCreateNotebook() {
|
||||
if (!newNotebookName.trim()) return;
|
||||
try {
|
||||
const trimmedName = newNotebookName.trim();
|
||||
const parentRel = newNotebookParent?.relative_path ?? null;
|
||||
await createNotebook(parentRel, newNotebookName.trim());
|
||||
const name = parentRel ? trimmedName : getNotebookNameSegments(trimmedName)?.join('/');
|
||||
if (!name) return;
|
||||
|
||||
await createNotebook(parentRel, name);
|
||||
newNotebookName = '';
|
||||
showNewNotebook = false;
|
||||
newNotebookParent = null;
|
||||
@@ -227,6 +239,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewNotebookKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter') {
|
||||
handleCreateNotebook();
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
showNewNotebook = false;
|
||||
newNotebookName = '';
|
||||
newNotebookParent = null;
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Backspace' && newNotebookParent && newNotebookName.length === 0) {
|
||||
e.preventDefault();
|
||||
newNotebookParent = null;
|
||||
}
|
||||
}
|
||||
|
||||
function startNewSubNotebook(nb: NotebookEntry) {
|
||||
contextMenu = null;
|
||||
newNotebookParent = nb;
|
||||
@@ -657,10 +686,7 @@
|
||||
type="text"
|
||||
bind:value={newNotebookName}
|
||||
placeholder={newNotebookParent ? 'Sub-notebook name...' : 'Notebook name...'}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') handleCreateNotebook();
|
||||
if (e.key === 'Escape') { showNewNotebook = false; newNotebookName = ''; newNotebookParent = null; }
|
||||
}}
|
||||
onkeydown={handleNewNotebookKeydown}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user