From d3c0efa94b11c766b17f4670a7e8438e97a87bdc Mon Sep 17 00:00:00 2001 From: Felipe Heidrich Date: Tue, 28 Feb 2012 12:13:10 -0500 Subject: Bug 372760 - segments offset should be more flexible --- .../org/eclipse/swt/custom/BidiSegmentEvent.java | 5 ++-- .../common/org/eclipse/swt/custom/StyledText.java | 27 ++++------------------ .../org/eclipse/swt/events/SegmentEvent.java | 5 ++-- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java index b688cb6368..06b714b7c6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java @@ -26,12 +26,11 @@ import org.eclipse.swt.events.*; * a segment relative to the start of the line. They must follow * the following rules: * - * In addition, the last element may be set to the end of the line - * but this is not required. + * In addition, the first element may be set to zero and the last element may + * be set to the end of the line but this is not required. * * The segments field may be left null if the entire line should * be reordered as is. 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 edb5b6a6b1..75de2c0edb 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 @@ -4776,30 +4776,13 @@ StyledTextEvent getBidiSegments(int lineOffset, String line) { if (event == null || event.segments == null || event.segments.length == 0) return null; int lineLength = line.length(); int[] segments = event.segments; - int segmentCount = segments.length; - if (event.segmentsChars == null) { - // test segment index consistency - if (segments[0] != 0) { + if (segments[0] > lineLength) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + for (int i = 1; i < segments.length; i++) { + if (segments[i] <= segments[i - 1] || segments[i] > lineLength) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - for (int i = 1; i < segmentCount; i++) { - if (segments[i] <= segments[i - 1] || segments[i] > lineLength) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - // ensure that last segment index is line end offset - if (segments[segmentCount - 1] != lineLength) { - segments = new int[segmentCount + 1]; - System.arraycopy(event.segments, 0, segments, 0, segmentCount); - segments[segmentCount] = lineLength; - } - event.segments = segments; - } else { - for (int i = 1; i < segmentCount; i++) { - if (event.segments[i] < event.segments[i - 1] || event.segments[i] > lineLength) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } } return event; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SegmentEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SegmentEvent.java index 99d1b0f312..336cebf359 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SegmentEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SegmentEvent.java @@ -22,12 +22,11 @@ import org.eclipse.swt.widgets.Event; * The elements in the segments field specify the start offset of a segment * relative to the start of the text. They must follow the following rules: * - * In addition, the last element may be set to the end of the text but this is - * not required. + * In addition, the first element may be set to zero and the last element may + * be set to the end of the line but this is not required. * * The segments field may be left null if the entire text content doesn't * require segmentation. -- cgit v1.2.3