Skip to content

Commit 7764a26

Browse files
authored
fix: allow code snippets to be copied
1 parent 6e6a7b2 commit 7764a26

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/code-snippet/code-snippet.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
232232
}
233233

234234
handleScroll() {
235+
if (this.skeleton) {
236+
return;
237+
}
238+
235239
let ref;
236240
switch (this.display) {
237241
case "multi":
@@ -263,7 +267,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
263267
onCopyButtonClicked() {
264268
if (!this.disabled) {
265269
window.navigator.clipboard
266-
.writeText(this.code.nativeElement.innerText || this.code.nativeElement.textContent).then(() => {
270+
.writeText(this.code).then(() => {
267271
this.showFeedback = true;
268272
this.animating = true;
269273
setTimeout(() => {
@@ -276,6 +280,11 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
276280

277281
ngOnInit() {
278282
this.calculateContainerHeight();
283+
}
284+
285+
ngAfterViewInit() {
286+
this.canExpand();
287+
this.handleScroll();
279288
if (window) {
280289
this.eventService.on(window as any, "resize", () => {
281290
this.canExpand();
@@ -284,15 +293,8 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
284293
}
285294
}
286295

287-
ngAfterViewInit() {
288-
setTimeout(() => {
289-
this.canExpand();
290-
this.handleScroll();
291-
});
292-
}
293-
294296
calculateContainerHeight() {
295-
if (this.display === "multi") {
297+
if (this.display === "multi" && !this.skeleton) {
296298
this.styles = {};
297299
if (this.expanded) {
298300
if (this.maxExpandedNumberOfRows > 0) {
@@ -313,7 +315,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
313315
}
314316

315317
protected canExpand() {
316-
if (this.display === "multi") {
318+
if (this.display === "multi" && !this.skeleton) {
317319
const height = this.codeContent.nativeElement.getBoundingClientRect().height;
318320
if (
319321
this.maxCollapsedNumberOfRows > 0 &&

0 commit comments

Comments
 (0)