Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions plugin/mdip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,26 @@ function! s:RandomName()
return l:new_random
endfunction

function! g:MarkdownPasteImageNames(A, L, P)
let files = glob(s:workdir . '/*.png', '', 1)
let names = map(files, 'fnamemodify(v:val, ":t:r")')
return filter(names, 'v:val =~ "^" . a:A')
endfunction

function! s:InputName()
call inputsave()
let name = input('Image name: ')
let name = input('Image name: ', '', 'customlist,MarkdownPasteImageNames')
call inputrestore()
return name
endfunction

function! s:Confirm(message)
call inputsave()
let response = input(a:message)
call inputrestore()
return response =~ '^y'
endfunction

function! g:MarkdownPasteImage(relpath)
execute "normal! i![" . g:mdip_tmpname[0:0]
let ipos = getcurpos()
Expand Down Expand Up @@ -208,21 +221,24 @@ function! mdip#MarkdownClipboardImage()

" add check whether file with the name exists
while 1
let workdir = s:SafeMakeDir()
let s:workdir = s:SafeMakeDir()
" change temp-file-name and image-name
let g:mdip_tmpname = s:InputName()
if empty(g:mdip_tmpname)
let g:mdip_tmpname = g:mdip_imgname . '_' . s:RandomName()
endif
let testpath = workdir . '/' . g:mdip_tmpname . '.png'
let testpath = s:workdir . '/' . g:mdip_tmpname
if testpath !~ '\.png$'
let testpath = testpath . '.png'
endif
if filereadable(testpath) == 0
break
else
echo "\nThis file name already exists"
elseif s:Confirm("This file name already exists. Overwrite? [y/n] ")
break
endif
endwhile

let tmpfile = s:SaveFileTMP(workdir, g:mdip_tmpname)
let tmpfile = s:SaveFileTMP(s:workdir, g:mdip_tmpname)
if tmpfile == 1
return
else
Expand Down