Sublime Text创建新视图

4

我正在研究Sublime Text 2,并计划对其进行扩展。我使用CTRL'弹出控制台,尝试执行以下操作:

>>> x = window.new_file()
>>> x 
<sublime.View object at 0x00000000032EBA70>
>>> x.insert(0,"Hello") 

一个新窗口确实打开了,但我的插入似乎不起作用:
Traceback (most recent call last):   File "<string>", line 1, in <module> Boost.Python.ArgumentError: Python argument types in
        View.insert(View, int, str) did not match C++ signature:
        insert(class SP<class TextBufferView>, class SP<class Edit>, __int64, class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)

有没有想法我做错了什么?
2个回答

6
.new_file()调用返回一个View对象,因此.insert()方法需要传递3个参数:

insert(edit, point, string)
int
将给定的string插入到指定的point处。返回插入的字符数:如果当前缓冲区正在将制表符转换为空格,则可能不同。

请参阅sublime.View API 参考资料

edit参数应为一个sublime.Edit对象;您需要调用view.begin_edit()创建一个,然后调用view.end_edit(edit)来标记可撤消的编辑操作:

edit = x.begin_edit() 
x.insert(edit, 0, 'Hello')
x.end_edit(edit)
< p > Edit 对象是一个令牌,可将编辑内容分组,以便可以一步撤消。


1
@DaveF:edit是一个类型为sublime.Edit参数。使用view.begin_edit()创建它。 - Martijn Pieters

1
>>> x = window.new_file()
>>> e = x.begin_edit()
>>> x.insert(e,0,"Hello")
5
>>> x.end_edit(e)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接