在查看我正在编写的包的Atom API时,它说您使用Cursor类来访问游标信息。我试图获取光标缓冲区位置,所以我尝试使用getBufferPosition()
。整行代码是:
cursorRow = atom.workspace.getActiveTextEditor().Cursor.getBufferPosition()[0]
获得该行。但是,它不断抛出这个错误:
Uncaught TypeError: Cannot read property 'getBufferPosition' of undefined
顺便说一下,这完全在CoffeeScript中。我无法弄清楚我做错了什么,因为API说getBufferPosition
是Cursor类的一个方法,所以应该可行。我究竟做错了什么?或者有更好的方法来解决这个问题吗?
提前致谢!
答案 0 :(得分:1)
您可以使用getCursorBufferPosition
of TextEditor
,即
cursorPosition = atom.workspace.getActiveTextEditor().getCursorBufferPosition()
您看到的错误告诉您文本编辑器中没有名为Cursor
的属性。 getBufferPosition
课程中可能定义了Cursor
,但您并未在Cursor
的实例上调用它,而是在undefined
上调用。