Skip to content

Commit

Permalink
Fix error with detection position of cursor (fix #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimr committed Feb 20, 2014
1 parent 2a49df8 commit f89d0f6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugin/beautifier.vim
Expand Up @@ -254,7 +254,6 @@ endfunction

"Converts number of non blank characters to cursor position (line and column)
function! s:getCursorPosition(numberOfNonBlankCharactersFromTheStartOfFile)
"echo a:numberOfNonBlankCharactersFromTheStartOfFile
let lineNumber = 1
let nonBlankCount = 0
while lineNumber <= line('$')
Expand All @@ -267,21 +266,26 @@ function! s:getCursorPosition(numberOfNonBlankCharactersFromTheStartOfFile)
endif
let charIndex = charIndex + 1
if nonBlankCount == a:numberOfNonBlankCharactersFromTheStartOfFile
"echo 'found position!'
"Found position!
return {'line': lineNumber,'column': charIndex}
end
endwhile
let lineNumber = lineNumber + 1
endwhile
"echo "Oops, nothing found!"

"Oops, nothing found!
return {}
endfunction



"Restoring current position by number of non blank characters
function! s:setNumberOfNonSpaceCharactersBeforeCursor(mark,numberOfNonBlankCharactersFromTheStartOfFile)
let location = s:getCursorPosition(a:numberOfNonBlankCharactersFromTheStartOfFile)
call setpos(a:mark, [0, location.line, location.column, 0])

if !empty(location)
call setpos(a:mark, [0, location.line, location.column, 0])
endif
endfunction


Expand Down
5 changes: 5 additions & 0 deletions test/vim/issue_47/Error with detection position of cursor
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

vim -u vimrc -c "execute 'try | call setpos(\".\", [0, 0, 0]) | silent call JsBeautify() | catch | cq! | endtry' | q!" file
2 changes: 2 additions & 0 deletions test/vim/issue_47/file
@@ -0,0 +1,2 @@

{}
12 changes: 12 additions & 0 deletions test/vim/issue_47/vimrc
@@ -0,0 +1,12 @@
" vim -u vimrc
set nocompatible

set nowrap

let root = '~/.vim/bundle'

filetype off
syntax on

runtime macros/matchit.vim
exec 'set rtp+=../../../'

0 comments on commit f89d0f6

Please sign in to comment.