Eclipse:Get 并设置编辑器的插入符号位置
Eclipse:Get and set caret position of the editor
我正在为 Eclipse 开发语音识别插件。例如,当我编写代码时,我可以简单地说 "for" 并且 "for(){}" 将被打印到编辑器。但是,当光标的范围超出 Eclipse 范围时,它工作得很好,例如当我点击浏览器搜索时,我所说的下一件事将打印在这里,而不是 Eclipse 编辑器。
有没有办法在 Eclipse 编辑器超出范围时找出插入符号位置,因为当您单击 Eclipse 的任何部分时 UI 旧插入符号位置会弹出.
我也在使用 Java机器人 API 将字符串模拟到屏幕上。我不相信它有设置插入符号位置的选项,只有 courser 位置。
更新:只需要文本编辑器插入符号位置 x 和 y 坐标,我可以使用 Java 机器人移动鼠标(插入符号位置 x,y)并按下鼠标来带来日食在任何模拟发生之前平台回到范围。
假设您有 IEditorPart
您感兴趣的,您可以使用以下方法获得插入符号位置:
IEditorPart editor = .... get part ..
Control control = editor.getAdapter(Control.class);
// For a text editor the control will be StyledText
if (control instanceof StyledText) {
StyledText text = (StyledText)control;
// Position of caret relative to top left of the control
Point relPos = text.getLocationAtOffset(text.getCaretOffset());
// Position relative to display
Point absPos = textWidget.toDisplay(relPos);
}
我正在为 Eclipse 开发语音识别插件。例如,当我编写代码时,我可以简单地说 "for" 并且 "for(){}" 将被打印到编辑器。但是,当光标的范围超出 Eclipse 范围时,它工作得很好,例如当我点击浏览器搜索时,我所说的下一件事将打印在这里,而不是 Eclipse 编辑器。
有没有办法在 Eclipse 编辑器超出范围时找出插入符号位置,因为当您单击 Eclipse 的任何部分时 UI 旧插入符号位置会弹出.
我也在使用 Java机器人 API 将字符串模拟到屏幕上。我不相信它有设置插入符号位置的选项,只有 courser 位置。
更新:只需要文本编辑器插入符号位置 x 和 y 坐标,我可以使用 Java 机器人移动鼠标(插入符号位置 x,y)并按下鼠标来带来日食在任何模拟发生之前平台回到范围。
假设您有 IEditorPart
您感兴趣的,您可以使用以下方法获得插入符号位置:
IEditorPart editor = .... get part ..
Control control = editor.getAdapter(Control.class);
// For a text editor the control will be StyledText
if (control instanceof StyledText) {
StyledText text = (StyledText)control;
// Position of caret relative to top left of the control
Point relPos = text.getLocationAtOffset(text.getCaretOffset());
// Position relative to display
Point absPos = textWidget.toDisplay(relPos);
}