From 7bd0733b88d1a7959c311e5abaf276fea286724c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 21 Mar 2019 09:55:45 -0400 Subject: [PATCH] optimize newLinePos search --- src/angular/directives/flex-copy.directive.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/angular/directives/flex-copy.directive.ts b/src/angular/directives/flex-copy.directive.ts index e5e700dbba..89607fdedc 100644 --- a/src/angular/directives/flex-copy.directive.ts +++ b/src/angular/directives/flex-copy.directive.ts @@ -23,10 +23,14 @@ export class FlexCopyDirective { 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 identation of following + // 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. - const stringEndPos = text.includes('\n') ? text.search(/\r?\n/) : text.length; + // 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) { + stringEndPos = newLinePos; + } copyText += text.substring(0, stringEndPos); } this.platformUtilsService.copyToClipboard(copyText, { window: window });