Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Thoms2017-10-13 15:16:55 -0400
committerAlexander Kurtakov2018-01-03 07:41:01 -0500
commit3df8f29f3617867ae37ef815827c463878f4f218 (patch)
treedfd085dcbf5be22aed9ee52bb583b3d317c71386 /org.eclipse.ui.workbench.texteditor
parente76fdc71f32c1c24eb4a7541357fc4ec9309ec75 (diff)
downloadeclipse.platform.text-3df8f29f3617867ae37ef815827c463878f4f218.tar.gz
eclipse.platform.text-3df8f29f3617867ae37ef815827c463878f4f218.tar.xz
eclipse.platform.text-3df8f29f3617867ae37ef815827c463878f4f218.zip
Bug 522103 - Refactor usage of StyledText#getOffsetAtLocation(Point)I20180104-2000I20180104-0030I20180103-2000
Refactored usages of StyledText#getOffsetAtLocation(), which throws an IAE when no character is at the given point. The new method returns -1 as return code, which is evaluated and try-catch blocks are avoided. Adjusted lower bound for org.eclipse.swt Change-Id: I1980f14b95926ca0e13044670101caa73ff1dcbd Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
Diffstat (limited to 'org.eclipse.ui.workbench.texteditor')
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java27
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java2
3 files changed, 15 insertions, 15 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index 4ab2c9ddb..a10ac2374 100644
--- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
@@ -26,6 +26,7 @@ Require-Bundle:
org.eclipse.compare.core;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.100,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.8.0,4.0.0)",
+ org.eclipse.swt;bundle-version="[3.107.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.ibm.icu.text
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
index 0ad4a48a3..965f311cc 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
@@ -1902,21 +1902,20 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
if (document == null)
return -1;
- try {
- int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y));
- Point p= styledText.getLocationAtOffset(widgetOffset);
- if (p.x > x)
- widgetOffset--;
-
- if (textViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer;
- return extension.widgetOffset2ModelOffset(widgetOffset);
- }
- IRegion visibleRegion= textViewer.getVisibleRegion();
- return widgetOffset + visibleRegion.getOffset();
- } catch (IllegalArgumentException e) {
+ int widgetOffset = styledText.getOffsetAtPoint(new Point(x, y));
+ if (widgetOffset == -1) {
return -1;
}
+ Point p = styledText.getLocationAtOffset(widgetOffset);
+ if (p.x > x)
+ widgetOffset--;
+
+ if (textViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
+ return extension.widgetOffset2ModelOffset(widgetOffset);
+ }
+ IRegion visibleRegion = textViewer.getVisibleRegion();
+ return widgetOffset + visibleRegion.getOffset();
}
}
@@ -3534,7 +3533,7 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
if (isBlockSelectionModeEnabled())
return false;
- int offset= st.getOffsetAtLocation(point);
+ int offset = st.getOffsetAtPoint(point);
Point p= st.getLocationAtOffset(offset);
if (p.x > point.x)
offset--;
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java
index 04987fc3b..d0e0a2a0b 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java
@@ -1572,7 +1572,7 @@ public abstract class AbstractTemplatesPage extends Page implements ITemplatesPa
if (fViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 ext= (ITextViewerExtension5) fViewer;
try {
- return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtLocation(point));
+ return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point));
} catch (IllegalArgumentException e) {
int docLineIndex= ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
String lineDelimiter= document.getLineDelimiter(docLineIndex);

Back to the top