-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactored duplicate offset functions #762
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,22 @@ function! go#util#Shelllist(arglist, ...) | |
endtry | ||
endfunction | ||
|
||
" Returns the byte offset for line and column | ||
function! go#util#Offset(line, col) | ||
if &encoding != 'utf-8' | ||
let sep = go#util#LineEnding() | ||
let buf = a:line == 1 ? '' : (join(getline(1, a:line-1), sep) . sep) | ||
let buf .= a:col == 1 ? '' : getline('.')[:a:col-2] | ||
return len(iconv(buf, &encoding, 'utf-8')) | ||
endif | ||
return line2byte(a:line) + (a:col-2) | ||
endfunction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the newline ending are different for fileformat dos. For example in
that would check for that. Can you please go over the offset functions and also add these kind of edge cases into this funciton ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot, my bad. We have a function in |
||
" | ||
" Returns the byte offset for the cursor | ||
function! go#util#OffsetCursor() | ||
return go#util#Offset(line('.'), col('.')) | ||
endfunction | ||
|
||
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can | ||
" simplify the following functions | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove
s:getOffset()
and changedef.vim
to make it that it uses this directly if possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.