From fcf283b99be027f57028be8e3f42e6d1479c8da9 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Thu, 22 Oct 2020 13:21:07 +0300 Subject: [PATCH] Fix filling from keyboard without input field focus --- keepassxc-browser/content/keepassxc-browser.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index fafc642..2d87e1a 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -705,8 +705,23 @@ kpxc.detectDatabaseChange = async function(response) { // Fill requested from the context menu. Active element is used for combination detection kpxc.fillInFromActiveElement = async function(passOnly = false) { + if (kpxc.credentials.length === 0) { + return; + } + const el = document.activeElement; - if (el.nodeName !== 'INPUT' || kpxc.credentials.length === 0) { + if (el.nodeName !== 'INPUT') { + // No active input element selected -> fill the first combination found + if (kpxc.combinations.length > 0) { + kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); + + // Focus to the input field + const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; + if (field) { + field.focus(); + } + } + return; } else if (kpxc.credentials.length > 1 && kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { kpxcAutocomplete.showList(el);