name: core
requiredPermissions:
  - fetch
syntax:
  Hashtag:
    firstCharacters:
      - "#"
    regex: "#[^#\\d\\s\\[\\]]+\\w+"
    className: sb-hashtag
  NakedURL:
    firstCharacters:
      - "h"
    regex: "https?:\\/\\/[-a-zA-Z0-9@:%._\\+~#=]{1,256}([-a-zA-Z0-9()@:%_\\+.~#?&=\\/]*)"
    className: sb-naked-url
  NamedAnchor:
    firstCharacters:
      - "$"
    regex: "\\$[a-zA-Z\\.\\-\\/]+[\\w\\.\\-\\/]*"
    className: sb-named-anchor
functions:
  setEditorMode:
    path: "./editor.ts:setEditorMode"
    events:
      - editor:init
  toggleDarkMode:
    path: "./editor.ts:toggleDarkMode"
    command:
      name: "Editor: Toggle Dark Mode"
  centerCursor:
    path: "./editor.ts:centerCursorCommand"
    command:
      name: "Editor: Center Cursor"
      key: "Ctrl-Alt-l"
  moveToPos:
    path: "./editor.ts:moveToPosCommand"
    command:
      name: "Editor: Move Cursor to Position"
  clearPageIndex:
    path: "./page.ts:clearPageIndex"
    events:
      - page:saved
      - page:deleted
  pageQueryProvider:
    path: ./page.ts:pageQueryProvider
    events:
      - query:page
  parseIndexTextRepublish:
    path: "./page.ts:parseIndexTextRepublish"
    events:
      - page:index_text
  reindexSpaceCommand:
    path: "./page.ts:reindexCommand"
    command:
      name: "Space: Reindex"
  deletePage:
    path: "./page.ts:deletePage"
    command:
      name: "Page: Delete"
  copyPage:
    path: "./page.ts:copyPage"
    command:
      name: "Page: Copy"

  syncSpaceCommand:
    path: "./sync.ts:syncSpaceCommand"
    command:
      name: "Sync: Now"
      key: "Alt-Shift-s"
      mac: "Cmd-Shift-s"

  # Attachments
  attachmentQueryProvider:
    path: ./attachment.ts:attachmentQueryProvider
    events:
      - query:attachment

  # Backlinks
  indexLinks:
    path: "./page_links.ts:indexLinks"
    events:
      - page:index
  linkQueryProvider:
    path: ./page_links.ts:linkQueryProvider
    events:
      - query:link

  pageComplete:
    path: "./page.ts:pageComplete"
    events:
      - editor:complete

  # Commands
  commandComplete:
    path: "./command.ts:commandComplete"
    events:
      - editor:complete

  # Item indexing
  indexItem:
    path: "./item.ts:indexItems"
    events:
      - page:index
  itemQueryProvider:
    path: "./item.ts:queryProvider"
    events:
      - query:item

  # Navigation
  linkNavigate:
    path: "./navigate.ts:linkNavigate"
    command:
      name: Navigate To page
      key: Ctrl-Enter
      mac: Cmd-Enter
  clickNavigate:
    path: "./navigate.ts:clickNavigate"
    events:
      - page:click
  navigateHome:
    path: "./navigate.ts:navigateCommand"
    command:
      name: "Navigate: Home"
      key: "Alt-h"
      page: ""

  # Hashtags
  indexTags:
    path: "./tags.ts:indexTags"
    events:
      - page:index
  tagComplete:
    path: "./tags.ts:tagComplete"
    events:
      - editor:complete
  tagProvider:
    path: "./tags.ts:tagProvider"
    events:
      - query:tag

  # Anchors
  indexAnchors:
    path: "./anchor.ts:indexAnchors"
    events:
      - page:index
  anchorComplete:
    path: "./anchor.ts:anchorComplete"
    events:
      - editor:complete
  
  # Template commands
  insertTemplateText:
    path: "./template.ts:insertTemplateText"
  applyLineReplace:
    path: ./template.ts:applyLineReplace
  insertFrontMatter:
    redirect: insertTemplateText
    slashCommand:
      name: front-matter
      description: Insert page front matter
      value: |
        ---
        |^|
        ---
  makeH1:
    redirect: applyLineReplace
    slashCommand:
      name: h1
      description: Turn line into h1 header
      match: "^#*\\s*"
      replace: "# "
  makeH2:
    redirect: applyLineReplace
    slashCommand:
      name: h2
      description: Turn line into h2 header
      match: "^#*\\s*"
      replace: "## "
  makeH3:
    redirect: applyLineReplace
    slashCommand:
      name: h3
      description: Turn line into h3 header
      match: "^#*\\s*"
      replace: "### "
  makeH4:
    redirect: applyLineReplace
    slashCommand:
      name: h4
      description: Turn line into h4 header
      match: "^#*\\s*"
      replace: "#### "
  insertCodeBlock:
    redirect: insertTemplateText
    slashCommand:
      name: code
      description: Insert code block
      value: |
        ```
        |^|
        ```

  newPage:
    path: ./page.ts:newPageCommand
    command:
      name: "Page: New"
      key: "Alt-Shift-n"

  insertHRTemplate:
    redirect: insertTemplateText
    slashCommand:
      name: hr
      description: Insert a horizontal rule
      value: "---"
  insertTable:
    redirect: insertTemplateText
    slashCommand:
      name: table
      description: Insert a table
      boost: -1 # Low boost because it's likely not very commonly used
      value: |
        | Header A | Header B |
        |----------|----------|
        | Cell A|^| | Cell B |
  quickNoteCommand:
    path: ./template.ts:quickNoteCommand
    command:
      name: "Quick Note"
      key: "Alt-Shift-n"
      priority: 1
  dailyNoteCommand:
    path: ./template.ts:dailyNoteCommand
    command:
      name: "Open Daily Note"
      key: "Alt-Shift-d"
  weeklyNoteCommand:
    path: ./template.ts:weeklyNoteCommand
    command:
      name: "Open Weekly Note"
      key: "Alt-Shift-w"

  instantiateTemplateCommand:
    path: ./template.ts:instantiateTemplateCommand
    command:
      name: "Template: Instantiate Page"
  insertSnippet:
    path: ./template.ts:insertSnippet
    command:
      name: "Template: Insert Snippet"
    slashCommand:
      name: snippet
      description: Insert a snippet
  insertTodayCommand:
    path: "./template.ts:insertTemplateText"
    slashCommand:
      name: today
      description: Insert today's date
      value: "{{today}}"
  insertTomorrowCommand:
    path: "./template.ts:insertTemplateText"
    slashCommand:
      name: tomorrow
      description: Insert tomorrow's date
      value: "{{tomorrow}}"

  # Text editing commands
  quoteSelectionCommand:
    path: ./text.ts:quoteSelection
    command:
      name: "Text: Quote Selection"
      key: "Ctrl-Shift-."
      mac: "Cmd-Shift-."
  listifySelection:
    path: ./text.ts:listifySelection
    command:
      name: "Text: Listify Selection"
      key: "Ctrl-Shift-8"
      mac: "Cmd-Shift-8"
  numberListifySelection:
    path: ./text.ts:numberListifySelection
    command:
      name: "Text: Number Listify Selection"
  linkSelection:
    path: ./text.ts:linkSelection
    command:
      name: "Text: Link Selection"
      key: "Ctrl-Shift-k"
      mac: "Cmd-Shift-k"
  bold:
    path: ./text.ts:wrapSelection
    command:
      name: "Text: Bold"
      key: "Ctrl-b"
      mac: "Cmd-b"
      wrapper: "**"
  italic:
    path: ./text.ts:wrapSelection
    command:
      name: "Text: Italic"
      key: "Ctrl-i"
      mac: "Cmd-i"
      wrapper: "_"
  strikethrough:
    path: ./text.ts:wrapSelection
    command:
      name: "Text: Strikethrough"
      key: "Ctrl-Shift-s"
      mac: "Cmd-Shift-s"
      wrapper: "~~"
  marker:
    path: ./text.ts:wrapSelection
    command:
      name: "Text: Marker"
      key: "Alt-m"
      wrapper: "=="

  # Refactoring Commands
  extractToPageCommand:
    path: ./refactor.ts:extractToPageCommand
    command:
      name: "Extract text to new page"
  renamePageCommand:
    path: "./refactor.ts:renamePageCommand"
    command:
      name: "Page: Rename"
      mac: Cmd-Alt-r
      key: Ctrl-Alt-r
      page: ""
  renamePrefixCommand:
    path: "./refactor.ts:renamePrefixCommand"
    command:
      name: "Refactor: Batch Rename Page Prefix"

  # Plug manager
  updatePlugsCommand:
    path: ./plugmanager.ts:updatePlugsCommand
    command:
      name: "Plugs: Update"
      key: "Ctrl-Shift-p"
      mac: "Cmd-Shift-p"
  getPlugHTTPS:
    path: "./plugmanager.ts:getPlugHTTPS"
    events:
      - get-plug:https
  getPlugGithub:
    path: "./plugmanager.ts:getPlugGithub"
    events:
      - get-plug:github
  getPlugGithubRelease:
    path: "./plugmanager.ts:getPlugGithubRelease"
    events:
      - get-plug:ghr
  addPlugCommand:
    path: ./plugmanager.ts:addPlugCommand
    command:
      name: "Plugs: Add"

  # Debug commands
  parseCommand:
    path: ./debug.ts:parsePageCommand
    command:
      name: "Debug: Parse Document"

  reloadUICommand:
    path: ./debug.ts:reloadUICommand
    command:
      name: "Debug: Reload UI"

  resetClientCommand:
    path: ./debug.ts:resetClientCommand
    command:
      name: "Debug: Reset Client"

  versionCommand:
    path: ./help.ts:versionCommand
    command:
      name: "Help: Version"
  gettingStartedCommand:
    path: ./help.ts:gettingStartedCommand
    command:
      name: "Help: Getting Started"

  accountLogoutCommand:
    path: ./account.ts:accountLogoutCommand
    command:
      name: "Account: Logout"

  # Link unfurl infrastructure
  unfurlLink:
    path: ./link.ts:unfurlCommand
    command:
      name: "Link: Unfurl"
      key: "Ctrl-Shift-u"
      mac: "Cmd-Shift-u"
      contexts:
        - NakedURL

  # Title-based link unfurl
  titleUnfurlOptions:
    path: ./link.ts:titleUnfurlOptions
    events:
      - unfurl:options
  titleUnfurl:
    path: ./link.ts:titleUnfurl
    events:
      - unfurl:title-unfurl

  embedWidget:
    path: ./embed.ts:embedWidget
    codeWidget: embed

  # Folding commands
  foldCommand:
    path: ./editor.ts:foldCommand
    command:
      name: "Fold: Fold"
      mac: "Cmd-Alt-["
      key: "Ctrl-Shift-["
  unfoldCommand:
    path: ./editor.ts:unfoldCommand
    command:
      name: "Fold: Unfold"
      mac: "Cmd-Alt-]"
      key: "Ctrl-Shift-]"
  toggleFoldCommand:
    path: ./editor.ts:toggleFoldCommand
    command:
      name: "Fold: Toggle Fold"
      mac: "Cmd-Alt-f"
      key: "Ctrl-Alt-f"
  foldAllCommand:
    path: ./editor.ts:foldAllCommand
    command:
      name: "Fold: Fold All"
      key: "Ctrl-Alt-["
  unfoldAllCommand:
    path: ./editor.ts:unfoldAllCommand
    command:
      name: "Fold: Unfold All"
      key: "Ctrl-Alt-]"

  # Random stuff
  statsCommand:
    path: ./stats.ts:statsCommand
    command:
      name: "Stats: Show"

  # Cloud pages
  readPageCloud:
    path: ./cloud.ts:readFileCloud
    pageNamespace:
      pattern: "💭 .+"
      operation: readFile
  writePageCloud:
    path: ./cloud.ts:writeFileCloud
    pageNamespace:
      pattern: "💭 .+"
      operation: writeFile
  getPageMetaCloud:
    path: ./cloud.ts:getFileMetaCloud
    pageNamespace:
      pattern: "💭 .+"
      operation: getFileMeta

  # Vim
  toggleVimMode:
    path: "./vim.ts:toggleVimMode"
    command:
      name: "Editor: Toggle Vim Mode"
  loadVimRc:
    path: "./vim.ts:loadVimRc"
    command:
      name: "Editor: Vim: Load VIMRC"
    events:
      - editor:modeswitch

  brokenLinksCommand:
    path: ./broken_links.ts:brokenLinksCommand
    command:
      name: "Broken Links: Show"
