Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rendered_markdown: Fix code getting copied when visiting playground.
nimishmedatwalacf13e49cffa
diff --git a/web/src/rendered_markdown.ts b/web/src/rendered_markdown.tsindex b2c250bca46..7cca8b59709 100644--- a/web/src/rendered_markdown.ts+++ b/web/src/rendered_markdown.ts@@ -307,14 +307,15 @@ export const update_elements = ($content: JQuery): void => {$view_in_playground_button.attr("data-tippy-content", title);$view_in_playground_button.attr("aria-label", title);}-- const clipboard = new ClipboardJS($buttonContainer[0], {+ const $copy_button = $buttonContainer.find(".copy_codeblock");+ const clipboard = new ClipboardJS($copy_button[0], {text(copy_element) {- return $(copy_element).siblings("code").text();+ const $code = $(copy_element).parent().siblings("code");+ return $code.text();},});+clipboard.on("success", () => {- const $copy_button = $buttonContainer.find(".copy_codeblock");show_copied_confirmation($copy_button[0]);});$codehilite.addClass("zulip-code-block");diff --git a/web/tests/rendered_markdown.test.js b/web/tests/rendered_markdown.test.jsindex 68d55c3982e..2f4567f8d07 100644--- a/web/tests/rendered_markdown.test.js+++ b/web/tests/rendered_markdown.test.js@@ -529,12 +529,14 @@ function assert_clipboard_setup() {assert.equal(clipboard_args[0], "copy-code-stub");const text = clipboard_args[1].text({to_$: () => ({- siblings(arg) {- assert.equal(arg, "code");- return {- text: () => "text",- };- },+ parent: () => ({+ siblings(arg) {+ assert.equal(arg, "code");+ return {+ text: () => "text",+ };+ },+ }),}),});assert.equal(text, "text");