diff --git a/static/js/app.mjs b/static/js/app.mjs index 89c0011..0ce2cb0 100644 --- a/static/js/app.mjs +++ b/static/js/app.mjs @@ -74,6 +74,11 @@ export class App { keyHandler(event) {//{{{ let handled = true + if (event.key == 'F2') { + this.nodeUI.renameNode() + return + } + // All keybindings is Alt+Shift, since the popular browsers at the time (2023) allows to override thees. // Ctrl+S is the exception to using Alt+Shift, since it is overridable and in such widespread use for saving. // Thus, the exception is acceptable to consequent use of alt+shift. diff --git a/static/js/page_node.mjs b/static/js/page_node.mjs index 40997e2..93f7c7a 100644 --- a/static/js/page_node.mjs +++ b/static/js/page_node.mjs @@ -63,18 +63,7 @@ export class N2PageNodeUI extends CustomHTMLElement { _mbus.subscribe('MARKDOWN_TOGGLE', () => this.showMarkdown(!this.showMarkdown())) _mbus.subscribe('MARKDOWN_EDIT', ({ detail }) => this.editMarkdown(detail.data)) - this.elName.addEventListener('click', () => { - const name = prompt('Change title', this.node.data.Name) - if (name === null) - return - - try { - this.node.setName(name) - } catch (err) { - console.error(err) - alert(err) - } - }) + this.elName.addEventListener('click', async () => this.renameNode()) this.elNodeContent.addEventListener('input', event => this.contentChanged(event)) this.elNodeContent.addEventListener('paste', async (event) => this.pasteHandler(event)) this.elIconMarkdown.addEventListener('click', () => this.showMarkdown(!this.showMarkdown())) @@ -93,7 +82,7 @@ export class N2PageNodeUI extends CustomHTMLElement { this.node.setContent(this.elNodeContent.value) }) this.elIconHistory.addEventListener('click', () => _mbus.dispatch('SHOW_PAGE', { page: 'history' })) - this.elIconSave.addEventListener('click', ()=>this.saveNode()) + this.elIconSave.addEventListener('click', () => this.saveNode()) this.showMarkdown(true) }// }}} @@ -111,6 +100,30 @@ export class N2PageNodeUI extends CustomHTMLElement { } else this.elNodeContent.focus({ preventScroll: true }) }// }}} + async renameNode() { + const name = prompt('Change title', this.node.data.Name) + if (name === null) + return + + try { + // Document isn't only renamed, but also saved at once. + // Not really correct, but good enough to not have to implement + // a separate way to only rename the document. Since history is + // preserved it shouldn't be that horrible. + this.node.setName(name) + await this.node.save() + + // Re-render the parent treenode forcefully to sort it again. + const parentUUID = this.node.ParentUUID + if (!parentUUID) + return + const parentTreeNode = _app.sidebar.getTreeNode(parentUUID) + parentTreeNode?.render(true, true) + } catch (err) { + console.error(err) + alert(err) + } + } async saveNode() {// {{{ if (!this.node.isModified()) return