WIP search

This commit is contained in:
Magnus Åhall 2026-02-25 23:50:31 +01:00
parent 39b9515f76
commit b20943cfd2

View file

@ -153,11 +153,31 @@ export class Application {
for (const folder of folders) for (const folder of folders)
this.recordsTree.append(folder.render()) this.recordsTree.append(folder.render())
this.removeEmptyFolders()
// Subscribe to settings update since the elements they will change // Subscribe to settings update since the elements they will change
// exists now. // exists now.
_mbus.subscribe('settings_updated', event => this.handlerSettingsUpdated(event.detail)) _mbus.subscribe('settings_updated', event => this.handlerSettingsUpdated(event.detail))
this.setBoxedFolders(this.settings.get('boxed_folders')) this.setBoxedFolders(this.settings.get('boxed_folders'))
}// }}}
removeEmptyFolders(folder) {// {{{
if (folder === undefined)
folder = this.topFolder
folder.subfolders.forEach((folder, _label) => {
this.removeEmptyFolders(folder)
})
// This is a leaf folder in the tree.
// It has to be removed from the parent as well, since that could be up for
// removal as well, all the way up the chain.
if (folder.subfolders.size === 0 && folder.records.length === 0) {
if (folder.parentFolder) {
folder.parentFolder.subfolders.delete(folder.labels()[0])
}
folder.div?.remove()
}
}// }}} }// }}}
handlerKeys(event) {// {{{ handlerKeys(event) {// {{{
let handled = true let handled = true
@ -175,6 +195,10 @@ export class Application {
new RecordDialog(new Record()).show() new RecordDialog(new Record()).show()
break break
case 'f':
this.searchField.focus()
break
default: default:
handled = false handled = false
} }
@ -195,13 +219,13 @@ export class Application {
else else
document.body.classList.remove('boxed-folders') document.body.classList.remove('boxed-folders')
}// }}} }// }}}
search() { search() {// {{{
this.searchFor = this.searchField.value.trim().toLowerCase() this.searchFor = this.searchField.value.trim().toLowerCase()
this.cleanFolders() this.cleanFolders()
this.renderFolders() this.renderFolders()
this.render() this.render()
} }// }}}
} }
class Folder { class Folder {