Commit c783a2a6e30f89faf986f09cc2afc880627437eb

Authored by Igor Kulikov
Committed by GitHub
2 parents 460418ac 47b9892f

Merge pull request #5484 from vvlladd28/improvement/markdown/copy-text

[3.3.2] UI: Improvement copy text in markdown (didn't work in HTTP)
@@ -21,6 +21,7 @@ import { DOCUMENT } from '@angular/common'; @@ -21,6 +21,7 @@ import { DOCUMENT } from '@angular/common';
21 import { WINDOW } from '@core/services/window.service'; 21 import { WINDOW } from '@core/services/window.service';
22 import { Tokenizer } from 'marked'; 22 import { Tokenizer } from 'marked';
23 import * as marked from 'marked'; 23 import * as marked from 'marked';
  24 +import { Clipboard } from '@angular/cdk/clipboard';
24 25
25 const copyCodeBlock = '{:copy-code}'; 26 const copyCodeBlock = '{:copy-code}';
26 const codeStyleRegex = '^{:code-style="(.*)"}\n'; 27 const codeStyleRegex = '^{:code-style="(.*)"}\n';
@@ -47,6 +48,7 @@ export class MarkedOptionsService extends MarkedOptions { @@ -47,6 +48,7 @@ export class MarkedOptionsService extends MarkedOptions {
47 private id = 1; 48 private id = 1;
48 49
49 constructor(private translate: TranslateService, 50 constructor(private translate: TranslateService,
  51 + private clipboardService: Clipboard,
50 @Inject(WINDOW) private readonly window: Window, 52 @Inject(WINDOW) private readonly window: Window,
51 @Inject(DOCUMENT) private readonly document: Document) { 53 @Inject(DOCUMENT) private readonly document: Document) {
52 super(); 54 super();
@@ -162,7 +164,7 @@ export class MarkedOptionsService extends MarkedOptions { @@ -162,7 +164,7 @@ export class MarkedOptionsService extends MarkedOptions {
162 const copyWrapper = $('#codeWrapper' + id); 164 const copyWrapper = $('#codeWrapper' + id);
163 if (copyWrapper.hasClass('noChars')) { 165 if (copyWrapper.hasClass('noChars')) {
164 const text = decodeURIComponent($('#copyCodeId' + id).text()); 166 const text = decodeURIComponent($('#copyCodeId' + id).text());
165 - this.window.navigator.clipboard.writeText(text).then(() => { 167 + if (this.clipboardService.copy(text)) {
166 import('tooltipster').then( 168 import('tooltipster').then(
167 () => { 169 () => {
168 if (!copyWrapper.hasClass('tooltipstered')) { 170 if (!copyWrapper.hasClass('tooltipstered')) {
@@ -186,9 +188,8 @@ export class MarkedOptionsService extends MarkedOptions { @@ -186,9 +188,8 @@ export class MarkedOptionsService extends MarkedOptions {
186 } 188 }
187 const tooltip = copyWrapper.tooltipster('instance'); 189 const tooltip = copyWrapper.tooltipster('instance');
188 tooltip.open(); 190 tooltip.open();
189 - }  
190 - );  
191 - }); 191 + });
  192 + }
192 } 193 }
193 } 194 }
194 } 195 }