Restore cursor position after omnifunc call
Calling directly the omnifunc may move the cursor position. This is the case with the default Vim omnifunc for C-family languages (ccomplete#Complete) which calls searchdecl to find a declaration. This function is supposed to move the cursor to the found declaration but it doesn't when called through the omni completion mapping (CTRL-X CTRL-O). So, we restore the cursor position after calling the omnifunc.
This commit is contained in:
parent
c9be11ab81
commit
83bb78a2d6
@ -90,13 +90,22 @@ class OmniCompleter( Completer ):
|
||||
# because it affects the value returned by 'query'
|
||||
request_data[ 'start_column' ] = return_value + 1
|
||||
|
||||
# Calling directly the omnifunc may move the cursor position. This is the
|
||||
# case with the default Vim omnifunc for C-family languages
|
||||
# (ccomplete#Complete) which calls searchdecl to find a declaration. This
|
||||
# function is supposed to move the cursor to the found declaration but it
|
||||
# doesn't when called through the omni completion mapping (CTRL-X CTRL-O).
|
||||
# So, we restore the cursor position after calling the omnifunc.
|
||||
line, column = vimsupport.CurrentLineAndColumn()
|
||||
|
||||
omnifunc_call = [ self._omnifunc,
|
||||
"(0,'",
|
||||
vimsupport.EscapeForVim( request_data[ 'query' ] ),
|
||||
"')" ]
|
||||
|
||||
items = vim.eval( ''.join( omnifunc_call ) )
|
||||
|
||||
vimsupport.SetCurrentLineAndColumn( line, column )
|
||||
|
||||
if isinstance( items, dict ) and 'words' in items:
|
||||
items = items[ 'words' ]
|
||||
|
||||
|
@ -56,6 +56,12 @@ def CurrentLineAndColumn():
|
||||
return line, column
|
||||
|
||||
|
||||
def SetCurrentLineAndColumn( line, column ):
|
||||
"""Sets the cursor position to the 0-based line and 0-based column."""
|
||||
# Line from vim.current.window.cursor is 1-based.
|
||||
vim.current.window.cursor = ( line + 1, column )
|
||||
|
||||
|
||||
def CurrentColumn():
|
||||
"""Returns the 0-based current column. Do NOT access the CurrentColumn in
|
||||
vim.current.line. It doesn't exist yet when the cursor is at the end of the
|
||||
|
Loading…
Reference in New Issue
Block a user