Commit 47b9892f80f20dd24ab4a7586afe244b266224cf
1 parent
113a6389
UI: Improvement copy text in markdown (didn't work in HTTP)
Showing
1 changed file
with
5 additions
and
4 deletions
... | ... | @@ -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 | } | ... | ... |