简体   繁体   中英

Move cursor after selected an item in autocompletion list

I implemented a Autocompletion plugin for SublimeText

import sublime_plugin
import sublime

tensorflow_functions = ["tf.AggregationMethod()","tf.Assert()","tf.AttrValue()","tf.AttrValue.ListValue()", etc...]

class TensorflowAutocomplete(sublime_plugin.EventListener):

    def __init__(self):

        self.tf_completions = [("%s \tTensorflow" % s, s) for s in tensorflow_functions]

    def on_query_completions(self, view, prefix, locations):

        if view.match_selector(locations[0], 'source.python'):
            return self.tf_completions
        else:
            return[]

Is there any ways I can move the cursor into the parenthesis when the user selected an item in the autocompletion list? I didn't tried anything because I can't find what I want in the API documentation.

You can just use snippets in the completions, so you change tf.Assert() to tf.Assert($1) (jump out with tab) or tf.Assert($0)

If all parens are empty you can just change your code to:

self.tf_completions = [("%s \tTensorflow" % s, s.replace("()", "($1)") for s in tensorflow_functions]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM