Skip to content

Commit

Permalink
Merge branch 'master' into caching_bullets_for_performance
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 authored Aug 3, 2024
2 parents 3598248 + 448ad2a commit b6b184b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
22 changes: 15 additions & 7 deletions plugin/bullets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ fun! s:match_checkbox_bullet_item(input_text)
" match any symbols listed in g:bullets_checkbox_markers as well as the
" default ' ', 'x', and 'X'
let l:checkbox_bullet_regex =
\ '\v(^(\s*)([-\*] \[(['
\ '\v(^(\s*)([+-\*] \[(['
\ . g:bullets_checkbox_markers
\ . ' xX])?\])(\s+))(.*)'
\ . ' xX])?\])(:?)(\s+))(.*)'
let l:matches = matchlist(a:input_text, l:checkbox_bullet_regex)

if empty(l:matches)
Expand All @@ -301,16 +301,17 @@ fun! s:match_checkbox_bullet_item(input_text)
let l:leading_space = l:matches[2]
let l:bullet = l:matches[3]
let l:checkbox_marker = l:matches[4]
let l:trailing_space = l:matches[5]
let l:text_after_bullet = l:matches[6]
let l:trailing_char = l:matches[5]
let l:trailing_space = l:matches[6]
let l:text_after_bullet = l:matches[7]

return {
\ 'bullet_type': 'chk',
\ 'bullet_length': l:bullet_length,
\ 'leading_space': l:leading_space,
\ 'bullet': l:bullet,
\ 'checkbox_marker': l:checkbox_marker,
\ 'closure': '',
\ 'closure': l:trailing_char,
\ 'trailing_space': l:trailing_space,
\ 'text_after_bullet': l:text_after_bullet
\ }
Expand Down Expand Up @@ -631,14 +632,21 @@ command! InsertNewBullet call <SID>insert_new_bullet()
" Helper for Colon Indent
" returns 1 if current line ends in a colon, else 0
fun! s:line_ends_in_colon(lnum)
return getline(a:lnum)[strlen(getline(a:lnum))-1:] ==# ':'
let l:line = getline(a:lnum)
if exists("*strcharlen") && exists("*strgetchar")
let l:last_char_nr = strgetchar(l:line, strcharlen(l:line)-1)
return l:last_char_nr == 65306 || l:last_char_nr == 58
else
" Older versions of vim do not support strchar*
return l:line[strlen(l:line)-1:] ==# ':'
endif
endfun
" --------------------------------------------------------- }}}

" Checkboxes ---------------------------------------------- {{{
fun! s:find_checkbox_position(lnum)
let l:line_text = getline(a:lnum)
return matchend(l:line_text, '\v\s*(\*|-) \[')
return matchend(l:line_text, '\v\s*(\*|-|\+) \[')
endfun

fun! s:select_checkbox(inner)
Expand Down
27 changes: 27 additions & 0 deletions spec/nested_bullets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,33 @@
\ti. this bullet is indented
\tii. this bullet is also indented
TEXT

write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT

vim.command 'let g:bullets_auto_indent_after_colon = 1'
vim.edit filename
vim.feedkeys '\<ESC>'
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'this is the second bullet that ends with fullwidth colon:'
vim.feedkeys '\<cr>'
vim.type 'this bullet is indented'
vim.feedkeys '\<cr>'
vim.type 'this bullet is also indented'
vim.write

file_contents = IO.read(filename)

expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. this is the second bullet that ends with fullwidth colon:
\ti. this bullet is indented
\tii. this bullet is also indented
TEXT
end
end
end

0 comments on commit b6b184b

Please sign in to comment.