From f960b9bd59cc1893b90f360f991ff293843ce9fe Mon Sep 17 00:00:00 2001 From: eight04 Date: Sat, 4 Dec 2021 00:23:16 +0800 Subject: [PATCH] Fix: make updateTag work with tag name --- autoload/emmet.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/autoload/emmet.vim b/autoload/emmet.vim index 12ed9a9..efafc3f 100644 --- a/autoload/emmet.vim +++ b/autoload/emmet.vim @@ -785,15 +785,28 @@ function! emmet#updateTag() abort if empty(current) return '' endif + let old_tag_name = current.name let str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') + let tag_changed = str =~# '^\s*\w' let item = emmet#parseIntoTree(str, type).child[0] for k in keys(item.attr) let current.attr[k] = item.attr[k] endfor + if tag_changed + let current.name = item.name + endif let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '') let html = substitute(html, '\${cursor}', '', '') let html = matchstr(html, '^<[^><]\+>') + if tag_changed + let pos2 = searchpairpos('<' . old_tag_name . '\>[^>]*>', '', '', 'W') + if pos2 != [0, 0] + let html .= emmet#util#getContent([region[1], pos2])[1:-2] + let html .= '' + let region = [region[0], [pos2[0], pos2[1] + len(old_tag_name) + 3]] + endif + endif call emmet#util#setContent(region, html) return '' endfunction