Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Thoms2017-10-13 15:16:55 -0400
committerKarsten Thoms2018-01-12 17:04:20 -0500
commit357a31b4c7ded6a2f6b68107d2ada54e8960344c (patch)
treedadfa1be0e4af2d14c03ba57c8db976574883b44 /org.eclipse.ui.workbench.texteditor
parente8186dc22f970dae14d07ccb5341906955989f29 (diff)
downloadeclipse.platform.text-357a31b4c7ded6a2f6b68107d2ada54e8960344c.tar.gz
eclipse.platform.text-357a31b4c7ded6a2f6b68107d2ada54e8960344c.tar.xz
eclipse.platform.text-357a31b4c7ded6a2f6b68107d2ada54e8960344c.zip
Bug 522103 - Refactor usage of StyledText#getOffsetAtLocation(Point)I20180114-2000I20180113-1500I20180112-2000
Mostly reverted to previous state to keep IAE handling that might is needed by calls of other StyledText methods that throw IAE. Change-Id: Iaed70b5845735b13c524379df5b31a0bbe595d29 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/src/org/eclipse/ui/texteditor/AbstractTextEditor.java29
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java9
2 files changed, 21 insertions, 17 deletions
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 965f311cc..e57e427a8 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -1899,23 +1899,26 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
StyledText styledText= textViewer.getTextWidget();
IDocument document= textViewer.getDocument();
- if (document == null)
- return -1;
-
int widgetOffset = styledText.getOffsetAtPoint(new Point(x, y));
- if (widgetOffset == -1) {
+ if (document == null || 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);
+ try {
+ 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) {
+ return -1;
}
- IRegion visibleRegion = textViewer.getVisibleRegion();
- return widgetOffset + visibleRegion.getOffset();
}
}
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 d0e0a2a0b..c4bc44fe1 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Dakshinamurthy Karra, IBM Corporation and others.
+ * Copyright (c) 2007, 2018 Dakshinamurthy Karra, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -1571,15 +1571,16 @@ public abstract class AbstractTemplatesPage extends Page implements ITemplatesPa
int widgetCaret= fViewer.getTextWidget().getCaretOffset();
if (fViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 ext= (ITextViewerExtension5) fViewer;
- try {
- return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point));
- } catch (IllegalArgumentException e) {
+ int widgetOffset = textWidget.getOffsetAtPoint(point);
+ int offset = widgetOffset != -1 ? ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point)) : -1;
+ if (offset == -1) {
int docLineIndex= ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
String lineDelimiter= document.getLineDelimiter(docLineIndex);
int delimLength= lineDelimiter == null ? 0 : lineDelimiter.length();
return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex)
- delimLength;
}
+ return offset;
}
IRegion visible= fViewer.getVisibleRegion();
return widgetCaret + visible.getOffset();

Back to the top