From c344dba8cb6458ad0164d542d97fb40c8ff638c8 Mon Sep 17 00:00:00 2001 From: Silenio Quarti Date: Mon, 6 May 2013 12:58:51 -0400 Subject: Bug 406623 - [DBCS4.3]: The first character in empty StyledText is duplicated when using custom StyledTextContent --- .../common/org/eclipse/swt/custom/StyledText.java | 11 +++-------- .../common/org/eclipse/swt/custom/StyledTextRenderer.java | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 480b18914e..b790cdf2ae 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -5792,6 +5792,9 @@ void handleCompositionChanged(Event event) { String text = event.text; int start = event.start; int end = event.end; + int charCount = content.getCharCount(); + start = Math.min(start, charCount); + end = Math.min(end, charCount); int length = text.length(); if (length == ime.getCommitCount()) { content.replaceTextRange(start, end - start, ""); @@ -7814,14 +7817,6 @@ void reset() { if (horizontalBar != null) { horizontalBar.setSelection(0); } - if (ime != null) { - String text = ime.getText(); - if (text != null && text.length() > 0 && ime.getCompositionOffset() != -1) { - ime.setCompositionOffset(0); - content.replaceTextRange(0, 0, text); - setCaretOffset(ime.getCaretOffset(), SWT.DEFAULT); - } - } resetCache(0, 0); setCaretLocation(); super.redraw(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java index f3ce6d2e24..3a441c092c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java @@ -941,6 +941,7 @@ TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpac int end = imeRanges[i*2+1] - lineOffset; TextStyle imeStyle = imeStyles[i], userStyle; for (int j = start; j <= end; j++) { + if (!(0 <= j && j < length)) break; userStyle = layout.getStyle(j); if (userStyle == null && j > 0) userStyle = layout.getStyle(j - 1); if (userStyle == null && j + 1 < length) userStyle = layout.getStyle(j + 1); -- cgit