From cf95b7bc11ac4bd7e75cbcba866f886736b966e8 Mon Sep 17 00:00:00 2001 From: catnaut Date: Sat, 23 Dec 2023 11:57:28 +0800 Subject: [PATCH 1/2] feat: add option to show copy code icon for inline code --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 12b1827..ddccc75 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,14 @@ const settings = [ type: "string", default: "0em" }, + { + key: "ShowCopyInlineCodeIcon", + title: "Show copy code icon for inline code?", + description: "Check the box if you would like to show a copy code icon for inline code. If unchecked, the copy code icon will not show for inline code.", + type: "boolean", + default: true, + enumPicker: "checkbox" + }, { key: "AlwaysShowInlineCopyButton", title: "Always show inline copy code button?", @@ -64,7 +72,9 @@ const main = async () => { // after exiting edit mode, insert the copy copy button next to inline code const inline_code_text = added_node.querySelectorAll(".content :not(pre) > code"); for (const text of inline_code_text) { - insertCopyCodeButton_InlineCode(); + if (logseq.settings.ShowCopyInlineCodeIcon) { + insertCopyCodeButton_InlineCode(); + } } } } From fa10588a3bddc0830f894105742f086fb57818e3 Mon Sep 17 00:00:00 2001 From: catnaut Date: Sat, 23 Dec 2023 12:24:59 +0800 Subject: [PATCH 2/2] refactor: use choice to set inline code copy style fix: hide inline code copy button after setting changed fix: inline code copy button insertion --- src/index.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/index.js b/src/index.js index ddccc75..47736a6 100644 --- a/src/index.js +++ b/src/index.js @@ -17,20 +17,17 @@ const settings = [ default: "0em" }, { - key: "ShowCopyInlineCodeIcon", - title: "Show copy code icon for inline code?", - description: "Check the box if you would like to show a copy code icon for inline code. If unchecked, the copy code icon will not show for inline code.", - type: "boolean", - default: true, - enumPicker: "checkbox" - }, - { - key: "AlwaysShowInlineCopyButton", - title: "Always show inline copy code button?", - description: "Check the box if you would like the copy code button to always show next to inline code. If unchecked, the copy code button will only appear when hovering over the inline code.", - default: false, - type: "boolean", - enumPicker: "checkbox" + key: "InlineCopyButtonStyle", + title: "Inline copy code button style", + description: "Choose how you would like the copy code button to appear next to inline code.", + type: "enum", + default: "Show on hover", + enumChoices: [ + "Always show", + "Show on hover", + "Never show" + ], + enumPicker: "select" } ] logseq.useSettingsSchema(settings); @@ -72,9 +69,7 @@ const main = async () => { // after exiting edit mode, insert the copy copy button next to inline code const inline_code_text = added_node.querySelectorAll(".content :not(pre) > code"); for (const text of inline_code_text) { - if (logseq.settings.ShowCopyInlineCodeIcon) { - insertCopyCodeButton_InlineCode(); - } + insertCopyCodeButton_InlineCode(); } } } @@ -187,13 +182,21 @@ const main = async () => { `) // always show the copy button for inline code - if (logseq.settings.AlwaysShowInlineCopyButton) { + if (logseq.settings.InlineCopyButtonStyle == "Always show") { logseq.provideStyle(` #${inline_code.id}-button { display: inline-flex; } `) } + // don't show copy button for inline code when UI inserted before setting changed + else if (logseq.settings.InlineCopyButtonStyle == "Never show") { + logseq.provideStyle(` + #${inline_code.id}-button { + display: none; + } + `) + } // show copy button for inline code on hover else { logseq.provideStyle(`