diff --git a/autoload/tablemode/spreadsheet.vim b/autoload/tablemode/spreadsheet.vim index 071793c..750bda2 100644 --- a/autoload/tablemode/spreadsheet.vim +++ b/autoload/tablemode/spreadsheet.vim @@ -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 - diff --git a/t/fixtures/formula/formula.txt b/t/fixtures/formula/formula.txt index 6c6a190..ab2df91 100644 --- a/t/fixtures/formula/formula.txt +++ b/t/fixtures/formula/formula.txt @@ -4,4 +4,4 @@ | Tomatoes | 5 | | Pasta | 100 | | Total | 0 | -/* tmf: $5,2=Sum(1:-1) */ +/* tmf: $4,2=Sum(1:-1) */ diff --git a/t/formula.vim b/t/formula.vim index bfd1566..d220788 100644 --- a/t/formula.vim +++ b/t/formula.vim @@ -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