Skip to content

Commit 972fe1b

Browse files
committed
copy settings to the clipboard
1 parent d7e1268 commit 972fe1b

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

src/core/settings.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {
33
ButtonComponent,
44
DropdownComponent,
55
getIcon,
6+
htmlToMarkdown,
67
Modifier,
78
normalizePath,
9+
Notice,
810
PluginSettingTab,
911
Setting,
1012
TextComponent,
@@ -662,6 +664,40 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
662664
});
663665
});
664666

667+
// ------------------------------------------------
668+
// Search and Settings to Clipboard
669+
// ------------------------------------------------
670+
671+
const settingActions = containerEl.createDiv("ex-settings-actions");
672+
const settingActionsContainer = settingActions.createDiv("setting-item-description ex-setting-actions-container");
673+
const clipboardActionEl = settingActionsContainer.createEl("a", {attr: { "aria-label": t("SETTINGS_COPY_TO_CLIPBOARD_ARIA") }});
674+
clipboardActionEl.innerHTML = getIcon("clipboard-copy").outerHTML + t("SETTINGS_COPY_TO_CLIPBOARD");
675+
clipboardActionEl.onClickEvent(e => {
676+
// Get the full HTML content first
677+
const fullHtml = containerEl.outerHTML;
678+
679+
// Find the index of the first <hr> element
680+
const startIndex = fullHtml.indexOf('<hr');
681+
682+
// Extract HTML from the first <hr> element onwards
683+
const html = startIndex > -1 ? fullHtml.substring(startIndex) : fullHtml;
684+
685+
function replaceHeading(html:string,level:number):string {
686+
const re = new RegExp(`<summary class="excalidraw-setting-h${level}">([^<]+)<\/summary>`,"g");
687+
return html.replaceAll(re,`<summary class="excalidraw-setting-h${level}"><h${level}>$1</h${level}></summary>`);
688+
}
689+
690+
let x = replaceHeading(html,1);
691+
x = replaceHeading(x,2);
692+
x = replaceHeading(x,3);
693+
x = replaceHeading(x,4);
694+
x = x.replaceAll(/<div class="setting-item-name">([^<]+)<\/div>/g,"<h5>$1</h5>");
695+
696+
const md = htmlToMarkdown(x);
697+
window.navigator.clipboard.writeText(md);
698+
new Notice(t("SETTINGS_COPIED_TO_CLIPBOARD"));
699+
});
700+
665701
// ------------------------------------------------
666702
// Saving
667703
// ------------------------------------------------

src/lang/locale/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export default {
205205
LINKS_BOOK_ARIA: "Read Sketch Your Mind, my book on Visual Thinking",
206206
LINKS_BOOK: "Read the Book",
207207

208+
SETTINGS_COPIED_TO_CLIPBOARD: "Markdown ready on clipboard",
209+
SETTINGS_COPY_TO_CLIPBOARD: "Copy as Text",
210+
SETTINGS_COPY_TO_CLIPBOARD_ARIA: "Copy the entire settings dialog to the clipboard as Markdown. Ideal for use with tools like ChatGPT to search and understand the settings.",
211+
208212
RELEASE_NOTES_NAME: "Display Release Notes after update",
209213
RELEASE_NOTES_DESC:
210214
"<b><u>Toggle ON:</u></b> Display release notes each time you update Excalidraw to a newer version.<br>" +

styles.css

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
640640
caret-color: var(--excalidraw-caret-color);
641641
}
642642

643-
.excalidraw-settings-links-container {
643+
.excalidraw-settings-links-container, .ex-setting-actions-container {
644644
display: flex; /* Align SVG and text horizontally */
645645
align-items: center; /* Center SVG and text vertically */
646646
text-decoration: none; /* Remove underline from links */
@@ -649,13 +649,20 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
649649
gap: 0.3em;
650650
}
651651

652-
.excalidraw-settings-links-container a {
652+
.excalidraw-settings-links-container {
653+
background-color: color-mix(in srgb, var(--color-base-100) 7%, transparent);
654+
padding: 0.5em;
655+
}
656+
657+
.excalidraw-settings-links-container a,
658+
.ex-setting-actions-container a {
653659
display: flex; /* Align children horizontally */
654660
align-items: center; /* Center items vertically */
655661
text-align: left;
656662
}
657663

658-
.excalidraw-settings-links-container svg {
664+
.excalidraw-settings-links-container svg,
665+
.ex-setting-actions-container svg {
659666
margin-right: 8px;
660667
height: 30px;
661668
width: 30px;

0 commit comments

Comments
 (0)