我为sublme text 3
开发插件。我需要获得最接近游标字的代码。离光标字最近的代码
例如,如果我得到的游标,图像...
...这个插件应该返回字run
....或者至少数10
对应位置char u
in line 4
:
然后我就可以从号码得到word run
10和文本行4
。
但现在我只能得到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
..这会给我一个光标在线的位置。
或者也许有更好的解决方案。
谢谢澄清 –