UI: Improvement copy text in markdown (didn't work in HTTP)
This commit is contained in:
parent
113a6389fa
commit
47b9892f80
@ -21,6 +21,7 @@ import { DOCUMENT } from '@angular/common';
|
|||||||
import { WINDOW } from '@core/services/window.service';
|
import { WINDOW } from '@core/services/window.service';
|
||||||
import { Tokenizer } from 'marked';
|
import { Tokenizer } from 'marked';
|
||||||
import * as marked from 'marked';
|
import * as marked from 'marked';
|
||||||
|
import { Clipboard } from '@angular/cdk/clipboard';
|
||||||
|
|
||||||
const copyCodeBlock = '{:copy-code}';
|
const copyCodeBlock = '{:copy-code}';
|
||||||
const codeStyleRegex = '^{:code-style="(.*)"}\n';
|
const codeStyleRegex = '^{:code-style="(.*)"}\n';
|
||||||
@ -47,6 +48,7 @@ export class MarkedOptionsService extends MarkedOptions {
|
|||||||
private id = 1;
|
private id = 1;
|
||||||
|
|
||||||
constructor(private translate: TranslateService,
|
constructor(private translate: TranslateService,
|
||||||
|
private clipboardService: Clipboard,
|
||||||
@Inject(WINDOW) private readonly window: Window,
|
@Inject(WINDOW) private readonly window: Window,
|
||||||
@Inject(DOCUMENT) private readonly document: Document) {
|
@Inject(DOCUMENT) private readonly document: Document) {
|
||||||
super();
|
super();
|
||||||
@ -162,7 +164,7 @@ export class MarkedOptionsService extends MarkedOptions {
|
|||||||
const copyWrapper = $('#codeWrapper' + id);
|
const copyWrapper = $('#codeWrapper' + id);
|
||||||
if (copyWrapper.hasClass('noChars')) {
|
if (copyWrapper.hasClass('noChars')) {
|
||||||
const text = decodeURIComponent($('#copyCodeId' + id).text());
|
const text = decodeURIComponent($('#copyCodeId' + id).text());
|
||||||
this.window.navigator.clipboard.writeText(text).then(() => {
|
if (this.clipboardService.copy(text)) {
|
||||||
import('tooltipster').then(
|
import('tooltipster').then(
|
||||||
() => {
|
() => {
|
||||||
if (!copyWrapper.hasClass('tooltipstered')) {
|
if (!copyWrapper.hasClass('tooltipstered')) {
|
||||||
@ -186,12 +188,11 @@ export class MarkedOptionsService extends MarkedOptions {
|
|||||||
}
|
}
|
||||||
const tooltip = copyWrapper.tooltipster('instance');
|
const tooltip = copyWrapper.tooltipster('instance');
|
||||||
tooltip.open();
|
tooltip.open();
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface CodeContext {
|
interface CodeContext {
|
||||||
copyCode: boolean;
|
copyCode: boolean;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user