From 82e26829c5d4fadde705b854ef1a8f37c22ffd23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 22 May 2023 09:03:17 -0400 Subject: [PATCH] fix: closes #11620, fix copy code when line numbers are enabled --- public/src/client/topic.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index a0b9aba183..da5ecae1b0 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -226,7 +226,14 @@ define('forum/topic', [ const btn = $(trigger); btn.find('i').removeClass('fa-copy').addClass('fa-check'); setTimeout(() => btn.find('i').removeClass('fa-check').addClass('fa-copy'), 2000); - return btn.parent().find('code').text(); + const codeEl = btn.parent().find('code'); + if (codeEl.attr('data-lines')) { + let codeText = ''; + codeEl.find('.hljs-ln-code[data-line-number]') + .each((index, el) => { codeText += $(el).text() + '\n'; }); + return codeText; + } + return codeEl.text(); }, });