From 46eaa636256932ddc45a73851d611c65c98367ad Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 1 Feb 2022 20:24:58 +0100 Subject: [PATCH] focus promoted/owned attributes input after activating the ribbon tab, closes #2606 --- package-lock.json | 18 +++++++++--------- package.json | 2 +- .../attribute_widgets/attribute_editor.js | 10 ++++++++++ .../app/widgets/containers/ribbon_container.js | 4 +++- .../ribbon_widgets/owned_attribute_list.js | 4 ++++ .../ribbon_widgets/promoted_attributes.js | 4 ++++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60dde35b1..da896f022 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "trilium", - "version": "0.49.4", + "version": "0.49.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.49.4", + "version": "0.49.5", "license": "AGPL-3.0-only", "dependencies": { "@electron/remote": "2.0.1", @@ -71,7 +71,7 @@ }, "devDependencies": { "cross-env": "7.0.3", - "electron": "16.0.6", + "electron": "16.0.8", "electron-builder": "22.14.5", "electron-packager": "15.4.0", "electron-rebuild": "3.2.5", @@ -3713,9 +3713,9 @@ } }, "node_modules/electron": { - "version": "16.0.6", - "resolved": "https://registry.npmjs.org/electron/-/electron-16.0.6.tgz", - "integrity": "sha512-Xs9dYLYhcJf3wXn8m2gDqFTb1L862KEhMxOx9swfFBHj6NoUPPtUgw/RyPQ0tXN1XPxG9vnBkoI0BdcKwrLKuQ==", + "version": "16.0.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-16.0.8.tgz", + "integrity": "sha512-znTVkl8LaGcPNdfc6SRr+6LYg2GtSCKXln/nW/PC+urBfAFnOYIuDock8QyGVFfzr5PuAa+g8YQQAboHV77D7g==", "hasInstallScript": true, "dependencies": { "@electron/get": "^1.13.0", @@ -14169,9 +14169,9 @@ } }, "electron": { - "version": "16.0.6", - "resolved": "https://registry.npmjs.org/electron/-/electron-16.0.6.tgz", - "integrity": "sha512-Xs9dYLYhcJf3wXn8m2gDqFTb1L862KEhMxOx9swfFBHj6NoUPPtUgw/RyPQ0tXN1XPxG9vnBkoI0BdcKwrLKuQ==", + "version": "16.0.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-16.0.8.tgz", + "integrity": "sha512-znTVkl8LaGcPNdfc6SRr+6LYg2GtSCKXln/nW/PC+urBfAFnOYIuDock8QyGVFfzr5PuAa+g8YQQAboHV77D7g==", "requires": { "@electron/get": "^1.13.0", "@types/node": "^14.6.2", diff --git a/package.json b/package.json index 93e0f158f..0ba9271e6 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ }, "devDependencies": { "cross-env": "7.0.3", - "electron": "16.0.6", + "electron": "16.0.8", "electron-builder": "22.14.5", "electron-packager": "15.4.0", "electron-rebuild": "3.2.5", diff --git a/src/public/app/widgets/attribute_widgets/attribute_editor.js b/src/public/app/widgets/attribute_widgets/attribute_editor.js index 433b4005a..614e74eb2 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_editor.js +++ b/src/public/app/widgets/attribute_widgets/attribute_editor.js @@ -497,6 +497,16 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget { await this.renderOwnedAttributes(attributes, false); } + focus() { + this.$editor.trigger('focus'); + + this.textEditor.model.change( writer => { + const positionAt = writer.createPositionAt(this.textEditor.model.document.getRoot(), 'end'); + + writer.setSelection(positionAt); + } ); + } + entitiesReloadedEvent({loadResults}) { if (loadResults.getAttributes(this.componentId).find(attr => attributeService.isAffecting(attr, this.note))) { this.refresh(); diff --git a/src/public/app/widgets/containers/ribbon_container.js b/src/public/app/widgets/containers/ribbon_container.js index 550287807..a344bef3a 100644 --- a/src/public/app/widgets/containers/ribbon_container.js +++ b/src/public/app/widgets/containers/ribbon_container.js @@ -186,7 +186,9 @@ export default class RibbonContainer extends NoteContextAwareWidget { const activeChild = this.getActiveRibbonWidget(); if (activeChild && (refreshActiveTab || !wasAlreadyActive)) { - activeChild.handleEvent('noteSwitched', {noteContext: this.noteContext, notePath: this.notePath}); + activeChild.handleEvent('noteSwitched', {noteContext: this.noteContext, notePath: this.notePath}).then(() => { + activeChild.focus?.(); + }); } } else { this.lastActiveComponentId = null; diff --git a/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js b/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js index 4f294979d..da8ed35ba 100644 --- a/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js +++ b/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js @@ -82,4 +82,8 @@ export default class OwnedAttributeListWidget extends NoteContextAwareWidget { this.getTitle(this.note); } } + + focus() { + this.attributeEditorWidget.focus(); + } } diff --git a/src/public/app/widgets/ribbon_widgets/promoted_attributes.js b/src/public/app/widgets/ribbon_widgets/promoted_attributes.js index d35fe4f0f..6c6e58495 100644 --- a/src/public/app/widgets/ribbon_widgets/promoted_attributes.js +++ b/src/public/app/widgets/ribbon_widgets/promoted_attributes.js @@ -310,6 +310,10 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { $attr.attr("data-attribute-id", result.attributeId); } + focus() { + this.$widget.find(".promoted-attribute-input:first").focus(); + } + entitiesReloadedEvent({loadResults}) { if (loadResults.getAttributes(this.componentId).find(attr => attributeService.isAffecting(attr, this.note))) { this.refresh();