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