mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Add HTML text object offset quirk
This commit is contained in:
@@ -7,17 +7,35 @@
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! matchup#quirks#isclike() abort " {{{1
|
||||
function! s:ftcheck(fts) abort " {{{1
|
||||
let l:ft = get(split(&filetype, '\.'), 0, '')
|
||||
return index(s:clikeft, l:ft) > -1
|
||||
return index(a:fts, l:ft) > -1
|
||||
endfunction
|
||||
|
||||
let s:clikeft = [ 'arduino', 'c', 'cpp', 'cuda',
|
||||
\ 'go', 'javascript', 'ld', 'php' ]
|
||||
" }}}1
|
||||
function! matchup#quirks#isclike() abort " {{{1
|
||||
return s:ftcheck(s:clikeft)
|
||||
endfunction
|
||||
|
||||
let s:clikeft = [
|
||||
\ 'arduino', 'c', 'cpp', 'cuda', 'ld', 'php', 'go',
|
||||
\ 'javascript', 'typescript',
|
||||
\ 'javascriptreact', 'typescriptreact',
|
||||
\]
|
||||
|
||||
" }}}1
|
||||
function! matchup#quirks#ishtmllike() abort " {{{1
|
||||
return s:ftcheck(s:htmllikeft)
|
||||
endfunction
|
||||
|
||||
let s:adjust_max = 7
|
||||
let s:htmllikeft = [
|
||||
\ 'tidy', 'php', 'liquid', 'haml', 'tt2html',
|
||||
\ 'html', 'xhtml', 'jsp', 'htmldjango',
|
||||
\ 'aspvbs', 'rmd', 'markdown', 'eruby',
|
||||
\ 'javascriptreact', 'typescriptreact',
|
||||
\]
|
||||
|
||||
" }}}1
|
||||
|
||||
function! matchup#quirks#status_adjust(offscreen) abort " {{{1
|
||||
if a:offscreen.match ==# '{' && matchup#quirks#isclike()
|
||||
@@ -47,9 +65,10 @@ function! matchup#quirks#status_adjust(offscreen) abort " {{{1
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
let s:adjust_max = 9
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
" vim: fdm=marker sw=2
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
|
||||
function! matchup#text_obj#delimited(is_inner, visual, type) abort " {{{1
|
||||
let l:v_motion_force = matchup#motion_force()
|
||||
|
||||
" get the current selection, move to the _start_ the of range
|
||||
@@ -126,6 +126,13 @@ function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
|
||||
let l:sol = (l:c2 <= 1)
|
||||
let [l:l2, l:c2] = matchup#pos#prev(l:l2, l:c2)[1:2]
|
||||
|
||||
" make *i% more like *it for html
|
||||
if matchup#quirks#ishtmllike()
|
||||
\ && matchup#util#matchpref('classic_textobj', 1)
|
||||
\ && l:close.match =~? '/\w\+\s*>'
|
||||
let l:c2 -= 1
|
||||
endif
|
||||
|
||||
" don't select only indent at close
|
||||
while matchup#util#in_indent(l:l2, l:c2)
|
||||
let l:c2 = 1
|
||||
@@ -201,8 +208,16 @@ function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
|
||||
else
|
||||
let l:c2 += matchup#delim#end_offset(l:close)
|
||||
|
||||
" make *a% more like *at for html
|
||||
if matchup#quirks#ishtmllike()
|
||||
\ && matchup#util#matchpref('classic_textobj', 1)
|
||||
\ && l:close.match =~? '/\w\+\s*>'
|
||||
let l:c1 -= 1
|
||||
endif
|
||||
|
||||
" special case for delete operator
|
||||
if !a:visual && v:operator ==# 'd'
|
||||
\ && l:line_count > 1
|
||||
\ && strpart(getline(l:l2), l:c2) =~# '^\s*$'
|
||||
\ && strpart(getline(l:l2), 0, l:c1-1) =~# '^\s*$'
|
||||
let l:c1 = 1
|
||||
@@ -258,7 +273,7 @@ function! matchup#text_obj#undo(seq)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#text_obj#double_click() " {{{1
|
||||
function! matchup#text_obj#double_click() abort " {{{1
|
||||
let [l:open, l:close] = [{}, {}]
|
||||
|
||||
call matchup#perf#timeout_start(0)
|
||||
|
||||
Reference in New Issue
Block a user