Skip to content

Commit

Permalink
feat(#7): move notes
Browse files Browse the repository at this point in the history
done move notes dialog.
  • Loading branch information
IlyasYOY committed May 12, 2023
1 parent 0c2b53e commit df59240
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/obs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local File = require "coredor.file"

local M = {}

function M.list_directories(path_string)
function M.list_folders(path_string)
if path_string == nil then
error "path must not be nil"
end
Expand Down
2 changes: 1 addition & 1 deletion lua/obs/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local coredor = require "coredor"

describe("list directories", function()
local utils = require "obs.utils"
local list_directories = utils.list_directories
local list_directories = utils.list_folders
local temp_file_fixture = spec.temp_file_fixture()
local temp_dir_fixture = spec.temp_dir_fixture()

Expand Down
33 changes: 33 additions & 0 deletions lua/obs/vault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local Path = require "plenary.path"

local obs_telescope = require "obs.telescope"
local core = require "coredor"
local utils = require "obs.utils"

-- table with vault options
---@class obs.VaultOpts
Expand Down Expand Up @@ -120,6 +121,38 @@ function Vault:find_and_insert_template()
self._templater:search_and_insert_template()
end

function Vault:find_directory_and_move_current_note()
local folders = utils.list_folders(self._home_path:expand())

local current_note_filename = vim.fn.expand "%:t"
local current_note_fullpath = vim.fn.expand "%"
local current_buf = vim.api.nvim_get_current_buf()

return obs_telescope.find_through_items(
"Folders",
folders,
function(selection)
local from_file = File:new(selection.source)
from_file:as_plenary():copy {
destination = selection.destination,
}
vim.fn.execute(current_buf .. "bdelete")
File:new(selection.destination):edit()
from_file:as_plenary():rm()
end,
function(entry)
entry = File:new(entry)
return {
value = entry:path(),
display = entry:path(),
ordinal = entry:path(),
source = current_note_fullpath,
destination = (entry:as_plenary() / current_note_filename):expand(),
}
end
)
end

function Vault:find_note()
obs_telescope.find_files("Find notes", self._home_path:expand())
end
Expand Down

0 comments on commit df59240

Please sign in to comment.