From 0047c0bdc0d33f8101aaf2138c7b41d655bb8343 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sat, 10 Dec 2022 14:05:46 +0100 Subject: [PATCH] settings: document code on when exactly the pubkey is regenerated The pubkey should not always be regenerated when a privatekey is pasted. The reason is that on paste event is fired before the privateKeyInput value is updated. Added code comments on when the condition passes and should be save to re-generate the pubkey. --- src/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 0e3c37f..11734bd 100644 --- a/src/main.js +++ b/src/main.js @@ -613,10 +613,10 @@ privateKeyInput.addEventListener('paste', (event) => { if (pubKeyInput.value || !event.clipboardData) { return; } - if (privateKeyInput.value === '' || ( - privateKeyInput.selectionStart === 0 + if (privateKeyInput.value === '' || ( // either privatekey field is empty + privateKeyInput.selectionStart === 0 // or the whole text is selected and replaced with the clipboard && privateKeyInput.selectionEnd === privateKeyInput.value.length - )) { + )) { // only generate the pubkey if no data other than the text from clipboard will be used try { pubKeyInput.value = getPublicKey(event.clipboardData.getData('text')); } catch(err) {} // settings form will call validKeys on input and display the error