Create new page with Page Picker

Has only played with the application for a couple days; overall love the app. One thing I find it annoying is how I need to type the file path every single time I create a new file with Page Picker. My use case is create small files at various location and typing the full path for each of them does consume some time.

I'm not exactly sure if there's other way to create a new page, but I took inspiration from vscode-advanced-newfile, and made a script. Would appreciate any feedbacks/comments as I'm new to lua and SilverBullet in general.

local function findPaths()
  local pages = query[[from p = tags.page select p.name]]

  local dirs = {}
  dirs[""] = true -- always keep root in there
  for _, name in ipairs(pages) do
    local dir = string.match(name, "^(.*)/[^/]*$") or ""
    dirs[dir] = true
  end

  local allDirs = {}
  for dir, _ in pairs(dirs) do
    allDirs[dir] = true
    local parts = {}
    for part in string.gmatch(dir, "[^/]+") do
      table.insert(parts, part)
    end
    local prefix = ""
    for i = 1, #parts - 1 do
      prefix = (i == 1) and parts[1] or (prefix .. "/" .. parts[i])
      allDirs[prefix] = true
    end
  end

  local folders = {}
  for dir, _ in pairs(allDirs) do
    table.insert(folders, {name = dir .. "/", path = dir})
  end

  return folders
end


local function choosePath(folders)
  local choice = editor.filterBox(
    "Create relative to existing directory",
    folders
  )
  if not choice then return nil end
  return choice.path
end

command.define {
  name = "Advance New File: New File",
  run = function()
    local basePath = choosePath(findPaths())

    if basePath == nil then return end -- cancel the operation

    local fileName = editor.prompt("Filename or relative path to file - Relative to " .. basePath .. " (Press 'Enter' to confirm or 'Escape' to cancel)", "")

    if not fileName or fileName == "" then return end -- cancel the operation

    local fullPath = (basePath == "") and fileName or (basePath .. "/" .. fileName)


    editor.navigate(fullPath)
  end
}

What may help you is to hit space in the page locker, this will autocomplete the current folder path you’re in.

Thanks! didn't know this exist. However, it still doesn't quite match my use case where I usually jump from one directory to another, which require me to type the path out or go to a page that is adjacent to the location of the new file before hitting space with page picker.

And if, I need to do the latter, then I believe it would make more sense to just make a new file command that specify the location first.