"use strict";var e=require("obsidian"); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function t(e,t,s,i){return new(s||(s=Promise))((function(n,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function d(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,d)}l((i=i.apply(e,t||[])).next())}))}function s(e,t,s){var i=void 0===t?null:t,n=function(e,t){var s=atob(e);if(t){for(var i=new Uint8Array(s.length),n=0,a=s.length;nthis.map.set(e.value(),e)))}has(e){return this.map.has(e.value())}add(e){return this.delete(e),this.map.set(e.value(),e)}addAll(e){e.forEach((e=>this.add(e)))}delete(e){this.map.delete(e.value())}values(){return Array.from(this.map.values())}valuesByLastAdd(){return Array.from(this.map.values()).reverse()}}class h{constructor(e,t,s=[]){this.id=e,this.text=t,this.tags=s}value(){return this.id}}class c{constructor(e,t,s,i){this.app=e,this.prevItems=t,this.recentAbovePinned=s.settings.recentAbovePinned,this.plugin=s,this.palette=i,this.allItems=[],this.pinnedItems=[],this.initialized=!1,this.hiddenIds=[],this.keymapHandlers=[]}getTitleText(){return this.titleText}getEmptyStateText(){return this.emptyStateText}getInstructions(){return[]}checkInitialized(){if(!this.initialized)throw new Error("This adapter has not been initialized")}initialize(){this.initialized=!0}mount(){}unmount(){this.keymapHandlers.forEach((e=>this.palette.scope.unregister(e))),this.keymapHandlers=[]}cleanQuery(e){return e}getPinnedItems(){return this.checkInitialized(),this.pinnedItems}getItems(){return this.checkInitialized(),this.allItems}getPrevItems(){return this.prevItems}getSortedItems(){const e=new l(this.getItems()),t=this.recentAbovePinned?this.getPrevItems().values():this.getPinnedItems();return[this.recentAbovePinned?this.getPinnedItems():this.getPrevItems().values(),t].forEach((t=>{t.forEach((t=>{e.has(t)&&e.add(t)}))})),e.valuesByLastAdd()}toggleHideId(e){return t(this,void 0,void 0,(function*(){this.hiddenIds.includes(e)?this.hiddenIds=this.hiddenIds.filter((t=>e!==t)):this.hiddenIds.push(e),this.plugin.settings[this.hiddenIdsSettingsKey]=this.hiddenIds,yield this.plugin.saveSettings(),yield this.plugin.loadSettings(),this.palette.updateSuggestions()}))}}class m{constructor(e,t,s,i=[],n=200){this.app=e,this.id=t,this.name=s,this.commandIds=i,this.delay=n}addCommand(e){this.commandIds.push(e)}removeCommand(e){this.commandIds=this.commandIds.filter((t=>t===e))}commandIsAvailable(e){const t=this.app.commands.findCommand(e);return!t.checkCallback||t.checkCallback(!0)}callAllCommands(){return t(this,void 0,void 0,(function*(){const t=new e.Notice(`Running "${this.name}"...`,1e4);for(let e=0;e{setTimeout(e,this.delay)}))}return t.hide(),new e.Notice(`Successfully ran "${this.name}"`),!0}))}checkCallback(e){return e?this.commandIsAvailable(this.commandIds[0]):(this.callAllCommands(),null)}}const r=new Set(["Alt","Ctrl","Mod","Shift"]),p={Mod:"Ctrl +",Ctrl:"Ctrl +",Meta:"Win +",Alt:"Alt +",Shift:"Shift +",Hyper:"Caps +"},u={Mod:"⌘",Ctrl:"^",Meta:"⌘",Alt:"⌥",Shift:"⇧",Hyper:"⇪"},g={TAB:"↹",ENTER:"↵",ARROWLEFT:"←",ARROWRIGHT:"→",ARROWUP:"↑",ARROWDOWN:"↓",BACKSPACE:"⌫",ESC:"Esc"};var y;function Z(t,s){let i=e.Platform.isMacOS?u:p;"mac"===s.hotkeyStyle?i=u:"windows"===s.hotkeyStyle&&(i=p);const n=[];var a;s.hyperKeyOverride&&(4===(a=t.modifiers).length&&a.every((e=>r.has(e))))?n.push(i.Hyper):t.modifiers.forEach((e=>{n.push(i[e])}));const o=t.key.toUpperCase();return n.push(g[o]||o),n.join(" ")}function b(e){return e.name}function S(t,s){const i=t.getCache(s);if(!i)return[];const n=(i.tags||[]).map((e=>e.tag)),a=e.parseFrontMatterTags(i.frontmatter)||[],o=n.concat(a),d=e.parseFrontMatterAliases(i.frontmatter)||[];return[new h(s,s,o),...d.map((e=>new h(`${e}:${s}`,e,o)))]}!function(e){e[e.Commands=0]="Commands",e[e.Files=1]="Files",e[e.Tags=2]="Tags"}(y||(y={}));class T extends e.FuzzySuggestModal{constructor(e,t){super(e),this.getItemText=b,this.callback=t}getItems(){return Object.values(this.app.commands.commands)}onChooseItem(e){this.callback(e)}}class W extends c{constructor(){super(...arguments),this.COMMAND_PLUGIN_NAME_SEPARATOR=": "}initialize(){super.initialize(),this.titleText="Better Command Palette: Commands",this.emptyStateText="No matching commands.",this.hiddenIds=this.plugin.settings.hiddenCommands,this.hiddenIdsSettingsKey="hiddenCommands",this.allItems=this.app.commands.listCommands().sort(((e,t)=>t.name.localeCompare(e.name))).map((e=>new h(e.id,e.name)));const e=this.app.internalPlugins.getPluginById("command-palette").instance.options.pinned||[];this.pinnedItems=e.reduce(((e,t)=>{const s=this.app.commands.findCommand(t);return s&&e.push(new h(t,s.name)),e}),[]).reverse()}mount(){this.keymapHandlers=[this.palette.scope.register(["Mod"],this.plugin.settings.fileSearchHotkey,(()=>this.palette.changeActionType(y.Files))),this.palette.scope.register(["Mod"],this.plugin.settings.tagSearchHotkey,(()=>this.palette.changeActionType(y.Tags)))]}getInstructions(){return[{command:Z({modifiers:[],key:"ENTER"},this.plugin.settings),purpose:"Run command"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.fileSearchHotkey},this.plugin.settings),purpose:"Search Files"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.tagSearchHotkey},this.plugin.settings),purpose:"Search Tags"}]}renderSuggestion(t,s,i){const n=this.app.commands.findCommand(t.id),a=this.app.hotkeyManager.getHotkeys(n.id),o=this.app.hotkeyManager.getDefaultHotkeys(n.id),d=a||o||[];if(this.getPinnedItems().find((e=>e.id===t.id))){const t=i.querySelector(".suggestion-flair");e.setIcon(t,"filled-pin",13),t.ariaLabel="Pinned",t.onClickEvent((()=>{}))}let{text:l}=t,h="";if(l.includes(this.COMMAND_PLUGIN_NAME_SEPARATOR)){const e=l.split(this.COMMAND_PLUGIN_NAME_SEPARATOR);h=e.shift(),l=e.join(this.COMMAND_PLUGIN_NAME_SEPARATOR)}s.createEl("span",{cls:"suggestion-title",text:l}),h&&this.plugin.settings.showPluginName&&s.createEl("span",{cls:"suggestion-note",text:h}),d.forEach((e=>{i.createEl("kbd",{cls:"suggestion-hotkey",text:Z(e,this.plugin.settings)})}))}onChooseSuggestion(e){return t(this,void 0,void 0,(function*(){this.getPrevItems().add(e),this.app.commands.executeCommandById(e.id)}))}}class v extends c{initialize(){super.initialize(),this.titleText="Better Command Palette: Files",this.emptyStateText="No matching files.",this.fileSearchPrefix=this.plugin.settings.fileSearchPrefix,this.hiddenIds=this.plugin.settings.hiddenFiles,this.hiddenIdsSettingsKey="hiddenFiles",this.allItems=[],this.unresolvedItems=new l,this.app.metadataCache.getCachedFiles().forEach((e=>{if(this.plugin.settings.fileTypeExclusion.some((t=>e.endsWith(`.${t}`))))return;const t=S(this.app.metadataCache,e);this.allItems=this.allItems.concat(t),Object.keys(this.app.metadataCache.unresolvedLinks[e]||{}).forEach((e=>this.unresolvedItems.add(new h(e,e))))})),this.allItems=this.allItems.concat(Array.from(this.unresolvedItems.values())).reverse(),[...this.app.workspace.getLastOpenFiles()].reverse().forEach((e=>{const t=S(this.app.metadataCache,e);t[0]&&this.prevItems.add(t[0])}))}mount(){this.keymapHandlers=[this.palette.scope.register(["Mod"],this.plugin.settings.commandSearchHotkey,(()=>this.palette.changeActionType(y.Commands))),this.palette.scope.register(["Mod"],this.plugin.settings.tagSearchHotkey,(()=>this.palette.changeActionType(y.Tags)))]}getInstructions(){const{openInNewTabMod:e,createNewFileMod:t}=this.plugin.settings;return[{command:Z({modifiers:[],key:"ENTER"},this.plugin.settings),purpose:"Open file"},{command:Z({modifiers:[e],key:"ENTER"},this.plugin.settings),purpose:"Open file in new pane"},{command:Z({modifiers:[t],key:"ENTER"},this.plugin.settings),purpose:"Create file"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.commandSearchHotkey},this.plugin.settings),purpose:"Search Commands"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.tagSearchHotkey},this.plugin.settings),purpose:"Search Tags"}]}cleanQuery(e){return e.replace(this.fileSearchPrefix,"")}renderSuggestion(t,s){let i=t.text;this.plugin.settings.displayOnlyNotesNames&&(i=t.text.split("/").pop()),this.plugin.settings.hideMdExtension&&i.endsWith(".md")&&(i=i.slice(0,-3));const n=s.createEl("div",{cls:"suggestion-title",text:i});if(this.unresolvedItems.has(t)&&n.addClass("unresolved"),t.id.includes(":")){n.createEl("span",{cls:"suggestion-name",text:t.text}).ariaLabel="Alias",e.setIcon(n,"right-arrow-with-tail");const[,s]=t.id.split(":");n.createEl("span",{cls:"suggestion-note",text:s})}s.createEl("div",{cls:"suggestion-note",text:`${t.tags.join(" ")}`})}onChooseSuggestion(s,i){return t(this,void 0,void 0,(function*(){let n=s&&s.id;if(s)n.includes(":")&&([,n]=n.split(":"));else{n=i.target.value.replace(this.fileSearchPrefix,"")}const a=yield function(s,i){return t(this,void 0,void 0,(function*(){let t=s.metadataCache.getFirstLinkpathDest(i,"");if(!t){const n=e.normalizePath(`${i}.md`),a=n.split("/").slice(0,-1).join("/");try{yield s.vault.createFolder(a)}catch(e){}t=yield s.vault.create(n,"")}return t}))}(this.app,n);a&&this.getPrevItems().add(s||new h(a.path,a.path)),function(e,t,s,i){const n="Shift"===t.openInNewTabMod?i.shiftKey:i.metaKey||i.ctrlKey;e.workspace.openLinkText(s.path,s.path,n)}(this.app,this.plugin.settings,a,i)}))}}class x extends c{initialize(){super.initialize(),this.hiddenIds=this.plugin.settings.hiddenTags,this.hiddenIdsSettingsKey="hiddenTags",this.tagSearchPrefix=this.plugin.settings.tagSearchPrefix,this.titleText="Better Command Palette: Tags",this.emptyStateText="No matching tags.",this.allItems=Object.entries(this.app.metadataCache.getTags()).map((([e,t])=>new h(e,e,[t])))}mount(){this.keymapHandlers=[this.palette.scope.register(["Mod"],this.plugin.settings.commandSearchHotkey,(()=>this.palette.changeActionType(y.Commands))),this.palette.scope.register(["Mod"],this.plugin.settings.fileSearchHotkey,(()=>this.palette.changeActionType(y.Files)))]}getInstructions(){return[{command:Z({modifiers:[],key:"ENTER"},this.plugin.settings),purpose:"See file usage"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.commandSearchHotkey},this.plugin.settings),purpose:"Search Commands"},{command:Z({modifiers:["Mod"],key:this.plugin.settings.fileSearchHotkey},this.plugin.settings),purpose:"Search Files"}]}cleanQuery(e){return e.replace(this.tagSearchPrefix,"")}renderSuggestion(e,t,s){t.createEl("span",{cls:"suggestion-content",text:e.text});const i=parseInt(e.tags[0],10);s.createEl("span",{cls:"suggestion-flair",text:`Found in ${i} file${1===i?"":"s"}`})}onChooseSuggestion(e){return t(this,void 0,void 0,(function*(){this.getPrevItems().add(e),this.palette.open(),this.palette.setQuery(`${this.plugin.settings.fileSearchPrefix}@${e.text}`,1)}))}}class P extends e.SuggestModal{constructor(e,t,s,i,n,a=""){super(e),this.toggleHiddenItems=()=>{this.showHiddenItems=!this.showHiddenItems,this.updateSuggestions()},this.fileSearchPrefix=i.settings.fileSearchPrefix,this.tagSearchPrefix=i.settings.tagSearchPrefix,this.suggestionLimit=i.settings.suggestionLimit,this.initialInputValue=a,this.plugin=i,this.modalEl.addClass("better-command-palette"),this.setPlaceholder("Select a command"),this.commandAdapter=new W(e,t,i,this),this.fileAdapter=new v(e,new l,i,this),this.tagAdapter=new x(e,s,i,this),this.suggestionsWorker=n,this.suggestionsWorker.onmessage=e=>this.receivedSuggestions(e),this.modalTitleEl=createEl("p",{cls:"better-command-palette-title"}),this.updateActionType(),this.modalEl.insertBefore(this.modalTitleEl,this.modalEl.firstChild),this.hiddenItemsHeaderEl=createEl("p","hidden-items-header"),this.showHiddenItems=!1,this.hiddenItemsHeaderEl.onClickEvent(this.toggleHiddenItems),this.modalEl.insertBefore(this.hiddenItemsHeaderEl,this.resultContainerEl),this.setScopes(i)}close(e){super.close(),e&&e.preventDefault()}setScopes(e){const t=t=>{const s=t.target;e.settings.closeWithBackspace&&""===s.value&&this.close(t)},{openInNewTabMod:s,createNewFileMod:i}=e.settings;this.scope.register([],"Backspace",(e=>{t(e)})),this.scope.register(["Mod"],"Backspace",(e=>{t(e)})),this.scope.register([i],"Enter",(e=>{this.actionType===y.Files&&(this.currentAdapter.onChooseSuggestion(null,e),this.close(e))})),this.scope.register([i,s],"Enter",(e=>{this.actionType===y.Files&&(this.currentAdapter.onChooseSuggestion(null,e),this.close(e))})),this.scope.register([s],"Enter",(e=>{if(this.actionType===y.Files&&this.currentSuggestions.length){const t=document.querySelector(".better-command-palette .prompt-results"),s=document.querySelector(".better-command-palette .is-selected"),i=Array.from(t.children).indexOf(s);this.currentAdapter.onChooseSuggestion(this.currentSuggestions[i],e),this.close(e)}})),this.scope.register(["Mod"],"I",this.toggleHiddenItems)}onOpen(){super.onOpen(),this.initialInputValue&&this.setQuery(this.initialInputValue)}changeActionType(e){let t="";e===y.Files?t=this.plugin.settings.fileSearchPrefix:e===y.Tags&&(t=this.plugin.settings.tagSearchPrefix);const s=this.inputEl.value,i=this.currentAdapter.cleanQuery(s);this.inputEl.value=t+i,this.updateSuggestions()}setQuery(e,t=-1){this.inputEl.value=e,t>-1&&this.inputEl.setSelectionRange(t,t),this.updateSuggestions()}updateActionType(){var e;const t=this.inputEl.value;let s,i;t.startsWith(this.fileSearchPrefix)?(i=y.Files,s=this.fileAdapter,this.modalEl.setAttribute("palette-mode","files")):t.startsWith(this.tagSearchPrefix)?(i=y.Tags,s=this.tagAdapter,this.modalEl.setAttribute("palette-mode","tags")):(i=y.Commands,s=this.commandAdapter,this.modalEl.setAttribute("palette-mode","commands")),i!==this.actionType&&(null===(e=this.currentAdapter)||void 0===e||e.unmount(),this.currentAdapter=s,this.currentAdapter.mount()),this.currentAdapter.initialized||this.currentAdapter.initialize();const n=i!==this.actionType;return this.actionType=i,n&&(this.updateEmptyStateText(),this.updateTitleText(),this.updateInstructions(),this.currentSuggestions=this.currentAdapter.getSortedItems().slice(0,this.suggestionLimit)),n}updateTitleText(){this.plugin.settings.showPluginName?this.modalTitleEl.setText(this.currentAdapter.getTitleText()):this.modalTitleEl.setText("")}updateEmptyStateText(){this.emptyStateText=this.currentAdapter.getEmptyStateText()}updateInstructions(){Array.from(this.modalEl.getElementsByClassName("prompt-instructions")).forEach((e=>{this.modalEl.removeChild(e)})),this.setInstructions([...this.currentAdapter.getInstructions(),{command:Z({modifiers:[],key:"ESC"},this.plugin.settings),purpose:"Close palette"},{command:Z({modifiers:["Mod"],key:"I"},this.plugin.settings),purpose:"Toggle Hidden Items"}])}getItems(){return this.currentAdapter.getSortedItems()}receivedSuggestions(e){const t=[];let s=0;for(let i=0;inew h(e.id,e.text,e.tags))),n=this.currentAdapter.getPrevItems();i.sort(((e,t)=>+n.has(t)-+n.has(e))),this.currentSuggestions=i,this.limit=this.currentSuggestions.length,this.updateSuggestions()}getSuggestionsAsync(e){const t=this.getItems();this.suggestionsWorker.postMessage({query:e,items:t})}getSuggestions(e){this.updateActionType();const t=e!==this.lastQuery;this.lastQuery=e;const s=this.currentAdapter.cleanQuery(e.trim());t&&this.getSuggestionsAsync(s);const i=this.currentSuggestions.filter((e=>!this.currentAdapter.hiddenIds.includes(e.id))),n=this.currentSuggestions.length-i.length;return this.updateHiddenItemCountHeader(n),this.showHiddenItems?this.currentSuggestions:i}updateHiddenItemCountHeader(e){if(this.hiddenItemsHeaderEl.empty(),0!==e){const t=`${this.showHiddenItems?"Hide":"Show"} hidden items (${e})`;this.hiddenItemsHeaderEl.setText(t)}}renderSuggestion(t,s){s.addClass("mod-complex");const i=this.currentAdapter.hiddenIds.includes(t.id);i&&s.addClass("hidden");const n=s.createEl("span","suggestion-content"),a=s.createEl("span","suggestion-aux"),o=a.createEl("span","suggestion-flair");!function(e,t,s,i){i.has(t)&&(s.addClass("recent"),s.createEl("span",{cls:"suggestion-note",text:e.recentlyUsedText}))}(this.plugin.settings,t,n,this.currentAdapter.getPrevItems()),e.setIcon(o,"cross",13),o.ariaLabel=i?"Click to Unhide":"Click to Hide",o.setAttr("data-id",t.id),o.onClickEvent((e=>{e.preventDefault(),e.stopPropagation();const t=e.target;this.currentAdapter.toggleHideId(t.getAttr("data-id"))})),this.currentAdapter.renderSuggestion(t,n,a)}onChooseSuggestion(e,s){return t(this,void 0,void 0,(function*(){this.currentAdapter.onChooseSuggestion(e,s)}))}}const f={closeWithBackspace:!0,showPluginName:!0,fileSearchPrefix:"/",tagSearchPrefix:"#",commandSearchHotkey:"p",fileSearchHotkey:"o",tagSearchHotkey:"t",suggestionLimit:50,recentAbovePinned:!1,hyperKeyOverride:!1,displayOnlyNotesNames:!1,hideMdExtension:!1,recentlyUsedText:"(recently used)",macros:[],hotkeyStyle:"auto",createNewFileMod:"Mod",openInNewTabMod:"Shift",hiddenCommands:[],hiddenFiles:[],hiddenTags:[],fileTypeExclusion:[]};class I extends e.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){this.containerEl.empty(),this.displayBasicSettings(),this.displayMacroSettings()}displayBasicSettings(){const{containerEl:s}=this,{settings:i}=this.plugin;s.empty(),s.createEl("h2",{text:"Better Command Palette Settings"}),new e.Setting(s).setName("Close on Backspace").setDesc("Close the palette when there is no text and backspace is pressed").addToggle((e=>e.setValue(i.closeWithBackspace).onChange((e=>t(this,void 0,void 0,(function*(){i.closeWithBackspace=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Show Plugin Name").setDesc("Show the plugin name in the command palette").addToggle((e=>e.setValue(i.showPluginName).onChange((e=>t(this,void 0,void 0,(function*(){i.showPluginName=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Recent above Pinned").setDesc("Sorts the suggestion so that the recently used items show before pinned items.").addToggle((e=>e.setValue(i.recentAbovePinned).onChange((e=>t(this,void 0,void 0,(function*(){i.recentAbovePinned=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Caps Lock Hyper Key Hotkey Override").setDesc('For those users who have use a "Hyper Key", enabling this maps the icons "⌥ ^ ⌘ ⇧" to the caps lock icon "⇪" ').addToggle((e=>e.setValue(i.hyperKeyOverride).onChange((e=>t(this,void 0,void 0,(function*(){i.hyperKeyOverride=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Use shift to create files and cmd/CTRL to open in new tab").setDesc("By default cmd/ctrl is used to create files and shift is used to open in new tab. This setting reverses that to mimic the behavior of the standard quick switcher.").addToggle((e=>e.setValue("Shift"===i.createNewFileMod).onChange((e=>t(this,void 0,void 0,(function*(){i.createNewFileMod=e?"Shift":"Mod",i.openInNewTabMod=e?"Mod":"Shift",yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Display only notes' names").setDesc("If enabled, only notes names will be displayed in Quick Switcher mode instead of their full path.").addToggle((e=>e.setValue(i.displayOnlyNotesNames).onChange((e=>t(this,void 0,void 0,(function*(){i.displayOnlyNotesNames=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Hide .md extensions").setDesc("If enabled, Markdown notes will be displayed without their .md extension in Quick Switcher mode").addToggle((e=>e.setValue(i.hideMdExtension).onChange((e=>t(this,void 0,void 0,(function*(){i.hideMdExtension=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Recently used text").setDesc("This text will be displayed next to recently used items").addText((e=>e.setValue(i.recentlyUsedText).onChange((e=>t(this,void 0,void 0,(function*(){i.recentlyUsedText=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("File Type Exclusions").setDesc('A comma separated list of file extensions (ex: "pdf,jpg,png") that should not be shown when searching files.').addText((e=>e.setValue(i.fileTypeExclusion.join(",")).onChange((e=>t(this,void 0,void 0,(function*(){const t=e.split(",").map((e=>e.trim()));i.fileTypeExclusion=t,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("File Search Prefix").setDesc("The prefix used to tell the palette you want to search files").addText((e=>e.setValue(i.fileSearchPrefix).onChange((e=>t(this,void 0,void 0,(function*(){i.fileSearchPrefix=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Tag Search Prefix").setDesc("The prefix used to tell the palette you want to search tags").addText((e=>e.setValue(i.tagSearchPrefix).onChange((e=>t(this,void 0,void 0,(function*(){i.tagSearchPrefix=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Command Search Hotkey").setDesc("The hotkey used to switch to command search while using the command palette.").addText((e=>e.setValue(i.commandSearchHotkey).onChange((e=>t(this,void 0,void 0,(function*(){i.commandSearchHotkey=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("File Search Hotkey").setDesc("The hotkey used to switch to file search while using the command palette.").addText((e=>e.setValue(i.fileSearchHotkey).onChange((e=>t(this,void 0,void 0,(function*(){i.fileSearchHotkey=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Tag Search Hotkey").setDesc("The hotkey used to switch to tag search while using the command palette.").addText((e=>e.setValue(i.tagSearchHotkey).onChange((e=>t(this,void 0,void 0,(function*(){i.tagSearchHotkey=e,yield this.plugin.saveSettings()}))))));const n={10:"10",20:"20",50:"50",100:"100",200:"200",500:"500",1e3:"1000"};new e.Setting(s).setName("Suggestion Limit").setDesc("The number of items that will be in the suggestion list of the palette. Really high numbers can affect performance").addDropdown((e=>e.addOptions(n).setValue(i.suggestionLimit.toString()).onChange((e=>t(this,void 0,void 0,(function*(){i.suggestionLimit=parseInt(e,10),yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Hotkey Modifier Style").setDesc("Allows autodetecting of hotkey modifier or forcing to Mac or Windows").addDropdown((e=>e.addOptions({auto:"Auto Detect",mac:"Force Mac Hotkeys",windows:"Force Windows Hotkeys"}).setValue(i.hotkeyStyle).onChange((e=>t(this,void 0,void 0,(function*(){i.hotkeyStyle=e,yield this.plugin.saveSettings()})))))),new e.Setting(s).setName("Add new macro").setDesc("Create a new grouping of commands that can be run together").addButton((e=>e.setButtonText("+").onClick((()=>t(this,void 0,void 0,(function*(){i.macros.push({name:`Macro ${i.macros.length+1}`,commandIds:[],delay:200}),yield this.plugin.saveSettings(),this.display()}))))))}displayMacroSettings(){const{containerEl:s}=this,{settings:i}=this.plugin;i.macros.forEach(((n,a)=>{const o=new e.Setting(s).setClass("macro-setting").setName(`Macro #${a+1}`).addButton((e=>e.setButtonText("Delete Macro").onClick((()=>t(this,void 0,void 0,(function*(){i.macros.splice(a,1),yield this.plugin.saveSettings(),this.display()})))))),d=o.settingEl.createEl("div","macro-main-settings");d.createEl("label",{text:"Macro Name"}),d.createEl("input",{cls:"name-input",type:"text",value:n.name}).on("change",".name-input",(e=>t(this,void 0,void 0,(function*(){const t=e.target;i.macros[a]=Object.assign(Object.assign({},n),{name:t.value}),yield this.plugin.saveSettings()})))),d.createEl("label",{text:"Delay (ms)"}),d.createEl("input",{cls:"delay-input",type:"number",value:n.delay.toString()}).on("change",".delay-input",(e=>t(this,void 0,void 0,(function*(){const t=e.target.value;i.macros[a].delay=parseInt(t,10),yield this.plugin.saveSettings()})))),d.createEl("label",{text:"Add a new Command to the macro"}),d.createEl("button",{text:"Add Command"}).onClickEvent((()=>t(this,void 0,void 0,(function*(){new T(this.app,(e=>t(this,void 0,void 0,(function*(){i.macros[a].commandIds.push(e.id),yield this.plugin.saveSettings(),this.display()})))).open()})))),n.commandIds.forEach(((s,n)=>{const d=this.app.commands.findCommand(s),l=o.settingEl.createEl("div","macro-command"),h=l.createEl("button",`delete-command-${n}`);l.createEl("p",{text:`${n+1}: ${d.name}`,cls:"command"}),e.setIcon(h,"trash"),h.onClickEvent((()=>t(this,void 0,void 0,(function*(){i.macros[a].commandIds.splice(n,1),yield this.plugin.saveSettings(),this.display()}))))}))}))}}class X extends e.Plugin{onload(){return t(this,void 0,void 0,(function*(){console.log("Loading plugin: Better Command Palette"),yield this.loadSettings(),this.prevCommands=new l,this.prevTags=new l,this.suggestionsWorker=new d({}),this.addCommand({id:"open-better-commmand-palette",name:"Open better command palette",hotkeys:[{modifiers:["Mod","Shift"],key:"p"}],callback:()=>{new P(this.app,this.prevCommands,this.prevTags,this,this.suggestionsWorker).open()}}),this.addCommand({id:"open-better-commmand-palette-file-search",name:"Open better command palette: File Search",hotkeys:[],callback:()=>{new P(this.app,this.prevCommands,this.prevTags,this,this.suggestionsWorker,this.settings.fileSearchPrefix).open()}}),this.addCommand({id:"open-better-commmand-palette-tag-search",name:"Open better command palette: Tag Search",hotkeys:[],callback:()=>{new P(this.app,this.prevCommands,this.prevTags,this,this.suggestionsWorker,this.settings.tagSearchPrefix).open()}}),this.addSettingTab(new I(this.app,this))}))}onunload(){this.suggestionsWorker.terminate()}loadMacroCommands(){this.settings.macros.forEach(((e,t)=>{if(!e.name||!e.commandIds.length)return;const s=new m(this.app,`obsidian-better-command-palette-macro-${t}`,e.name,e.commandIds,e.delay);this.addCommand(s),this.prevCommands&&(this.prevCommands=this.prevCommands.values().reduce(((e,t)=>(t.id===s.id&&t.text!==s.name||e.add(t),e)),new l))}))}deleteMacroCommands(){Object.keys(this.app.commands.commands).filter((e=>e.includes("obsidian-better-command-palette-macro-"))).forEach((e=>{this.app.commands.removeCommand(e)}))}loadSettings(){return t(this,void 0,void 0,(function*(){this.settings=Object.assign(Object.assign({},f),yield this.loadData()),this.loadMacroCommands()}))}saveSettings(){return t(this,void 0,void 0,(function*(){this.deleteMacroCommands(),yield this.saveData(this.settings),this.loadMacroCommands()}))}}module.exports=X;