【发布时间】:2013-11-02 05:44:34
【问题描述】:
我为sublme text 3 开发插件。我需要最接近光标字的代码。
例如,如果我将光标放在图像上...
...这个插件应该返回单词run
....或至少编号10,对应于4行中字符u的位置:
然后我将能够从数字10 和行文本4 中获取单词run。
但现在我只能得到 linetext 光标所在的位置:
import sublime, sublime_plugin
class line_nearest_to_cursor_wordCommand(sublime_plugin.WindowCommand):
def run(self):
print('line_nearest_to_cursor_word called')
view = self.window.active_view()
region1 = view.sel()[0]
line = view.line(region1)
linetext = view.substr(line)
print(linetext)
当我打印 region1 时,它给出了两个数字,但它们很奇怪:
print (region1) # prints (113, 113), but 113 is not position of char "u" in line " def run(self):"
所以问题归结为写法getXcoordPositionOnLine...
xCoord = getXcoordPositionOnLine(region1)
print xCoord
... 这会给我光标在行上的 x 位置。
或者也许有更好的解决方案。
【问题讨论】:
标签: python plugins sublimetext2 sublimetext sublimetext3