diff options
author | Dani Megert | 2006-05-10 17:50:34 +0000 |
---|---|---|
committer | Dani Megert | 2006-05-10 17:50:34 +0000 |
commit | 5a0ca26f52dfbd45c1a123466af99078ff7a8cac (patch) | |
tree | 60f3ec96a967b1d0e24f1046c35fe5908957462b | |
parent | 3a188aeb7da6168fc460980b4ac891f72dc78c23 (diff) | |
download | eclipse.platform.text-5a0ca26f52dfbd45c1a123466af99078ff7a8cac.tar.gz eclipse.platform.text-5a0ca26f52dfbd45c1a123466af99078ff7a8cac.tar.xz eclipse.platform.text-5a0ca26f52dfbd45c1a123466af99078ff7a8cac.zip |
Fixed bugs: 140591: [typing] IndexOutOfBoundsException when inserting string literatl at beginning of document
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java index e8271e975a0..c6b4eda196e 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java @@ -172,7 +172,39 @@ public class SourceViewerDecorationSupport { gc.drawLine(x1, y1, x1, left.y + textWidget.getLineHeight(offset) - 1); } else { - textWidget.redrawRange(offset, length + 1, true); + /* + * The length for IBeam's is always 0, which causes no redraw to occur in + * StyledText#redraw(int, int, boolean). We try to normally redraw at length of one, + * and up to the line start of the next line if offset is at the end of line. If at + * the end of the document, we redraw the entire document as the offset is behind + * any content. + */ + final int contentLength= textWidget.getCharCount(); + if (offset >= contentLength) { + textWidget.redraw(); + return; + } + + char ch= textWidget.getTextRange(offset, 1).charAt(0); + if (ch == '\r' || ch == '\n') { + // at the end of a line, redraw up to the next line start + int nextLine= textWidget.getLineAtOffset(offset) + 1; + if (nextLine >= textWidget.getLineCount()) { + /* + * Panic code: should not happen, as offset is not the last offset, + * and there is a delimiter character at offset. + */ + textWidget.redraw(); + return; + } + + int nextLineOffset= textWidget.getOffsetAtLine(nextLine); + length= nextLineOffset - offset; + } else { + length= 1; + } + + textWidget.redrawRange(offset, length, true); } } } |