我正在编写一个简单的插件,它可以更改Sublime编辑器的全部内容,并将其替换为其他内容。这样做时
viewRegion = sublime.Region(0, self.view.size())
everything = self.view.substr(viewRegion)
self.view.replace(edit, viewRegion, everything)
视图滚动到顶部。如何防止此情况或恢复原始视口?
答案 0 :(得分:1)
作为黑客攻击,你可以保存位置并在超时时恢复它:
def format(self, edit):
self.curpos = self.view.viewport_position()
self.selection = self.view.sel()[0]
viewRegion = sublime.Region(0, self.view.size())
everything = self.view.substr(viewRegion)
# do something useful
self.view.replace(edit, viewRegion, everything)
# reestablish selection
sublime.set_timeout(self.reset_pos, 0)
def reset_pos(self):
self.view.sel().clear()
self.view.sel().add(self.selection)
self.view.set_viewport_position(self.curpos, False)