本文整理汇总了Python中common.selection.Selection.get_position方法的典型用法代码示例。如果您正苦于以下问题:Python Selection.get_position方法的具体用法?Python Selection.get_position怎么用?Python Selection.get_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.selection.Selection
的用法示例。
在下文中一共展示了Selection.get_position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context
# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import get_position [as 别名]
def get_context(view):
valid = True
valid_needle = True
position = Selection.get_position(view)
# regions
word_region = view.word(position)
line_region = view.line(position)
pre_region = sublime.Region(line_region.a, word_region.a)
post_region = sublime.Region(word_region.b, line_region.b)
# text
line = view.substr(line_region)
word = view.substr(word_region)
pre = view.substr(pre_region)
post = view.substr(post_region)
needle_region = view.word(position)
# st2: unmutable region
needle_start = needle_region.a
needle_end = needle_region.b
# grab everything in 'separators'
needle = ""
separator = False
pre_match = ""
# search for a separator before current word, i.e. <">path/to/<position>
pre_quotes = re.search("(["+NEEDLE_SEPARATOR_BEFORE+"])([^"+NEEDLE_SEPARATOR+"]*)$", pre)
if pre_quotes:
needle += pre_quotes.group(2) + word
separator = pre_quotes.group(1)
pre_match = pre_quotes.group(2)
needle_start -= len(pre_quotes.group(2))
else:
# use whitespace as separator
pre_quotes = re.search("(\s)([^"+NEEDLE_SEPARATOR+"\s]*)$", pre)
if pre_quotes:
needle = pre_quotes.group(2) + word
separator = pre_quotes.group(1)
pre_match = pre_quotes.group(2)
needle_start -= len(pre_quotes.group(2))
if pre_quotes:
post_quotes = re.search("^(["+NEEDLE_SEPARATOR_AFTER+"]*)", post)
if post_quotes:
needle += post_quotes.group(1)
needle_end += len(post_quotes.group(1))
else:
print("no post quotes found => invalid")
valid = False
elif not re.search("["+NEEDLE_INVALID_CHARACTERS+"]", needle):
needle = pre + word
needle_start = pre_region.a
else:
needle = word
needle_region = sublime.Region(needle_start, needle_end)
# grab prefix
prefix_region = sublime.Region(line_region.a, pre_region.b - len(pre_match) - 1)
prefix_line = view.substr(prefix_region)
# # print("prefix line", prefix_line)
#define? (["...", "..."]) -> before?
# before: ABC =:([
prefix = re.search("\s*(["+NEEDLE_CHARACTERS+"]+)["+DELIMITER+"]*$", prefix_line)
if prefix is None:
# validate array, like define(["...", ".CURSOR."])
prefix = re.search("^\s*(["+NEEDLE_CHARACTERS+"]+)["+DELIMITER+"]+", prefix_line)
if prefix:
# print("prefix:", prefix.group(1))
prefix = prefix.group(1)
tag = re.search("<\s*(["+NEEDLE_CHARACTERS+"]*)\s*[^>]*$", prefix_line)
if tag:
tag = tag.group(1)
# print("tag:", tag)
style = re.search("[\s\"\'']*(["+NEEDLE_CHARACTERS+"]*)[\s\"\']*\:[^\:]*$", prefix_line)
if style:
style = style.group(1)
# print("style:", style)
if separator is False:
# print("context", "separator undefined => invalid", needle)
valid = False
elif re.search("["+NEEDLE_INVALID_CHARACTERS+"]", needle):
# print("context", "invalid characters in needle => invalid", needle)
valid_needle = False
valid = False
elif prefix is None and separator.strip() == "":
# print("context", "prefix undefined => invalid", needle)
valid = False
#.........这里部分代码省略.........