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();
|
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() {
|
async function handleCreateNotebook() {
|
||||||
if (!newNotebookName.trim()) return;
|
if (!newNotebookName.trim()) return;
|
||||||
try {
|
try {
|
||||||
|
const trimmedName = newNotebookName.trim();
|
||||||
const parentRel = newNotebookParent?.relative_path ?? null;
|
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 = '';
|
newNotebookName = '';
|
||||||
showNewNotebook = false;
|
showNewNotebook = false;
|
||||||
newNotebookParent = null;
|
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) {
|
function startNewSubNotebook(nb: NotebookEntry) {
|
||||||
contextMenu = null;
|
contextMenu = null;
|
||||||
newNotebookParent = nb;
|
newNotebookParent = nb;
|
||||||
@@ -657,10 +686,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value={newNotebookName}
|
bind:value={newNotebookName}
|
||||||
placeholder={newNotebookParent ? 'Sub-notebook name...' : 'Notebook name...'}
|
placeholder={newNotebookParent ? 'Sub-notebook name...' : 'Notebook name...'}
|
||||||
onkeydown={(e) => {
|
onkeydown={handleNewNotebookKeydown}
|
||||||
if (e.key === 'Enter') handleCreateNotebook();
|
|
||||||
if (e.key === 'Escape') { showNewNotebook = false; newNotebookName = ''; newNotebookParent = null; }
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user