Skip to content

[Obsidian] Search note activated by hotkey not working  #3286

Closed

Description

@simpzan

Extension – Obsidian

Author: @marcjulianschwarz

Description

Activate Search Note with hotkey is not working. The dialog for Search Note shows error.

Error:

TypeError: Cannot read properties of undefined (reading 'searchArgument')

Si:searchNoteCommand.js:142:5894

---
139: `+n),(0,O.showToast)({title:"Added selected text to note",style:O.Toast.Style.Success}),!0}}catch{(0,O.showToast)({title:"Couldn't copy selected text",message:"Maybe you didn't select anything.",style:O.Toast.Style.Failure})}}var ws=s=>"obsidian://open?path="+encodeURIComponent(s);function hi(s,e,t,n){let i=z.default.readdirSync(s);n=n||[];for(let r of i)z.default.statSync(s+"/"+r).isDirectory()&&!r.includes(".obsidian")?n=hi(s+"/"+r,e,t,n):xd(r,t)&&r!==".md"&&!r.includes(".excalidraw")&&!s.includes(".obsidian")&&$d(s,e)&&n.push(La.default.join(s,"/",r));return n}function $d(s,e){for(let t of e)if(s.includes(t))return!1;return!0}function xd(s,e){for(let t of e)if(s.endsWith(t))return!0;return!1}function Aa(){let e=(0,O.getPreferenceValues)().excludedFolders;if(e){let t=e.split(",");for(let n=0;n<t.length;n++)t[n]=t[n].trim();return t}else return[]}var Be=require("@raycast/api"),Z=V(require("react")),el=V(require("fs"));var As=require("@raycast/api");var D=require("@raycast/api"),Fe=V(require("react")),ja=V(require("fs"));var I=require("react/jsx-runtime");function Ka(s){let{note:e,vault:t,pref:n,onDelete:i,action:r}=s,[o,a]=(0,Fe.useState)(e.content),[l,c]=(0,Fe.useState)(ne(e,t)),d=!ja.default.existsSync(e.path);d&&Ta(t);function f(){let m=ie(e.path);e.content=m,a(m)}function u(){let m=bs([e]);e.tags=m}function p(m){switch(+m){case 0:c(!l);break;case 2:i&&i(e,t),Ea(t,e);break;case 1:f(),u(),mi(t,e);break;case 3:f(),u(),mi(t,e)}}function g(){return e.tags.length>0?(0,I.jsx)(D.List.Item.Detail.Metadata.TagList,{title:"Tags",children:e.tags.map(m=>(0,I.jsx)(D.List.Item.Detail.Metadata.TagList.Item,{text:m},m))}):null}function h(){let m=Na(e.content,"url");return m?(0,I.jsx)(D.List.Item.Detail.Metadata.Link,{target:m,text:"View",title:"URL"}):null}return d?null:(0,I.jsx)(D.List.Item,{title:e.title,accessories:[{text:l?"\u2B50\uFE0F":""}],detail:(0,I.jsx)(D.List.Item.Detail,{markdown:Nt(o),metadata:n.showMetadata?(0,I.jsxs)(D.List.Item.Detail.Metadata,{children:[(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Character Count",text:o.length.toString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Word Count",text:yi(o).toString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Reading Time",text:$a(o).toString()+" min read"}),(0,I.jsx)(g,{}),(0,I.jsx)(h,{}),(0,I.jsx)(D.List.Item.Detail.Metadata.Separator,{}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Creation Date",text:xa(e).toLocaleDateString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"File Size",text:Ba(e).toFixed(2)+" KB"}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Note Path",text:Va(e.path.split(t.path)[1],55)})]}):(0,I.jsx)(Fe.default.Fragment,{})}),actions:(0,I.jsx)(D.ActionPanel,{children:(0,I.jsx)(Fe.default.Fragment,{children:r&&r(e,t,p)})})})}var $e=require("@raycast/api"),Ua=V(require("react")),fe=require("react/jsx-runtime");function Ya(s){let{setNotes:e,allNotes:t,tags:n,searchArguments:i}=s;function r(){if(i&&i.tagArgument!="")return i.tagArgument.startsWith("#")?i.tagArgument:"#"+i.tagArgument}function o(f){e&&t&&(f!="all"?e&&e(t.filter(u=>u.tags.includes(f))):e&&e(t))}function a(){return(0,fe.jsxs)(Ua.default.Fragment,{children:[(0,fe.jsx)($e.List.Dropdown.Item,{title:"All",value:"all"}),(0,fe.jsx)($e.List.Dropdown.Section,{title:"Tags"}),n.map(f=>(0,fe.jsx)($e.List.Dropdown.Item,{title:f,value:f},f))]})}function l(){return(0,fe.jsx)($e.List.Dropdown,{tooltip:"Search For",defaultValue:r()??"",onChange:o,children:a()})}function c(){return(0,fe.jsx)($e.List.Dropdown,{tooltip:"Search For",onChange:o,children:a()})}function d(){return r()?l():c()}return(0,fe.jsx)(d,{})}var bi=require("react/jsx-runtime");function ks(s){let{notes:e,allNotes:t,vault:n,isLoading:i,title:r,searchArguments:o,setNotes:a,action:l,onDelete:c,onSearchChange:d}=s,f=(0,As.getPreferenceValues)(),{showDetail:u}=f,p=bs(t??[]),g=e===void 0;return e!==void 0&&(g=e.length==0),i!==void 0&&(g=i),(0,bi.jsx)(As.List,{isLoading:g,isShowingDetail:u,onSearchTextChange:d,navigationTitle:r,searchText:o?o.searchArgument:"",searchBarAccessory:(0,bi.jsx)(Ya,{tags:p,setNotes:a,allNotes:t,searchArguments:o}),children:e?.map(h=>(0,bi.jsx)(Ka,{note:h,vault:n,pref:f,onDelete:c,action:l},h.path))})}function Ja(s,e,t){return e.length===0?s:(e=e.toLowerCase(),t?s.filter(n=>n.content.toLowerCase().includes(e)||n.title.toLowerCase().includes(e)||n.path.toLowerCase().includes(e)):s.filter(n=>n.title.toLowerCase().includes(e)))}var A=require("@raycast/api"),K=V(require("react"));var F=require("@raycast/api"),Ga=V(require("fs"));var Cs=require("react/jsx-runtime");function Wa(s){let{note:e,actionCallback:t}=s,{pop:n}=(0,F.useNavigation)(),{appendTemplate:i}=(0,F.getPreferenceValues)();async function r(o){let a=await wt(o.content);Ga.default.appendFileSync(e.path,`
140: `+a),(0,F.showToast)({title:"Added text to note",style:F.Toast.Style.Success}),n(),t(3)}return(0,Cs.jsx)(F.Form,{navigationTitle:"Add text to: "+e.title,actions:(0,Cs.jsx)(F.ActionPanel,{children:(0,Cs.jsx)(F.Action.SubmitForm,{title:"Submit",onSubmit:r})}),children:(0,Cs.jsx)(F.Form.TextArea,{title:`Add text to:
141: `+e.title,id:"content",placeholder:"Text",defaultValue:i})})}var M=require("@raycast/api"),Qa=V(require("fs")),Xa=require("react");var Ts=require("react/jsx-runtime");function Ha(s){let{note:e,actionCallback:t}=s,{pop:n}=(0,M.useNavigation)(),[i]=(0,Xa.useState)(ie(e.path,!1));async function r(o){let a=o.content;a=await wt(a);let l={title:"Override note",message:'Are you sure you want to override the note: "'+e.title+'"?',icon:M.Icon.ExclamationMark};await(0,M.confirmAlert)(l)&&(Qa.default.writeFileSync(e.path,a),(0,M.showToast)({title:"Edited note",style:M.Toast.Style.Success}),t(1),n())}return(0,Ts.jsx)(M.Form,{navigationTitle:"Edit: "+e.title,actions:(0,Ts.jsx)(M.ActionPanel,{children:(0,Ts.jsx)(M.Action.SubmitForm,{title:"Submit",onSubmit:r})}),children:(0,Ts.jsx)(M.Form.TextArea,{title:`Edit:
142: `+e.title,id:"content",placeholder:"Text",enableMarkdown:!0,defaultValue:i})})}var xe=require("@raycast/api"),At=require("react");var vt=require("react/jsx-runtime");function za(s){let{note:e,showTitle:t,vault:n,actionCallback:i}=s,{pop:r}=(0,xe.useNavigation)(),o=e?.content;o=Nt(o??"");let[a,l]=(0,At.useState)(e?ne(e,n):!1),[c,d]=(0,At.useState)(o);function f(){if(e){let p=ie(e.path);e.content=p,d(p)}}(0,At.useEffect)(f,[e]);function u(p,g=void 0){switch(i&&i(p),+p){case 0:l(!a);break;case 2:r();break;case 1:f();break;case 3:f()}}return(0,vt.jsx)(xe.Detail,{isLoading:e===void 0,navigationTitle:t?a?"\u2B50 "+e?.title:e?.title:"",markdown:c,actions:e?(0,vt.jsxs)(xe.ActionPanel,{children:[(0,vt.jsx)(Ct,{note:e,vault:n,actionCallback:u}),(0,vt.jsx)(kt,{note:e,vault:n,actionCallback:u})]}):null})}var w=require("react/jsx-runtime");function Bd(s){let{path:e}=s;return(0,w.jsx)(A.Action.ShowInFinder,{title:"Show in Finder",icon:A.Icon.Finder,path:e,shortcut:{modifiers:["opt"],key:"enter"}})}function Vd(s){let{note:e,vault:t,actionCallback:n}=s;return(0,w.jsx)(A.Action.Push,{title:"Edit Note",target:(0,w.jsx)(Ha,{note:e,vault:t,actionCallback:n}),shortcut:{modifiers:["opt"],key:"e"},icon:A.Icon.Pencil})}function Rd(s){let{note:e,actionCallback:t}=s;return(0,w.jsx)(A.Action.Push,{title:"Append to Note",target:(0,w.jsx)(Wa,{note:e,actionCallback:t}),shortcut:{modifiers:["opt"],key:"a"},icon:A.Icon.Pencil})}function jd(s){let{note:e,actionCallback:t}=s;return(0,w.jsx)(A.Action,{title:"Append Selected Text to Note",shortcut:{modifiers:["opt"],key:"s"},onAction:async()=>{await Ra(e)&&t(3)},icon:A.Icon.Pencil})}function Kd(s){let{note:e}=s;return(0,w.jsx)(A.Action.CopyToClipboard,{title:"Copy Note Content",content:e.content,shortcut:{modifiers:["opt"],key:"c"}})}function Ud(s){let{note:e}=s;return(0,w.jsx)(A.Action.Paste,{title:"Paste Note Content",content:e.content,shortcut:{modifiers:["opt"],key:"v"}})}function Yd(s){let{note:e}=s;return(0,w.jsx)(A.Action.CopyToClipboard,{title:"Copy Markdown Link",icon:A.Icon.Link,content:`[${e.title}](${ws(e.path)})`,shortcut:{modifiers:["opt"],key:"l"}})}function Jd(s){let{note:e}=s;return(0,w.jsx)(A.Action.CopyToClipboard,{title:"Copy Obsidian URI",icon:A.Icon.Link,content:ws(e.path),shortcut:{modifiers:["opt"],key:"u"}})}function Gd(s){let{note:e,vault:t,actionCallback:n}=s,[i,r]=(0,K.useState)(ne(e,t));return(0,w.jsx)(A.Action,{title:i?"Unpin Note":"Pin Note",shortcut:{modifiers:["opt"],key:"p"},onAction:()=>{i?(Ss(e,t),r(!i),n(0)):(va(e,t),r(!i),n(0))},icon:i?A.Icon.XMarkCircle:A.Icon.Pin})}function Wd(s){let{note:e,vault:t,actionCallback:n}=s;return(0,w.jsx)(A.Action,{title:"Delete Note",shortcut:{modifiers:["opt"],key:"d"},onAction:async()=>{await Fa(e,t)&&n(2)},icon:{source:A.Icon.Trash,tintColor:A.Color.Red}})}function Qd(s){let{note:e,vault:t,actionCallback:n}=s;return(0,w.jsx)(A.Action.Push,{title:"Quick Look",target:(0,w.jsx)(za,{note:e,vault:t,showTitle:!0,actionCallback:n}),icon:A.Icon.Eye})}function Xd(s){let{path:e}=s;return(0,w.jsx)(A.Action.Open,{title:"Open in Obsidian",target:ws(e),icon:Is})}function Hd(s){let{note:e,vault:t}=s;return(0,w.jsx)(A.Action.Open,{title:"Open in new Pane",target:"obsidian://advanced-uri?vault="+encodeURIComponent(t.name)+"&filepath="+encodeURIComponent(e.path.replace(t.path,""))+"&newpane=true",icon:Is})}function Za(s){let{vault:e}=s;return(0,w.jsx)(A.Action.ShowInFinder,{title:"Show in Finder",icon:A.Icon.Finder,path:e.path})}function zd(s){let{vault:e,str:t}=s,n=_e(e).filter(r=>r.content.includes(t)),i=n.length;if(i>0){let r=(0,w.jsx)(ks,{vault:e,notes:n,title:`${i} notes mentioning "${t}"`,action:(o,a,l)=>(0,w.jsxs)(K.default.Fragment,{children:[(0,w.jsx)(Ct,{note:o,vault:a,actionCallback:l}),(0,w.jsx)(kt,{note:o,vault:a,actionCallback:l})]})});return(0,w.jsx)(A.Action.Push,{title:`Show Mentioning Notes (${i})`,target:r,icon:A.Icon.Megaphone})}else return(0,w.jsx)(K.default.Fragment,{})}function Zd(s){let{note:e}=s,t=qa(e.content);if(t.length===1){let n=t[0];return(0,w.jsxs)(K.default.Fragment,{children:[(0,w.jsx)(A.Action.Paste,{title:"Paste Code",icon:A.Icon.Code,content:n.code}),(0,w.jsx)(A.Action.CopyToClipboard,{title:"Copy Code",icon:A.Icon.Code,content:n.code})]})}else return t.length>1?(0,w.jsx)(A.Action.Push,{title:"Copy Code",icon:A.Icon.Code,target:(0,w.jsx)(A.List,{isShowingDetail:!0,children:t?.map(n=>(0,w.jsx)(A.List.Item,{title:n.code,detail:(0,w.jsx)(A.List.Item.Detail,{markdown:"```\n"+n.code+"```"}),subtitle:n.language,actions:(0,w.jsxs)(A.ActionPanel,{children:[(0,w.jsx)(A.Action.Paste,{title:"Paste Code",icon:A.Icon.Code,content:n.code}),(0,w.jsx)(A.Action.CopyToClipboard,{title:"Copy Code",icon:A.Icon.Code,content:n.code})]})},n.code))})}):(0,w.jsx)(K.default.Fragment,{})}function kt(s){let{note:e,vault:t,actionCallback:n}=s;return(0,w.jsxs)(K.default.Fragment,{children:[(0,w.jsx)(Bd,{path:e.path}),(0,w.jsx)(zd,{vault:t,str:e.title}),(0,w.jsx)(Zd,{note:e}),(0,w.jsx)(Vd,{note:e,vault:t,actionCallback:n}),(0,w.jsx)(Rd,{note:e,actionCallback:n}),(0,w.jsx)(jd,{note:e,actionCallback:n}),(0,w.jsx)(Kd,{note:e}),(0,w.jsx)(Ud,{note:e}),(0,w.jsx)(Yd,{note:e}),(0,w.jsx)(Jd,{note:e}),(0,w.jsx)(Gd,{note:e,vault:t,actionCallback:n}),(0,w.jsx)(Wd,{note:e,vault:t,actionCallback:n})]})}function Ct(s){let{note:e,vault:t,actionCallback:n}=s,{primaryAction:i}=(0,A.getPreferenceValues)(),[r,o]=Ma([t],"obsidian-advanced-uri"),a=(0,w.jsx)(Qd,{note:e,vault:t,actionCallback:n}),l=(0,w.jsx)(Xd,{path:e.path}),c=r.includes(t)?(0,w.jsx)(Hd,{note:e,vault:t}):null;return i=="quicklook"?(0,w.jsxs)(K.default.Fragment,{children:[a,l,c]}):i=="obsidian"?(0,w.jsxs)(K.default.Fragment,{children:[l,c,a]}):i=="newpane"?(0,w.jsxs)(K.default.Fragment,{children:[c,l,a]}):(0,w.jsxs)(K.default.Fragment,{children:[l,c,a]})}var Tt=require("react/jsx-runtime");function Si(s){let{searchContent:e}=(0,Be.getPreferenceValues)(),{showTitle:t,vault:n,searchArguments:i}=s,[r,o]=(0,Z.useState)([]),[a,l]=(0,Z.useState)([]),[c,d]=(0,Z.useState)(i.searchArgument||""),f=(0,Z.useMemo)(()=>Ja(r,c,e),[r,c]);function u(p){o(r.filter(g=>g.path!==p.path)),l(a.filter(g=>g.path!==p.path))}return(0,Z.useEffect)(()=>{async function p(){try{await el.default.promises.access(n.path+"/.");let g=_e(n);o(g),l(g)}catch{(0,Be.showToast)({title:"The path set in preferences doesn't exist",message:"Please set a valid path in preferences",style:Be.Toast.Style.Failure})}}p()},[]),(0,Tt.jsx)(ks,{title:t?"Search Note in "+n.name:"",notes:f.slice(0,wi),allNotes:a,setNotes:o,vault:n,onDelete:u,onSearchChange:d,searchArguments:i,action:(p,g,h)=>(0,Tt.jsxs)(Z.default.Fragment,{children:[(0,Tt.jsx)(Ct,{note:p,vault:g,actionCallback:h}),(0,Tt.jsx)(kt,{note:p,vault:g,actionCallback:h})]})})}var Se=require("@raycast/api");var Ve=require("react/jsx-runtime");function tl(s){let{vaults:e,target:t}=s;return(0,Ve.jsx)(Se.List,{children:e?.map(n=>(0,Ve.jsx)(Se.List.Item,{title:n.name,actions:(0,Ve.jsxs)(Se.ActionPanel,{children:[(0,Ve.jsx)(Se.Action.Push,{title:"Select Vault",target:t(n)}),(0,Ve.jsx)(Za,{vault:n})]})},n.key))})}var sl=require("@raycast/api"),eh=require("react/jsx-runtime");function nl(){return(0,eh.jsx)(sl.Detail,{markdown:`# No vaults found
143: 
144:  Please use Obsidian to create a vault, or set a vault path in the extension's preferences before using this command.`})}var Et=require("react/jsx-runtime");function rl(s){let{ready:e,vaults:t}=Da();if(e){if(t.length===0)return(0,Et.jsx)(nl,{});if(t.length>1)return(0,Et.jsx)(tl,{vaults:t,target:n=>(0,Et.jsx)(Si,{vault:n,showTitle:!0,searchArguments:s.arguments})});if(t.length==1)return(0,Et.jsx)(Si,{vault:t[0],showTitle:!1,searchArguments:s.arguments});Ei()}else return(0,Et.jsx)(il.List,{isLoading:!0})}0&&(module.exports={});
145: 
---

rl:searchNoteCommand.js:144:195
jt:index.js:5:2490
ray-navigation-stack
Nr:index.js:5:2088
Suspense
Ht:index.js:4:3437
ray-root
Wi:index.js:5:3006

Steps To Reproduce

  1. I assigned hotkey "ctrl + opt + n" to Search Note.
  2. I activated Search Note by pressing the hotkey, the raycast dialog for Search Note shows up. The dialog says "Something went wrong".
  3. On the dialog, I clicked "Copy Error" action. The content of the error in this file. raycast-obsidian-error.log

The current behavior

The dialog of Search Note show error message.

The expected behavior

The dialog of Search Note shows search bar.

Raycast version

Version: 1.41.1

Activity

  1. added
    bug
    extension
    on Oct 21, 2022
  2. marcjulianschwarz commented on Oct 26, 2022

    @marcjulianschwarz
    Contributor

    Hi @simpzan,

    thank you for the detailed description of the bug. I was able to reproduce it and it will thus be fixed with the next version.
    For now, I have added the issue to the backlog/roadmap of this extension.

  3. moved this from Backlog - Bugs to Unreleased in Obsidian for Raycast - Roadmapon Oct 28, 2022
  4. Repository owner moved this from Unreleased to Done in Obsidian for Raycast - Roadmapon Oct 28, 2022
  5. added a commit that references this issue on Sep 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugextension

    Type

    No type

    Fields

    Priority

    None yet

    Severity

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions