| Summary: | getSourceViewer() in AbstractTextEditor should be public | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Prashant Deva <prashant.deva> |
| Component: | Text | Assignee: | Platform-Text-Inbox <platform-text-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | daniel_megert, remy.suen |
| Version: | 3.6 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
|
Description
Prashant Deva
We don't want to encourage accessing the source viewer. If you write your own editor you're free to expose it to the public. (In reply to comment #1) > We don't want to encourage accessing the source viewer. If you write your own > editor you're free to expose it to the public. That was the question. *Why* dont you want to expose the source viewer? If you are ok with exposing the underlying styled text widget what is the reason for not exposing the source viewer. Not exposing it means simple tasks like a plugin wanting to know the current cursor position are not possible. (In reply to comment #2) > Not exposing it means simple tasks like a plugin wanting to know the current > cursor position are not possible. Could you not retrieve this from the selection provider (ITextSelection)? (In reply to comment #3) > (In reply to comment #2) > > Not exposing it means simple tasks like a plugin wanting to know the current > > cursor position are not possible. > > Could you not retrieve this from the selection provider (ITextSelection)? No that works only when a full block of text is selected. I want to know the line no whenever the cursor moves. This involves setting a caretlistener on the styled text widget and then using the *source viewer* to get the actual line no. You cannot get the line no from the text widget due to issue of folding thus source viewer is needed. (In reply to comment #4) > No that works only when a full block of text is selected. I want to know the > line no whenever the cursor moves. I think there's still a way to get this with public APIs but not sure off-hand. Dani would know for sure. > This involves setting a caretlistener on the styled text widget and then using > the *source viewer* to get the actual line no. > > You cannot get the line no from the text widget due to issue of folding thus > source viewer is needed. Is the line information from the editor's IDocument no good?
> Is the line information from the editor's IDocument no good?
No, because lines in the source viewer can get folded, thus it wont be correct.
Thats why sourceviewer has a widgetOffset2ModelOffset() method, to get the right line no.
Look at AbstractTextEditor.getCursorPosition() method.
As you will notice you *need* the source viewer to get the correct caret position.
>No, because lines in the source viewer can get folded, thus it wont be correct.
This information is present in the projection document itself (see projection mapping).
How does one get to the projection document? All the AbstractTextEditor allows you to get to is the StyledText which has no concept of documents or viewers. (In reply to comment #8) > How does one get to the projection document? > All the AbstractTextEditor allows you to get to is the StyledText which has no > concept of documents or viewers. From the editor via document provider. It provides a document which is not a projection document and has no connection to projection mapping. To add more info, the instance of IDocument returned for a JDT java text editor is SynchronizableDocument which has no connection to any projection mapping or projection document. Right, the Java editor does not give you the projection document. If you don't own the editor then you can use the selection listener Remy already mentioned. If you need to get the event for each caret change, then you need to add a post selection changed listener. It really doesn't help if you continue to reopen the bug as we won't make add API. the problem is not about listening to the current selection. I know i can add a selection listener, but say I want this: I want to know the current line number of the selection and get the text of the line. The selection listener method doesnt work in this case because it gives a widget offset when a model offset is needed. To convert to widget offset I need the sourceviewer to call its widgetOffset2ModelOffset(offset) method. (In reply to comment #13) > the problem is not about listening to the current selection. I know i can add a > selection listener, but say I want this: > > I want to know the current line number of the selection and get the text of the > line. > > The selection listener method doesnt work in this case because it gives a > widget offset No it does not. Just make sure you use the listener on the part and not the widget. |