diff --git a/apps/browser/src/tools/popup/generator/generator.component.html b/apps/browser/src/tools/popup/generator/generator.component.html index 83b2c6dee7..5c9c749201 100644 --- a/apps/browser/src/tools/popup/generator/generator.component.html +++ b/apps/browser/src/tools/popup/generator/generator.component.html @@ -19,7 +19,11 @@ {{ "passwordGeneratorPolicyInEffect" | i18n }}
-
+
-
+
-
+
diff --git a/apps/web/src/app/tools/password-generator-history.component.html b/apps/web/src/app/tools/password-generator-history.component.html index a4b382c4b5..b451457660 100644 --- a/apps/web/src/app/tools/password-generator-history.component.html +++ b/apps/web/src/app/tools/password-generator-history.component.html @@ -10,7 +10,7 @@ {{ h.date | date : "medium" }} diff --git a/libs/angular/src/directives/copy-text.directive.ts b/libs/angular/src/directives/copy-text.directive.ts new file mode 100644 index 0000000000..e3298c214c --- /dev/null +++ b/libs/angular/src/directives/copy-text.directive.ts @@ -0,0 +1,20 @@ +import { Directive, ElementRef, HostListener, Input } from "@angular/core"; + +import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; + +@Directive({ + selector: "[appCopyText]", +}) +export class CopyTextDirective { + constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) {} + + @Input("appCopyText") copyText: string; + + @HostListener("copy") onCopy() { + if (window == null) { + return; + } + + this.platformUtilsService.copyToClipboard(this.copyText, { window: window }); + } +} diff --git a/libs/angular/src/directives/select-copy.directive.ts b/libs/angular/src/directives/select-copy.directive.ts deleted file mode 100644 index 908418c26f..0000000000 --- a/libs/angular/src/directives/select-copy.directive.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Directive, ElementRef, HostListener } from "@angular/core"; - -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; - -@Directive({ - selector: "[appSelectCopy]", -}) -export class SelectCopyDirective { - constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) {} - - @HostListener("copy") onCopy() { - if (window == null) { - return; - } - let copyText = ""; - const selection = window.getSelection(); - for (let i = 0; i < selection.rangeCount; i++) { - const range = selection.getRangeAt(i); - const text = range.toString(); - - // The selection should only contain one line of text. In some cases however, the - // selection contains newlines and space characters from the indentation of following - // sibling nodes. To avoid copying passwords containing trailing newlines and spaces - // that aren't part of the password, the selection has to be trimmed. - let stringEndPos = text.length; - const newLinePos = text.search(/(?:\r\n|\r|\n)/); - if (newLinePos > -1) { - const otherPart = text.substr(newLinePos).trim(); - if (otherPart === "") { - stringEndPos = newLinePos; - } - } - copyText += text.substring(0, stringEndPos); - } - this.platformUtilsService.copyToClipboard(copyText, { window: window }); - } -} diff --git a/libs/angular/src/jslib.module.ts b/libs/angular/src/jslib.module.ts index 929875bbb2..649dacf24b 100644 --- a/libs/angular/src/jslib.module.ts +++ b/libs/angular/src/jslib.module.ts @@ -10,13 +10,13 @@ import { ApiActionDirective } from "./directives/api-action.directive"; import { AutofocusDirective } from "./directives/autofocus.directive"; import { BoxRowDirective } from "./directives/box-row.directive"; import { CopyClickDirective } from "./directives/copy-click.directive"; +import { CopyTextDirective } from "./directives/copy-text.directive"; import { FallbackSrcDirective } from "./directives/fallback-src.directive"; import { IfFeatureDirective } from "./directives/if-feature.directive"; import { InputStripSpacesDirective } from "./directives/input-strip-spaces.directive"; import { InputVerbatimDirective } from "./directives/input-verbatim.directive"; import { LaunchClickDirective } from "./directives/launch-click.directive"; import { NotPremiumDirective } from "./directives/not-premium.directive"; -import { SelectCopyDirective } from "./directives/select-copy.directive"; import { StopClickDirective } from "./directives/stop-click.directive"; import { StopPropDirective } from "./directives/stop-prop.directive"; import { TrueFalseValueDirective } from "./directives/true-false-value.directive"; @@ -50,6 +50,7 @@ import { IconComponent } from "./vault/components/icon.component"; AutofocusDirective, BoxRowDirective, CalloutComponent, + CopyTextDirective, CreditCardNumberPipe, EllipsisPipe, ExportScopeCalloutComponent, @@ -61,7 +62,6 @@ import { IconComponent } from "./vault/components/icon.component"; NotPremiumDirective, SearchCiphersPipe, SearchPipe, - SelectCopyDirective, StopClickDirective, StopPropDirective, TrueFalseValueDirective, @@ -81,6 +81,7 @@ import { IconComponent } from "./vault/components/icon.component"; BitwardenToastModule, BoxRowDirective, CalloutComponent, + CopyTextDirective, CreditCardNumberPipe, EllipsisPipe, ExportScopeCalloutComponent, @@ -92,7 +93,6 @@ import { IconComponent } from "./vault/components/icon.component"; NotPremiumDirective, SearchCiphersPipe, SearchPipe, - SelectCopyDirective, StopClickDirective, StopPropDirective, TrueFalseValueDirective,