mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Include the header when deleting columns
This commit is contained in:
@@ -31,12 +31,31 @@ function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#GetFirstRowOrHeader(line) "{{{2
|
||||
if tablemode#table#IsRow(a:line)
|
||||
let line = tablemode#utils#line(a:line)
|
||||
|
||||
while tablemode#table#IsTable(line - 1)
|
||||
let line -= 1
|
||||
endwhile
|
||||
if tablemode#table#IsBorder(line) | let line += 1 | endif
|
||||
|
||||
return line
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#MoveToFirstRow() "{{{2
|
||||
if tablemode#table#IsRow('.')
|
||||
call cursor(tablemode#spreadsheet#GetFirstRow('.'), col('.'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#MoveToFirstRowOrHeader() "{{{2
|
||||
if tablemode#table#IsRow('.')
|
||||
call cursor(tablemode#spreadsheet#GetFirstRowOrHeader('.'), col('.'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
||||
if tablemode#table#IsRow(a:line)
|
||||
let line = tablemode#utils#line(a:line)
|
||||
@@ -142,7 +161,7 @@ function! tablemode#spreadsheet#DeleteColumn() "{{{2
|
||||
if tablemode#table#IsRow('.')
|
||||
for i in range(v:count1)
|
||||
call tablemode#spreadsheet#MoveToStartOfCell()
|
||||
call tablemode#spreadsheet#MoveToFirstRow()
|
||||
call tablemode#spreadsheet#MoveToFirstRowOrHeader()
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
call tablemode#spreadsheet#MoveToLastRow()
|
||||
normal! d
|
||||
|
||||
9
t/fixtures/complex_header.txt
Normal file
9
t/fixtures/complex_header.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
|----------+----------+----------+----------|
|
||||
| counting | backward | alphabet | backward |
|
||||
|:========:+:=========+=========:+==========|
|
||||
| 1 | 9 | a | z |
|
||||
| 2 | 8 | b | y |
|
||||
| 3 | 7 | c | x |
|
||||
| 4 | 6 | d | w |
|
||||
| 5 | 5 | e | v |
|
||||
|----------+----------+----------+----------|
|
||||
@@ -103,6 +103,30 @@ describe 'spreadsheet'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Manipulation of tables with headers'
|
||||
before
|
||||
new
|
||||
normal! ggdG
|
||||
let g:table_mode_header_fillchar = '='
|
||||
read t/fixtures/complex_header.txt
|
||||
call cursor(4, 7)
|
||||
end
|
||||
|
||||
it 'should successfully delete a row '
|
||||
Expect tablemode#spreadsheet#RowCount('.') == 5
|
||||
call tablemode#spreadsheet#DeleteRow()
|
||||
Expect tablemode#spreadsheet#RowCount('.') == 4
|
||||
Expect getline(4) == '| 2 | 8 | b | y |'
|
||||
end
|
||||
|
||||
it 'should successfully delete a column'
|
||||
Expect tablemode#spreadsheet#ColumnCount('.') == 4
|
||||
call tablemode#spreadsheet#DeleteColumn()
|
||||
Expect tablemode#spreadsheet#ColumnCount('.') == 3
|
||||
Expect getline(4) == '| 9 | a | z |'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Repeated Manipulations'
|
||||
before
|
||||
new
|
||||
|
||||
Reference in New Issue
Block a user