diff --git a/CHANGELOG.md b/CHANGELOG.md index b25790c..88273e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ## 🏗️ developed > to be update in the next version +## 3.2.0-b1 +- [feature] Settings: global configuration for format on paste #97 + ## 3.1.0 - [feature] several commands (e.g. decode URI) support in front matter (metadata) - [feature] command for open settings tab directly diff --git a/manifest-beta.json b/manifest-beta.json index 3fd07d5..dc6988b 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "obsidian-text-format", "name": "Text Format", - "version": "3.1.0", + "version": "3.2.0-b1", "minAppVersion": "0.9.7", "description": "Format text such as lowercase/uppercase/capitalize/titlecase, converting order/bullet list, removing redundant spaces/newline characters.", "author": "Benature", diff --git a/src/langs/langs.ts b/src/langs/langs.ts index 3c722cc..3cd8dc1 100644 --- a/src/langs/langs.ts +++ b/src/langs/langs.ts @@ -28,7 +28,7 @@ const EN = { "word-cases-desc": "lowercase / uppercase / title case / capitalize case / cycle case", "lowercase-before-capitalize": "Lowercase before capitalize/title case", "lowercase-before-capitalize-desc": "When running the capitalize or title case command, the plugin will lowercase the selection at first.", - "cycle-case-sequence": "Cycle case sequence (one case in a line)", + "cycle-case-sequence": "Cycle case sequence (one case per line)", "cycle-case-sequence-desc": "Support cases: `lowerCase`, `upperCase`, `capitalizeWord`, `capitalizeSentence`, `titleCase`. \n" + "Note that the result of `capitalizeWord` and `titleCase` could be the same in some cases, " + @@ -109,7 +109,11 @@ const EN = { "method-decide-callout-type": "Method to decide callout type", "method-decide-callout-type-desc": "How to decide the type of new callout block for command `Callout format`? `Fix callout type` use the default callout type always, other methods only use the default type when it fails to find previous callout block.", "default-callout-type": "Default callout type", - "default-callout-type-desc": "Set the default callout type for command `Callout format`. " + "default-callout-type-desc": "Set the default callout type for command `Callout format`. ", + "format-on-paste": { + "name": "Format on paste", + "desc": "Format the pasted content automatically. One command per line.", + } } } diff --git a/src/main.ts b/src/main.ts index c18487e..ea56fca 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,7 +76,7 @@ export default class TextFormat extends Plugin { const text = activeElement.textContent; const replacedText = await this.quickFormat(text, cmd); await this.app.fileManager.processFrontMatter(file, (fm) => { - fm[metadataKey] = replacedText; + fm[metadataKey] = replacedText; }); // let keyboardEvent = new KeyboardEvent('keydown', { // keyCode: 13, code: 'KeyEnter', key: 'Enter' @@ -102,14 +102,19 @@ export default class TextFormat extends Plugin { return; } // @ts-ignore - const formatOnPasteCmdList = info.metadataEditor.properties.find(m => m.key === "tfFormatOnPaste")?.value; + let formatOnPasteCmdList = info.metadataEditor.properties.find(m => m.key === "tfFormatOnPaste")?.value; // console.log(formatOnPasteCmdList) - if (formatOnPasteCmdList === undefined || formatOnPasteCmdList?.length == 0) { return; } + if (formatOnPasteCmdList === undefined) { + if (this.settings.formatOnSaveSettings.enabled) { + formatOnPasteCmdList = this.settings.formatOnSaveSettings.commandsString.split("\n").map((c) => c.trim().replace(/^[ -]*/g, "")); + } else return; + } + if (formatOnPasteCmdList?.length == 0) return; + let clipboard = evt.clipboardData.getData('text/html') || evt.clipboardData.getData('text/plain'); if (!clipboard) { return; } evt?.preventDefault(); - // evt?.stopPropagation(); for (let cmd of formatOnPasteCmdList) { const formatText = (await this.formatSelection(clipboard, cmd)).editorChange.text; diff --git a/src/settings/settingTab.ts b/src/settings/settingTab.ts index c36955b..d281ac1 100644 --- a/src/settings/settingTab.ts +++ b/src/settings/settingTab.ts @@ -58,6 +58,26 @@ export class TextFormatSettingTab extends PluginSettingTab { this.makeCollapsible(headerEl, this.contentEl, true); + new Setting(this.contentEl) + .setName(getString(["setting", "format-on-paste", "name"])) + .setDesc(getString(["setting", "format-on-paste", "desc"])) + .addToggle((toggle) => { + toggle + .setValue(this.plugin.settings.formatOnSaveSettings.enabled) + .onChange(async (value) => { + this.plugin.settings.formatOnSaveSettings.enabled = value; + await this.plugin.saveSettings(); + }); + }) + .addTextArea((text) => + text + // .setPlaceholder(getString(["setting", "format-on-paste", "placeholder"])) + .setValue(this.plugin.settings.formatOnSaveSettings.commandsString) + .onChange(async (value) => { + this.plugin.settings.formatOnSaveSettings.commandsString = value; + await this.plugin.saveSettings(); + }) + ); new Setting(this.contentEl)