File tree Expand file tree Collapse file tree 4 files changed +41
-7
lines changed
Expand file tree Collapse file tree 4 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -128,11 +128,11 @@ setreg("o", "- [ ] ")
128128
129129# Redefinition of <cr> . Unmap if user does not want it.
130130inoremap <buffer> <silent> <CR> <ScriptCmd> funcs.CR_Hacked()<CR>
131- # if ! exists (' g:markdown_extras_config' )
132- # && has_key (g: markdown_extras_config , ' hack_CR' )
133- # && ! g: markdown_extras_config [' hack_CR' ]
134- # iunmap <buffer> <cr>
135- # endif
131+ if exists (' g:markdown_extras_config' )
132+ && has_key (g: markdown_extras_config , ' hack_CR' )
133+ && ! g: markdown_extras_config [' hack_CR' ]
134+ iunmap <buffer> <cr>
135+ endif
136136
137137nnoremap <buffer> <expr> <CR> empty(links.IsLink())
138138 \ ? '<ScriptCmd> SetLinkOpFunc()<CR> g@iw'
Original file line number Diff line number Diff line change @@ -182,6 +182,8 @@ filling it with he various keys.
182182 greater than 0.
183183 "fuzzy_search" Fuzzy or exact search in the links popup.
184184 Default: | true | .
185+ "hack_CR" Set to | false | for the standard behavior of <CR> .
186+ Default: | true | .
185187
186188
187189 *g:markdown_extras_indices*
Original file line number Diff line number Diff line change @@ -68,8 +68,6 @@ export def CR_Hacked()
6868 )
6969 item_symbol = $ " {current_line->matchstr($'^\s*{variant_4}')
7070 \ - >substitute (string (curr_nr), string (curr_nr + 1 ), ' ' )}"
71- # elseif current_line = ~ $ ' ^\s\+'
72- # item_symbol = $ " {current_line->matchstr($'^\s\+ ')}"
7371 endif
7472 return item_symbol
7573 enddef
@@ -106,6 +104,12 @@ export def CR_Hacked()
106104 endwhile
107105 endif
108106
107+ # if item_symbol = ' ' it may still mean that we are not in an item list but
108+ # yet we have an indendent line , hence, we must preserve the leading spaces
109+ if empty (item_symbol)
110+ item_symbol = $ " {getline('.')->matchstr($'^\s\+ ')}"
111+ endif
112+
109113 # The following is in case the cursor is on the lhs of the item_symbol
110114 if col (' .' ) < len (item_symbol)
111115 if current_line = ~ $ ' ^\s*{variant_4}'
Original file line number Diff line number Diff line change @@ -251,3 +251,31 @@ def g:Test_CR_hacked_wrapped_lines()
251251 :% bw !
252252 Cleanup_testfile (src_name_1)
253253enddef
254+
255+
256+ def g: Test_CR_hacked_preserve_indent ()
257+ # OBS! normal shall be without ! because we are testing <CR> which is
258+ # hacked!
259+ Generate_testfile (lines_1, src_name_1)
260+ vnew
261+ exe $ " edit {src_name_1}"
262+ setlocal spell spelllang = la
263+
264+ const test_string = " \<space>\<space>\<space>\<space>\<space> today\<space> is"
265+ .. " \<space> a\<cr> beautiful\<space> day"
266+
267+ const expected_lines_35_39 = [
268+ ' ' ,
269+ ' today is a' ,
270+ ' beautiful day' ,
271+ ' ' ,
272+ ' ciao' ,
273+ ]
274+
275+ execute $ " silent norm Go\<cr> {test_string}\<cr>\<cr> ciao"
276+
277+ echom assert_equal (expected_lines_35_39, getline (35 , 39 ))
278+
279+ :% bw !
280+ Cleanup_testfile (src_name_1)
281+ enddef
You can’t perform that action at this time.
0 commit comments