Node renaming

This commit is contained in:
Magnus Åhall 2026-06-10 17:21:29 +02:00
parent c583138270
commit 9ebda04428
2 changed files with 31 additions and 13 deletions

View file

@ -74,6 +74,11 @@ export class App {
keyHandler(event) {//{{{ keyHandler(event) {//{{{
let handled = true 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. // 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. // 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. // Thus, the exception is acceptable to consequent use of alt+shift.

View file

@ -63,18 +63,7 @@ export class N2PageNodeUI extends CustomHTMLElement {
_mbus.subscribe('MARKDOWN_TOGGLE', () => this.showMarkdown(!this.showMarkdown())) _mbus.subscribe('MARKDOWN_TOGGLE', () => this.showMarkdown(!this.showMarkdown()))
_mbus.subscribe('MARKDOWN_EDIT', ({ detail }) => this.editMarkdown(detail.data)) _mbus.subscribe('MARKDOWN_EDIT', ({ detail }) => this.editMarkdown(detail.data))
this.elName.addEventListener('click', () => { this.elName.addEventListener('click', async () => this.renameNode())
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.elNodeContent.addEventListener('input', event => this.contentChanged(event)) this.elNodeContent.addEventListener('input', event => this.contentChanged(event))
this.elNodeContent.addEventListener('paste', async (event) => this.pasteHandler(event)) this.elNodeContent.addEventListener('paste', async (event) => this.pasteHandler(event))
this.elIconMarkdown.addEventListener('click', () => this.showMarkdown(!this.showMarkdown())) this.elIconMarkdown.addEventListener('click', () => this.showMarkdown(!this.showMarkdown()))
@ -111,6 +100,30 @@ export class N2PageNodeUI extends CustomHTMLElement {
} else } else
this.elNodeContent.focus({ preventScroll: true }) 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() {// {{{ async saveNode() {// {{{
if (!this.node.isModified()) if (!this.node.isModified())
return return