Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions plugin/bullets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,21 @@ fun! s:insert_new_bullet()
" searching up from there
let l:send_return = 1
let l:normal_mode = mode() ==# 'n'
let l:insert_mode = mode() ==# 'i'
let l:indent_next = s:line_ends_in_colon(l:curr_line_num) && g:bullets_auto_indent_after_colon
let l:text_after_cursor = ''

" check if current line is a bullet
if l:bullet != {}
" check whether we're in the middle of the line (for insert mode only)
if !s:is_at_eol() && !s:is_at_first_col() && l:insert_mode
let l:col = col('.')
let l:curr_line = getline('.')
let l:text_before_cursor = l:curr_line[:l:col-2]
let l:text_after_cursor = l:curr_line[l:col-1:]
call setline(l:curr_line_num, l:text_before_cursor)
endif

" check if current line is a bullet and we are at the end of the line (for
" insert mode only)
if l:bullet != {} && (l:normal_mode || s:is_at_eol())
" was any text entered after the bullet?
if l:bullet.text_after_bullet ==# ''
" We don't want to create a new bullet if the previous one was not used,
Expand All @@ -598,6 +608,10 @@ fun! s:insert_new_bullet()
let l:next_bullet_list = [s:pad_to_length(l:next_bullet, l:bullet.bullet_length)]
endif

if l:text_after_cursor !=# ''
let l:next_bullet_list[0] = l:next_bullet_list[0] . l:text_after_cursor
endif

" prepend blank lines if desired
if g:bullets_line_spacing > 1
let l:next_bullet_list += map(range(g:bullets_line_spacing - 1), '""')
Expand All @@ -610,7 +624,11 @@ fun! s:insert_new_bullet()

" go to next line after the new bullet
let l:col = strlen(getline(l:next_line_num)) + 1
call setpos('.', [0, l:next_line_num, l:col])
if l:text_after_cursor ==# ''
call setpos('.', [0, l:next_line_num, l:col])
else
call setpos('.', [0, l:next_line_num, l:bullet.bullet_length + 1])
endif

" indent if previous line ended in a colon
if l:indent_next
Expand Down Expand Up @@ -645,6 +663,10 @@ fun! s:is_at_eol()
return strlen(getline('.')) + 1 ==# col('.')
endfun

fun! s:is_at_first_col()
return col('.') ==# 1
endfun

command! InsertNewBullet call <SID>insert_new_bullet()

" Helper for Colon Indent
Expand Down
1 change: 0 additions & 1 deletion spec/asciidoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
end

it 'supports nested dot bullets' do
pending('FIXME: this test fails, but the functionality works')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was causing tests to fail. Happy to add it back if needed.

test_bullet_inserted('rats', <<-INIT, <<-EXPECTED)
= Pets!
. dogs
Expand Down
48 changes: 24 additions & 24 deletions spec/bullets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@

RSpec.describe 'Bullets.vim' do
describe 'inserting new bullets' do
context 'on return key when cursor is not at EOL' do
it 'splits the line and does not add a bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
- this is the first bullet
TEXT

vim.edit filename
vim.type 'G$i'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
- this is the first bulle
second bullett\n
TEXT
end
end

context 'on return key when cursor is at EOL' do
it 'adds a new bullet if the previous line had a known bullet type' do
test_bullet_inserted('do that', <<-INIT, <<-EXPECTED)
Expand Down Expand Up @@ -57,6 +33,30 @@
EXPECTED
end

context 'on return key when cursor is not at EOL' do
it 'splits the line and adds a new bullet if the previous line had a known bullet type' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
- this is the first bullet
TEXT

vim.edit filename
vim.type 'G$i'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
- this is the first bulle
- second bullett\n
TEXT
end
end

it 'adds a pandoc bullet if the prev line had one' do
test_bullet_inserted('second bullet', <<-INIT, <<-EXPECTED)
Hello there
Expand Down
Loading