From c5c7f8a623591bdb53c5a3b6e7414aedd08e4ec5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 10 Feb 2020 23:00:39 -0500 Subject: [PATCH] adjustments to copy username/pass shortcuts --- jslib | 2 +- src/app/vault/vault.component.ts | 18 ++++++++++++------ src/main/menu.main.ts | 29 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/jslib b/jslib index bb459ce4b4..fd260dfbae 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit bb459ce4b45d0ddcfc2ec0cfe3e925125550d862 +Subproject commit fd260dfbae1717cdc019353f091501ac1dabe45f diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index e6e5914472..d06ad1d4ea 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -32,6 +32,7 @@ import { GroupingsComponent } from './groupings.component'; import { PasswordGeneratorComponent } from './password-generator.component'; import { PasswordHistoryComponent } from './password-history.component'; import { ShareComponent } from './share.component'; +import { ViewComponent } from './view.component'; import { CipherType } from 'jslib/enums/cipherType'; import { EventType } from 'jslib/enums/eventType'; @@ -53,6 +54,7 @@ const BroadcasterSubscriptionId = 'VaultComponent'; templateUrl: 'vault.component.html', }) export class VaultComponent implements OnInit, OnDestroy { + @ViewChild(ViewComponent) viewComponent: ViewComponent; @ViewChild(AddEditComponent) addEditComponent: AddEditComponent; @ViewChild(CiphersComponent) ciphersComponent: CiphersComponent; @ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent; @@ -152,15 +154,19 @@ export class VaultComponent implements OnInit, OnDestroy { this.showingModal = false; break; case 'copyUsername': - const selectedCipherU = this.cipherId != null ? this.ciphersComponent.ciphers.find(cipher => cipher.id == this.cipherId) : null; - if (selectedCipherU != null && selectedCipherU.login != null && selectedCipherU.login.username != null) { - this.copyValue(selectedCipherU.login.username, 'username'); + const uComponent = this.addEditComponent == null ? this.viewComponent : this.addEditComponent; + const uCipher = uComponent != null ? uComponent.cipher : null; + if (this.cipherId != null && uCipher != null && uCipher.id === this.cipherId && + uCipher.login != null && uCipher.login.username != null) { + this.copyValue(uCipher.login.username, 'username'); } break; case 'copyPassword': - const selectedCipherP = this.cipherId != null ? this.ciphersComponent.ciphers.find(cipher => cipher.id == this.cipherId) : null; - if (selectedCipherP != null && selectedCipherP.login != null && selectedCipherP.login.password != null) { - this.copyValue(selectedCipherP.login.password, 'password'); + const pComponent = this.addEditComponent == null ? this.viewComponent : this.addEditComponent; + const pCipher = pComponent != null ? pComponent.cipher : null; + if (this.cipherId != null && pCipher != null && pCipher.id === this.cipherId && + pCipher.login != null && pCipher.login.password != null) { + this.copyValue(pCipher.login.password, 'password'); } break; default: diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index 160cf44ced..5920270e51 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -152,6 +152,22 @@ export class MenuMain extends BaseMenu { }, ]; + this.editMenuItemOptions.submenu = (this.editMenuItemOptions.submenu as MenuItemConstructorOptions[]).concat([ + { type: 'separator' }, + { + label: this.main.i18nService.t('copyUsername'), + id: 'copyUsername', + click: () => this.main.messagingService.send('copyUsername'), + accelerator: 'CmdOrCtrl+U', + }, + { + label: this.main.i18nService.t('copyPassword'), + id: 'copyPassword', + click: () => this.main.messagingService.send('copyPassword'), + accelerator: 'CmdOrCtrl+P', + }, + ]); + if (!isWindowsStore()) { accountSubmenu.unshift({ label: this.main.i18nService.t('premiumMembership'), @@ -359,19 +375,6 @@ export class MenuMain extends BaseMenu { click: () => this.main.messagingService.send('openPasswordHistory'), }, { type: 'separator' }, - { - label: this.main.i18nService.t('copyUsername'), - id: 'copyUsername', - click: () => this.main.messagingService.send('copyUsername'), - accelerator: 'CmdOrCtrl+U', - }, - { - label: this.main.i18nService.t('copyPassword'), - id: 'copyPassword', - click: () => this.main.messagingService.send('copyPassword'), - accelerator: 'CmdOrCtrl+P', - }, - { type: 'separator' }, ] as MenuItemConstructorOptions[]).concat(this.viewSubMenuItemOptions), }, {