Page Picker: Last Opened / Modified

Since the Page Picker’s ordering rule is neither order by _.lastOpened desc, nor order by _.modified desc, nor order by _.lastClick desc mentioned in Click History - #12 by ChenZhu-Xie, I created these auxiliary pickers to help streamline buddie’s workflow.

PS: I also noticed that the page list expanded from [[ follows an even stranger order — one that matches none of the 4 patterns above… -_-|| So… we have 4 to 5 page pickers…?

Page Picker: Last Opened

command.define {
  name = "Page Picker: Last Opened",
  key = "Ctrl-p",
  priority = 1,
  run = function()
    local VisitHistory = queryVisitHistory()
    if not VisitHistory or #VisitHistory == 0 then
      editor.flashNotification("No Visit History found.")
      return
    end
    
    local sel = editor.filterBox("🤏 Pick", VisitHistory, "order by _.lastOpened desc", "a Page")
    if not sel then return end
    editor.navigate(sel.name)
    editor.invokeCommand("Navigate: Center Cursor")
  end
}

local function queryVisitHistory()
  return query[[
    -- from editor.getRecentlyOpenedPages "page"
    from editor.getRecentlyOpenedPages()
    where _.lastOpened
    select {name=_.ref, description=os.date("%Y-%m-%d %H:%M:%S", _.lastOpened/1000)} 
    order by _.lastOpened desc
]]
end

command.update {
  name = "Share: Page",
  key = "Shift-Alt-s",
  mac = "Shift-Alt-s",
  priority = 2,
}

Page Picker: Last Modified

command.define {
  name = "Page Picker: Last Modified",
  key = "Shift-Alt-p",
  priority = 1,
  run = function()
    local ModifyHistory = queryModifyHistory()
    if not ModifyHistory or #ModifyHistory == 0 then
      editor.flashNotification("No Modify History found.")
      return
    end
    
    local sel = editor.filterBox("🤏 Pick", ModifyHistory, "order by _.lastModified desc", "a Page")
    if not sel then return end
    editor.navigate(sel.name)
    editor.invokeCommand("Navigate: Center Cursor")
  end
}

local function queryModifyHistory()
  return query[[
    from index.tag "page"
    select {name=_.ref, description=string.sub(_.lastModified:gsub("T", " "), 1, -5)} 
    order by lastModified desc
]]
end

Help

I’ve noticed that Silversearch - Fulltext search for Silverbullet allows Alt-Enter to insert a link (rather than Enter to jump to the selction), I’d like to introduce this feature but don’t know how.

maybe outside the reach of space-lua? @MrMugame

I think many picker(developer)s need this feature (to multi-role every picker).

1 Like

I don’t think you can know if the FilterBox result was selected with any modifier keys pressed, so you would probably need multiple different commands for “Insert Link Picker” and “Page Picker”, etc. Silversearch does this by completely remodeling the picker using a modal.

1 Like