diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index deb66cc..c030c46 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -3,7 +3,7 @@ " Author: Kim Silkebækken " haya14busa " Source: https://github.com/Lokaltog/vim-easymotion -" Last Change: 22 Feb 2014. +" Last Change: 24 Feb 2014. "============================================================================= " Saving 'cpoptions' {{{ scriptencoding utf-8 @@ -828,13 +828,27 @@ function! s:PromptUser(groups) "{{{ let coord_key_dict = s:CreateCoordKeyDict(a:groups) for dict_key in sort(coord_key_dict[0]) - let target_key = coord_key_dict[1][dict_key] + " NOTE: {{{ + " let g:EasyMotion_keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + " Perform (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] = { @@ -842,63 +856,71 @@ 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 target_key_len = strdisplaywidth(target_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 {{{ + " Get target_char by compensated line. + let target_char = matchstr(lines[line_num]['marker'], + \ '\%' . col_num . 'c.') + let target_char_disp_len = strdisplaywidth(target_char) + let target_char_byte_len = strlen(target_char) + " Original target_line + 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 " Column add byte length + " Disable two-key-combo feature? let marker_max_length = g:EasyMotion_disable_two_key_combo == 1 \ ? 1 : 2 - while c < target_key_len && c < marker_max_length - if strlen(lines[line_num]['marker']) >= col_num + c + 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 - let lines[line_num]['marker'] = substitute( - \ lines[line_num]['marker'], - \ '\%' . (col_num + c) . 'c.', - \ strpart(target_key, c, 1) . repeat(' ', target_char_len - 1), - \ '') - else - let lines[line_num]['marker'] = substitute( - \ lines[line_num]['marker'], - \ '\%' . (col_num + c) . 'c.', - \ strpart(target_key, c, 1), - \ '') - endif + let substitute_expr = i == 0 + \ ? marker_chars_first . + \ repeat(' ', target_char_disp_len - 1) + \ : split(marker_chars, '\zs')[i] + + let lines[line_num]['marker'] = substitute( + \ lines[line_num]['marker'], + \ '\%' . (col_num + col_add) . 'c.', + \ escape(substitute_expr,'&'), + \ '') else - let lines[line_num]['marker'] .= strpart(target_key, c, 1) + " EOL + let lines[line_num]['marker'] .= split(marker_chars, '\zs')[i] endif - let c += 1 - endwhile + let col_add += strlen(split(marker_chars, '\zs')[i]) + endfor else " Set the line to the marker character if the line is empty - let lines[line_num]['marker'] = target_key + let lines[line_num]['marker'] = matchstr(marker_chars, '^.\{,2}') endif " -- Highlight targets ------------------- {{{ - if target_key_len == 1 + if marker_chars_len == 1 call EasyMotion#highlight#add_highlight( \ '\%' . line_num . 'l\%' . col_num . 'c', \ g:EasyMotion_hl_group_target) @@ -908,7 +930,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 + 1) . 'c', + \ '\%' . line_num . 'l\%' . (col_num + marker_chars_first_byte_len) . 'c', \ g:EasyMotion_hl2_second_group_target) endif endif @@ -916,7 +938,7 @@ function! s:PromptUser(groups) "{{{ " Add marker/target length difference for multibyte " compensation - let lines[line_num]['mb_compensation'] += + let lines[line_num]['mb_compensation'] = \ (target_line_byte_len - strlen(lines[line_num]['marker'])) endfor