@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.
I would suggest you use c
and <c-r>
to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**
I would also recommend following the technique/example laid out by Vim's help (See :h g@)
nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
if !a:0
set opfunc=BoldIt
return 'g@'
endif
let type = a:1
let sel_save = &selection
let reg_save = getreginfo('"')
let reg_save = @@
let reg_type = getregtype('"');
let cb_save = &clipboard
let visual_marks_save = [getpos("'<"), getpos("'>")]
let commands = {}
let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"
try
set clipboard= selection=inclusive
let cmd = 'noautocmd keepjumps normal! '
let cmd .= get(commands, type, '')
silent exe cmd
finally
call setreg('"', reg_save, reg_type)
call setpos("'<", visual_marks_save[0])
call setpos("'>", visual_marks_save[1])
let &clipboard = cb_save
let &selection = sel_save
endtry
endfunction
Note: This may require a newer version of Vim (tested on Vim 8.2.2681)