Altered table mode behavior such that if there is a header line, i.e.
the first line of the table is separated by a border with the rest of
the table, then it is not taken into account for formulas and cell
arithmetic
This commit is contained in:
Dhruva Sagar
2014-08-15 09:40:29 +05:30
parent 8683146a5f
commit 761a67b36b
3 changed files with 8 additions and 35 deletions

View File

@@ -22,7 +22,7 @@ function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
if tablemode#table#IsRow(a:line)
let line = tablemode#utils#line(a:line)
while tablemode#table#IsRow(line - 1) || tablemode#table#IsBorder(line - 1)
while !tablemode#table#IsHeader(line - 1) && (tablemode#table#IsRow(line - 1) || tablemode#table#IsBorder(line - 1))
let line -= 1
endwhile
if tablemode#table#IsBorder(line) | let line += 1 | endif
@@ -77,7 +77,7 @@ function! tablemode#spreadsheet#RowNr(line) "{{{2
let line = tablemode#utils#line(a:line)
let rowNr = 0
while tablemode#table#IsRow(line) || tablemode#table#IsBorder(line)
while !tablemode#table#IsHeader(line) && (tablemode#table#IsRow(line) || tablemode#table#IsBorder(line))
if tablemode#table#IsRow(line) | let rowNr += 1 | endif
let line -= 1
endwhile
@@ -89,13 +89,13 @@ function! tablemode#spreadsheet#RowCount(line) "{{{2
let line = tablemode#utils#line(a:line)
let [tline, totalRowCount] = [line, 0]
while tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline)
while !tablemode#table#IsHeader(tline) && (tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline))
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
let tline -= 1
endwhile
let tline = line + 1
while tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline)
while !tablemode#table#IsHeader(tline) && (tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline))
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
let tline += 1
endwhile
@@ -138,32 +138,6 @@ function! tablemode#spreadsheet#MoveToStartOfCell() "{{{2
endif
endfunction
function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
if tablemode#table#IsRow(a:line)
let line = tablemode#utils#line(a:line)
while tablemode#table#IsRow(line - 1) || tablemode#table#IsBorder(line - 1)
let line -= 1
endwhile
if tablemode#table#IsBorder(line) | let line += 1 | endif
return line
endif
endfunction
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
if tablemode#table#IsRow(a:line)
let line = tablemode#utils#line(a:line)
while tablemode#table#IsRow(line + 1) || tablemode#table#IsBorder(line + 1)
let line += 1
endwhile
if tablemode#table#IsBorder(line) | let line -= 1 | endif
return line
endif
endfunction
function! tablemode#spreadsheet#DeleteColumn() "{{{2
if tablemode#table#IsRow('.')
for i in range(v:count1)
@@ -205,4 +179,3 @@ function! tablemode#spreadsheet#Average(range, ...) abort "{{{2
call insert(args, a:range)
return s:Average(call('tablemode#spreadsheet#cell#GetCellRange', args))
endfunction

View File

@@ -4,4 +4,4 @@
| Tomatoes | 5 |
| Pasta | 100 |
| Total | 0 |
/* tmf: $5,2=Sum(1:-1) */
/* tmf: $4,2=Sum(1:-1) */

View File

@@ -10,16 +10,16 @@ describe 'Formulas'
it 'should add a formula successfully'
call cursor(6, 15)
call tablemode#spreadsheet#formula#Add("Sum(1:4)")
call tablemode#spreadsheet#formula#Add("Sum(1:3)")
Expect tablemode#spreadsheet#cell#GetCell() == '125.0'
call cursor(8, 15)
Expect getline('.') == '/* tmf: $5,2=Sum(1:4) */'
Expect getline('.') == '/* tmf: $4,2=Sum(1:3) */'
call cursor(7, 15)
call tablemode#spreadsheet#formula#Add("Sum(1:-1)")
Expect tablemode#spreadsheet#cell#GetCell() == '250.0'
call cursor(8, 15)
Expect getline('.') == '/* tmf: $5,2=Sum(1:4) ; $6,2=Sum(1:-1) */'
Expect getline('.') == '/* tmf: $4,2=Sum(1:3) ; $5,2=Sum(1:-1) */'
end
end