17 lines
8.3 KiB
JavaScript
Executable File
17 lines
8.3 KiB
JavaScript
Executable File
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
"use strict";var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var E=(a,o,e)=>o in a?u(a,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[o]=e;var O=(a,o)=>{for(var e in o)u(a,e,{get:o[e],enumerable:!0})},A=(a,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of D(o))!F.call(a,i)&&i!==e&&u(a,i,{get:()=>o[i],enumerable:!(s=k(o,i))||s.enumerable});return a};var U=a=>A(u({},"__esModule",{value:!0}),a);var r=(a,o,e)=>E(a,typeof o!="symbol"?o+"":o,e);var y={};O(y,{default:()=>b});module.exports=U(y);var d=require("obsidian");var l=require("obsidian");var n={ribbonIcon:!0,ribbonCommandUsesCode:!0,showFileContextMenuItem:!0,executeTemplate:'code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}"',urlProtocol:"vscode",openFile:!0,workspacePath:"{{vaultpath}}"},m=class extends l.PluginSettingTab{constructor(e,s){super(e,s);r(this,"plugin");this.plugin=s}display(){let{containerEl:e}=this;e.empty(),e.createEl("h3",{text:"General settings"}),new l.Setting(e).setName("Display Ribbon Icon").setDesc("Toggle this OFF if you want to hide the Ribbon Icon.").addToggle(i=>i.setValue(this.plugin.settings.ribbonIcon).onChange(t=>{this.plugin.settings.ribbonIcon=t,this.plugin.saveSettings(),this.plugin.refreshIconRibbon()})),new l.Setting(e).setName("Ribbon opens via 'code' command").setDesc("Toggle this OFF if you'd prefer that the Ribbon Icon opens VSCode via URL.").addToggle(i=>i.setValue(this.plugin.settings.ribbonCommandUsesCode).onChange(t=>{this.plugin.settings.ribbonCommandUsesCode=t,this.plugin.saveSettings()})),new l.Setting(e).setName('Display "Open in VS Code" option for files/folders').setDesc('Toggle this OFF to hide the "Open in VS Code" option when right-clicking a file/folder.').addToggle(i=>i.setValue(this.plugin.settings.showFileContextMenuItem).onChange(t=>{this.plugin.settings.showFileContextMenuItem=t,this.plugin.saveSettings()})),e.createEl("h3",{text:"Open via 'code' CLI settings"}),new l.Setting(e).setName("Template for executing the 'code' command").setDesc(`You can use the following variables: '{{vaultpath}}' (absolute), '{{filepath}}' (relative), '{{folderpath}}' (relative), '{{line}}' and '{{ch}}'. Note that on MacOS, a full path to the VSCode executable is required (generally '/usr/local/bin/code'). Example template: "'/usr/local/bin/code' '{{vaultpath}}' '{{vaultpath}}/{{filepath}}'"`).addText(i=>i.setPlaceholder(n.executeTemplate).setValue(this.plugin.settings.executeTemplate||n.executeTemplate).onChange(t=>{t=t.trim(),t===""&&(t=n.executeTemplate),this.plugin.settings.executeTemplate=t,this.plugin.saveData(this.plugin.settings)})),e.createEl("h3",{text:"Open via 'vscode://' URL settings"}),e.createEl("p",{text:"See: "}).appendChild(createEl("a",{text:"Opening VS Code with URLs",href:"https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls"})),new l.Setting(e).setName("Open current file").setDesc("Open the current file rather than the root of the vault.").addToggle(i=>i.setValue(this.plugin.settings.openFile||n.openFile).onChange(t=>{this.plugin.settings.openFile=t,this.plugin.saveData(this.plugin.settings)})),new l.Setting(e).setName("Path to VSCode Workspace").setDesc('Defaults to the {{vaultpath}} template variable. You can set this to an absolute path to a ".code-workspace" file if you prefer to use a ').addText(i=>i.setPlaceholder(n.workspacePath).setValue(this.plugin.settings.workspacePath||n.workspacePath).onChange(t=>{t=t.trim(),t===""&&(t=n.workspacePath),this.plugin.settings.workspacePath=t,this.plugin.saveData(this.plugin.settings)})).descEl.appendChild(createEl("a",{text:"multi-root workspace",href:"https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces"})).appendText("."),new l.Setting(e).setName("URL protocol").setDesc("You can override the default vscode:// to VSCode Insiders, VSCodium or other VSCode variants' protocol string").addText(i=>i.setPlaceholder(n.urlProtocol).setValue(this.plugin.settings.urlProtocol||n.urlProtocol).onChange(t=>{t=t.trim(),t===""&&(t=n.urlProtocol),this.plugin.settings.urlProtocol=t,this.plugin.saveData(this.plugin.settings)}))}};var V=require("child_process");var p=class p extends d.Plugin{constructor(){super(...arguments);r(this,"DEV",!1);r(this,"ribbonIcon");r(this,"settings");r(this,"logTag",`[${this.manifest.id}]`)}async onload(){var s;console.log("Loading "+this.manifest.name+" plugin"),(0,d.addIcon)(p.iconId,p.iconSvgContent),await this.loadSettings(),this.refreshIconRibbon(),this.addSettingTab(new m(this.app,this)),this.addCommand({id:"open-vscode",name:"Open as Visual Studio Code workspace",callback:this.openVSCode.bind(this)}),this.addCommand({id:"open-vscode-via-url",name:"Open as Visual Studio Code workspace using a vscode:// URL",callback:this.openVSCodeUrl.bind(this)}),this.registerEvent(this.app.workspace.on("file-menu",this.fileMenuHandler.bind(this)));let e=this.app.plugins.getPlugin("hot-reload");this.DEV=(s=e==null?void 0:e.enabledPlugins.has(this.manifest.id))!=null?s:!1,this.DEV&&(this.addCommand({id:"open-vscode-reload",name:"Reload the plugin in dev",callback:this.reload.bind(this)}),this.addCommand({id:"open-vscode-reset-settings",name:"Reset plugins settings to default in dev",callback:this.resetSettings.bind(this)}))}openVSCode(e=this.app.workspace.getActiveFile()){var v,f,C,w,S,P;if(!(this.app.vault.adapter instanceof d.FileSystemAdapter))return;let{executeTemplate:s}=this.settings,i=this.app.vault.adapter.getBasePath(),t=(v=e==null?void 0:e.path)!=null?v:"",c=(C=(f=e==null?void 0:e.parent)==null?void 0:f.path)!=null?C:"",h=(w=this.app.workspace.getActiveViewOfType(d.MarkdownView))==null?void 0:w.editor.getCursor(),x=((S=h==null?void 0:h.line)!=null?S:0)+1,I=((P=h==null?void 0:h.ch)!=null?P:0)+1,g=s.trim()===""?n.executeTemplate:s;g=g.replaceAll("{{vaultpath}}",i).replaceAll("{{filepath}}",t).replaceAll("{{folderpath}}",c).replaceAll("{{line}}",x.toString()).replaceAll("{{ch}}",I.toString()),this.DEV&&console.log(this.logTag,{command:g}),(0,V.exec)(g,T=>{T&&console.error(`${this.logTag} exec error: ${T.message}`)})}openVSCodeUrl(){var c;if(!(this.app.vault.adapter instanceof d.FileSystemAdapter))return;let e=this.app.vault.adapter.getBasePath(),s=this.app.workspace.getActiveFile(),i=(c=s==null?void 0:s.path)!=null?c:"";this.DEV&&console.log(this.logTag,{settings:this.settings,path:e,filePath:i});let t=`${this.settings.urlProtocol}://file/${e}`;if(this.settings.openFile){t+=`/${i}`;let h=this.settings.workspacePath.replaceAll("{{vaultpath}}",e);window.open(`${this.settings.urlProtocol}://file/${h}`),setTimeout(()=>{this.DEV&&console.log(this.logTag,{url:t}),window.open(t)},200)}else this.DEV&&console.log(this.logTag,{url:t}),window.open(t)}async loadSettings(){let e=await this.loadData(),s=!1;e!=null&&e.useUrlInsiders&&(e.urlProtocol="vscode-insiders",delete e.useUrlInsiders,s=!0),this.settings=Object.assign({},n,e),s&&await this.saveData(this.settings)}async saveSettings(e=this.settings){await this.saveData(e)}refreshIconRibbon(){var e;(e=this.ribbonIcon)==null||e.remove(),this.settings.ribbonIcon&&(this.ribbonIcon=this.addRibbonIcon(p.iconId,"VSCode",()=>{this.settings.ribbonCommandUsesCode?this.openVSCode():this.openVSCodeUrl()}))}fileMenuHandler(e,s){this.settings.showFileContextMenuItem&&e.addItem(i=>{i.setTitle("Open in VS Code").setIcon(p.iconId).onClick(()=>{this.openVSCode(s)})})}async reload(){let e=this.manifest.id,s=this.app.plugins;await s.disablePlugin(e),await s.enablePlugin(e),console.log(`${this.logTag} reloaded`,this)}async resetSettings(){console.log(this.logTag,{old:this.settings,default:n}),this.settings=n,await this.saveData(this.settings)}};r(p,"iconId","vscode-logo"),r(p,"iconSvgContent",`
|
|
<svg role="img" viewBox="0 0 24 24"
|
|
xmlns="http://www.w3.org/2000/svg">
|
|
<title>Visual Studio Code</title>
|
|
<path
|
|
fill="currentColor"
|
|
d="M23.15 2.587L18.21.21a1.494 1.494 0 0 0-1.705.29l-9.46 8.63-4.12-3.128a.999.999 0 0 0-1.276.057L.327 7.261A1 1 0 0 0 .326 8.74L3.899 12 .326 15.26a1 1 0 0 0 .001 1.479L1.65 17.94a.999.999 0 0 0 1.276.057l4.12-3.128 9.46 8.63a1.492 1.492 0 0 0 1.704.29l4.942-2.377A1.5 1.5 0 0 0 24 20.06V3.939a1.5 1.5 0 0 0-.85-1.352zm-5.146 14.861L10.826 12l7.178-5.448v10.896z"
|
|
/>
|
|
</svg>
|
|
`);var b=p;
|
|
|
|
/* nosourcemap */ |