Eclipse SWT StyledText 在指定位置强制设置插入符
我有一个编辑器实现,它使用 SWT StyledText 作为编辑器区域。 当使用 CTRL+S(不在工具栏上,焦点仍然存在于 StyledText 上)调用保存操作时,插入符号会丢失。因此,StyledText 不会接收下一个键盘输入。 我们需要手动单击所需的位置来激活插入符号并开始在文本框中键入内容。 我对保存前后的选择和焦点做了一些分析。
`Control beforeFocusControl = Display.getCurrent().getFocusControl();
IWorkbenchPart beforeActivePart = getActivePart();
if (beforeFocusControl instanceof StyledText) {
StyledText sText = (StyledText) beforeFocusControl;
Cursor oldCursor = sText.getCursor();
}
// save the editor
EditorWindowManager.getInstance().saveEditors(SnippetEditor);
Control afterFocusControl = Display.getCurrent().getFocusControl();
IWorkbenchPart afterActivePart = getActivePart();
// before and after there is no change in selection
// beforeFocusControl == afterFocusControl
// beforeActivePart == afterActivePart
if (afterFocusControl instanceof StyledText) {
StyledText sText = (StyledText) afterFocusControl;
//as old focus control was same i tried force setting the cursor and focus
sText.setCursor(sText.getCursor());
sText.forceFocus();
}`
焦点或工作台选择没有变化。因此,我尝试再次设置插入符号并强制聚焦 StyledText,但这并没有将插入符号恢复到上次编辑的位置。
jface 有没有方便的 api 来做到这一点?我知道它丢失之前最后出现的插入符位置。
I have an editor implementation which uses SWT StyledText as an editor area.
When Save Operation is invoked using CTRL+S (not on the toollbar, still focus is present on StyledText) caret is lost. Due to this next keyboard inputs are not received by StyledText.
We need to manually click desired positoin to activate the caret and start typing in the text box.
I did some anyalysis on selection and focus before and after save.
`Control beforeFocusControl = Display.getCurrent().getFocusControl();
IWorkbenchPart beforeActivePart = getActivePart();
if (beforeFocusControl instanceof StyledText) {
StyledText sText = (StyledText) beforeFocusControl;
Cursor oldCursor = sText.getCursor();
}
// save the editor
EditorWindowManager.getInstance().saveEditors(SnippetEditor);
Control afterFocusControl = Display.getCurrent().getFocusControl();
IWorkbenchPart afterActivePart = getActivePart();
// before and after there is no change in selection
// beforeFocusControl == afterFocusControl
// beforeActivePart == afterActivePart
if (afterFocusControl instanceof StyledText) {
StyledText sText = (StyledText) afterFocusControl;
//as old focus control was same i tried force setting the cursor and focus
sText.setCursor(sText.getCursor());
sText.forceFocus();
}`
There is no change in focus or workbench selection. So i tried to set the caret again and force focus the StyledText but this did not get back the caret to last edited location.
Is there any convenient api in jface to do this ? I know the caret position where it was last present before it was lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论