Improve readability and add NOTE for multibyte handling
This commit is contained in:
parent
8be000a257
commit
93f4849764
@ -846,15 +846,27 @@ function! s:PromptUser(groups) "{{{
|
||||
let coord_key_dict = s:CreateCoordKeyDict(a:groups)
|
||||
|
||||
for dict_key in sort(coord_key_dict[0])
|
||||
let marker_key = coord_key_dict[1][dict_key]
|
||||
let marker_key_first = matchstr(marker_key, '^.')
|
||||
let marker_key_first_byte_len = strlen(marker_key_first)
|
||||
" NOTE: {{{
|
||||
" let g:EasyMotion_keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
" Perform <Plug>(easymotion-w)
|
||||
"
|
||||
" lines[line_num]['orig']:
|
||||
" Lorem ipsum dolor sit amet consectetur adipisicing
|
||||
"
|
||||
" {target_char}:
|
||||
" {L}orem {i}psum {d}olor {s}it {a}met {c}onsectetur {a}dipisicing
|
||||
"
|
||||
" lines[line_num]['marker'], {marker_chars}:
|
||||
" {A}orem {B}psum {C}olor {D}it {E}met {F}onsectetur {G}dipisicing
|
||||
" 2-key-combo: {marker_chars} could be 1 or 2 chars like {AB}
|
||||
"
|
||||
" }}}
|
||||
|
||||
" Prepare original line and marker line {{{
|
||||
let [line_num, col_num] = split(dict_key, ',')
|
||||
|
||||
let line_num = str2nr(line_num)
|
||||
let col_num = str2nr(col_num)
|
||||
|
||||
" Add original line and marker line
|
||||
if ! has_key(lines, line_num)
|
||||
let current_line = getline(line_num)
|
||||
let lines[line_num] = {
|
||||
@ -862,68 +874,73 @@ function! s:PromptUser(groups) "{{{
|
||||
\ 'marker': current_line,
|
||||
\ 'mb_compensation': 0,
|
||||
\ }
|
||||
endif
|
||||
" mb_compensation -> multibyte compensation
|
||||
endif "}}}
|
||||
|
||||
" Multibyt Compensation: {{{
|
||||
" Solve multibyte issues by matching the byte column
|
||||
" number instead of the visual column
|
||||
let col_num -= lines[line_num]['mb_compensation']
|
||||
|
||||
" Compensate for byte difference between marker
|
||||
" character and target character
|
||||
"
|
||||
" This has to be done in order to match the correct
|
||||
" column; \%c matches the byte column and not display
|
||||
" column.
|
||||
let target_char_len = strdisplaywidth(
|
||||
\ matchstr(lines[line_num]['marker'],
|
||||
\ '\%' . col_num . 'c.'))
|
||||
let marker_key_len = strchars(marker_key)
|
||||
let col_num -= lines[line_num]['mb_compensation']
|
||||
"}}}
|
||||
|
||||
" Prepare marker characters {{{
|
||||
let marker_chars = coord_key_dict[1][dict_key]
|
||||
let marker_chars_len = EasyMotion#helper#strchars(marker_chars)
|
||||
let marker_chars_first = matchstr(marker_chars, '^.')
|
||||
let marker_chars_first_byte_len = strlen(marker_chars_first)
|
||||
"}}}
|
||||
|
||||
let target_line_byte_len = strlen(lines[line_num]['marker'])
|
||||
|
||||
let target_char_byte_len = strlen(matchstr(
|
||||
\ lines[line_num]['marker'],
|
||||
\ '\%' . col_num . 'c.'))
|
||||
" Prepare targets characters {{{
|
||||
let target_char = matchstr(lines[line_num]['orig'],
|
||||
\ '\%' . col_num . 'c.')
|
||||
let target_char_disp_len = strdisplaywidth(target_char)
|
||||
let target_char_byte_len = strlen(target_char)
|
||||
let target_line_byte_len = strlen(lines[line_num]['orig'])
|
||||
"}}}
|
||||
|
||||
if strlen(lines[line_num]['marker']) > 0
|
||||
" Substitute marker character if line length > 0
|
||||
let c = 0
|
||||
let col_add = 0
|
||||
let col_add = 0 " Column add byte length
|
||||
" Disable two-key-combo feature?
|
||||
let marker_max_length = g:EasyMotion_disable_two_key_combo == 1
|
||||
\ ? 1 : 2
|
||||
let marker_limit = min([marker_key_len, marker_max_length])
|
||||
while c < marker_limit
|
||||
let marker_limit = min([marker_chars_len, marker_max_length])
|
||||
for i in range(marker_limit)
|
||||
if strlen(lines[line_num]['marker']) >= col_num + col_add
|
||||
" Substitute marker character if line length > 0
|
||||
if c == 0
|
||||
if i == 0
|
||||
let lines[line_num]['marker'] = substitute(
|
||||
\ lines[line_num]['marker'],
|
||||
\ '\%' . (col_num + col_add) . 'c.',
|
||||
\ marker_key_first
|
||||
\ . repeat(' ', target_char_len - 1),
|
||||
\ marker_chars_first
|
||||
\ . repeat(' ', target_char_disp_len - 1),
|
||||
\ '')
|
||||
else
|
||||
let lines[line_num]['marker'] = substitute(
|
||||
\ lines[line_num]['marker'],
|
||||
\ '\%' . (col_num + col_add) . 'c.',
|
||||
\ matchstr(marker_key, '^.\zs.'),
|
||||
\ matchstr(marker_chars, '^.\zs.'),
|
||||
\ '')
|
||||
endif
|
||||
else
|
||||
" EOL
|
||||
let lines[line_num]['marker'] .= split(marker_key, '\zs')[c]
|
||||
let lines[line_num]['marker'] .= split(marker_chars, '\zs')[i]
|
||||
endif
|
||||
let c += 1
|
||||
let col_add += marker_key_first_byte_len
|
||||
endwhile
|
||||
let col_add += marker_chars_first_byte_len
|
||||
endfor
|
||||
else
|
||||
" Set the line to the marker character if the line is empty
|
||||
let lines[line_num]['marker'] = marker_key
|
||||
let lines[line_num]['marker'] = marker_chars
|
||||
endif
|
||||
|
||||
" -- Highlight targets ------------------- {{{
|
||||
if EasyMotion#helper#strchars(marker_key) == 1
|
||||
if marker_chars_len == 1
|
||||
call EasyMotion#highlight#add_highlight(
|
||||
\ '\%' . line_num . 'l\%' . col_num . 'c',
|
||||
\ g:EasyMotion_hl_group_target)
|
||||
@ -933,7 +950,7 @@ function! s:PromptUser(groups) "{{{
|
||||
\ g:EasyMotion_hl2_first_group_target)
|
||||
if g:EasyMotion_disable_two_key_combo != 1
|
||||
call EasyMotion#highlight#add_highlight(
|
||||
\ '\%' . line_num . 'l\%' . (col_num + marker_key_first_byte_len) . 'c',
|
||||
\ '\%' . line_num . 'l\%' . (col_num + marker_chars_first_byte_len) . 'c',
|
||||
\ g:EasyMotion_hl2_second_group_target)
|
||||
endif
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user