Merge pull request #533 from eight04/dev-update-tag-name

Fix: make updateTag work with tag name
This commit is contained in:
mattn
2021-12-05 00:38:44 +09:00
committed by GitHub
2 changed files with 15 additions and 2 deletions

View File

@@ -785,15 +785,28 @@ function! emmet#updateTag() abort
if empty(current) if empty(current)
return '' return ''
endif endif
let old_tag_name = current.name
let str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') let str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g')
let tag_changed = str =~# '^\s*\w'
let item = emmet#parseIntoTree(str, type).child[0] let item = emmet#parseIntoTree(str, type).child[0]
for k in keys(item.attr) for k in keys(item.attr)
let current.attr[k] = item.attr[k] let current.attr[k] = item.attr[k]
endfor endfor
if tag_changed
let current.name = item.name
endif
let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '') let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '')
let html = substitute(html, '\${cursor}', '', '') let html = substitute(html, '\${cursor}', '', '')
let html = matchstr(html, '^<[^><]\+>') let html = matchstr(html, '^<[^><]\+>')
if tag_changed
let pos2 = searchpairpos('<' . old_tag_name . '\>[^>]*>', '', '</' . old_tag_name . '>', 'W')
if pos2 != [0, 0]
let html .= emmet#util#getContent([region[1], pos2])[1:-2]
let html .= '</' . current.name . '>'
let region = [region[0], [pos2[0], pos2[1] + len(old_tag_name) + 3]]
endif
endif
call emmet#util#setContent(region, html) call emmet#util#setContent(region, html)
return '' return ''
endfunction endfunction

View File

@@ -736,11 +736,11 @@ endfunction
function! emmet#lang#html#parseTag(tag) abort function! emmet#lang#html#parseTag(tag) abort
let current = emmet#newNode() let current = emmet#newNode()
let mx = '<\([a-zA-Z][a-zA-Z0-9]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\?\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>' let mx = '<\([a-zA-Z][a-zA-Z0-9-]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9-]\+=\?\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i') let current.name = substitute(match, mx, '\1', 'i')
let attrs = substitute(match, mx, '\2', 'i') let attrs = substitute(match, mx, '\2', 'i')
let mx = '\([a-zA-Z0-9]\+\)\(\(=[^"'' \t]\+\)\|="\([^"]\{-}\)"\|=''\([^'']\{-}\)''\)\?' let mx = '\([a-zA-Z0-9-]\+\)\(\(=[^"'' \t]\+\)\|="\([^"]\{-}\)"\|=''\([^'']\{-}\)''\)\?'
while len(attrs) > 0 while len(attrs) > 0
let match = matchstr(attrs, mx) let match = matchstr(attrs, mx)
if len(match) == 0 if len(match) == 0