Skip to content

Commit

Permalink
hoge
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Jan 26, 2024
1 parent b34bb2c commit fc92ce1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lua/frecency/database/native.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ end
function Native:get_entries(workspace, datetime)
local now = self:now(datetime)
local items = {}
local starts_with
if workspace then
starts_with = workspace .. (workspace:sub(#workspace) == Path.path.sep and "" or Path.path.sep)
end
for path, record in pairs(self.table.records) do
if not workspace or path:find(starts_with, 1, true) then
if self.fs:starts_with(path, workspace) then
table.insert(items, {
path = path,
count = record.count,
Expand Down
16 changes: 16 additions & 0 deletions lua/frecency/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ function FS:relative_from_home(path)
return Path:new(path):make_relative(self.os_homedir)
end

---@type table<string,string>
local with_sep = {}

---@param path string
---@param base string?
---@return boolean
function FS:starts_with(path, base)
if not base then
return true
end
if not with_sep[base] then
with_sep[base] = base .. (base:sub(#base) == Path.path.sep and "" or Path.path.sep)
end
return path:find(with_sep[base], 1, true) == 1
end

---@private
---@param path string
---@return boolean
Expand Down

0 comments on commit fc92ce1

Please sign in to comment.