File tree 5 files changed +26
-8
lines changed
5 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Added
11
11
12
+ - Added configuration option ` image_name_func: (fun(): string)|? ` for customizing the default image name/prefix when pasting images via ` :ObsidianPasteImg ` .
12
13
- Added client method ` Client:current_note() ` to get the note corresponding to the current buffer.
13
14
- Added note method ` Note.add_field(key: string, value: any) ` to add/update an additional field in the frontmatter.
14
15
- Added note method ` Note.get_field(key: string) ` .
Original file line number Diff line number Diff line change @@ -316,6 +316,12 @@ This is a complete list of all of the options that can be passed to `require("ob
316
316
return tostring (os.time ()) .. " -" .. suffix
317
317
end ,
318
318
319
+ -- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
320
+ image_name_func = function ()
321
+ -- Prefix image names with timestamp.
322
+ return string.format (" %s-" , os.time ())
323
+ end ,
324
+
319
325
-- Optional, boolean or a function that takes a filename and returns a boolean.
320
326
-- `true` indicates that you don't want obsidian.nvim to manage frontmatter.
321
327
disable_frontmatter = false ,
Original file line number Diff line number Diff line change @@ -9,7 +9,13 @@ return function(client, data)
9
9
img_folder = client .dir / client .opts .attachments .img_folder
10
10
end
11
11
12
- local path = paste_img (data .args , img_folder )
12
+ --- @type string |?
13
+ local default_name
14
+ if client .opts .image_name_func then
15
+ default_name = client .opts .image_name_func ()
16
+ end
17
+
18
+ local path = paste_img (data .args , img_folder , default_name )
13
19
14
20
if path ~= nil then
15
21
util .insert_text (client .opts .attachments .img_text_func (client , path ))
Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ local config = {}
11
11
--- @field log_level integer
12
12
--- @field notes_subdir string |?
13
13
--- @field templates obsidian.config.TemplateOpts
14
- --- @field note_id_func function |?
15
- --- @field follow_url_func function |?
16
- --- @field note_frontmatter_func function |?
14
+ --- @field note_id_func (fun ( title : string ): string )|?
15
+ --- @field follow_url_func fun ( url : string )|?
16
+ --- @field image_name_func (fun (): string )|?
17
+ --- @field note_frontmatter_func fun ( note : obsidian.Note )|?
17
18
--- @field disable_frontmatter (fun ( fname : string ?): boolean )| boolean |?
18
19
--- @field backlinks obsidian.config.LocationListOpts
19
20
--- @field tags obsidian.config.LocationListOpts
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ local function get_clip_check_command()
28
28
return check_cmd
29
29
end
30
30
31
- --- Check if clipboard contains image data.
31
+ --- Check if clipboard contains image data.
32
+ ---
32
33
--- @return boolean
33
34
local function clipboard_is_img ()
34
35
local content = {}
@@ -49,8 +50,9 @@ local function clipboard_is_img()
49
50
end
50
51
end
51
52
52
- --- Save image from clipboard to `path`.
53
+ --- Save image from clipboard to `path`.
53
54
--- @param path string
55
+ ---
54
56
--- @return boolean | integer |? result
55
57
local function save_clipboard_image (path )
56
58
local this_os = util .get_os ()
84
86
85
87
--- @param fname string |?
86
88
--- @param default_dir Path | string
89
+ --- @param default_name string |?
90
+ ---
87
91
--- @return Path |? image_path the absolute path to the image file
88
- M .paste_img = function (fname , default_dir )
92
+ M .paste_img = function (fname , default_dir , default_name )
89
93
if not clipboard_is_img () then
90
94
log .err " There is no image data in the clipboard"
91
95
return
92
96
else
93
97
-- Get filename to save to.
94
98
if fname == " " then
95
- fname = vim .fn .input { prompt = " Enter file name: " }
99
+ fname = vim .fn .input { prompt = " Enter file name: " , default = default_name }
96
100
end
97
101
98
102
if fname == " " then
You can’t perform that action at this time.
0 commit comments