| Summary: | [jface] TextViewer.setVisibleRegion begins at offset line's start | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Patrick Konemann <patrick.koenemann> |
| Component: | Text | Assignee: | Platform-Text-Inbox <platform-text-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | Andreas.Muelder, daniel_megert, nyssen, remy.suen |
| Version: | 3.7 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Text owns this code. This looks like a bug on your end.
int line= master.getLineOfOffset(modelRangeOffset);
This gets the line which contains the start offset
offset= master.getLineOffset(line);
This computes the start of the line, which means this offset <= start offset and hence includes the start offset. The length is adjusted accordingly.
The start offset is honored but the it is adjusted to start at the beginning of the line and same for the end offset. This is as specified by ProjectViewer: it only supports full line projections.
We are confused, according to the JavaDoc in ITextViewer.setVisibleRegion(): * Defines and sets the region of this viewer's document which will be * visible in the presentation. Every character inside the specified region * is supposed to be visible in the viewer's widget after that call. This does not say anything about lines. And since updateSlaveDocument is directly called in TextViewer.setVisibleRegion, we would expect the offset to be honored per character and not only per line. Otherwise this function would not make any sense in single-line texts. Another point is that setVisibleRegion works for cutting the end of a line (it does not keep the entire line). But you are using a ProjectViewer which refines the contract. If you use a TextViewer then it should work. >But you are using a ProjectViewer
ProjectionViewer
(In reply to comment #4) > But you are using a ProjectViewer which refines the contract. If you use a > TextViewer then it should work. Mmh - looking at the old implementation in TextViewer.updateVisibleDocument(...) I think also TextViewer doesn't work as you'd expect. We always take the full first line and this is not against the contract which only says that the characters in the given range are supposed to be visible. It doesn't say anything about cutting text at the beginning of the first line. Cutting at the beginning can be a problem for existing code which computes things relative to the line start. We won't change that behavior. If you really need this you can either implement your own viewer or we turn this bug into a feature request for adding new API that behaves the way you want it. Ok, thank you for the clarifications. We'll then change this default behaviour in a subclass. |
When setting the visible region for a text viewer via TextViewer.setVisibleRegion(start, length), parameter 'start' is ignored. The cause is apparently ProjectionViewer.updateSlaveDocument in which the offset is calculated with respect to multi-line documents. Instead of *adding* the line offset to the specified offset, the code *replaces* the specified offset with the line offset: if (!isProjectionMode()) { // mimic original TextViewer behavior IDocument master= projection.getMasterDocument(); int line= master.getLineOfOffset(modelRangeOffset); offset= master.getLineOffset(line); length= (modelRangeOffset - offset) + modelRangeLength; } Changing the offset assignment to the following works for us: offset+= master.getLineOffset(line);