Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2008-09-15 10:14:34 -0400
committerDani Megert2008-09-15 10:14:34 -0400
commitb5ffeccb0006c448880f32af5a75b88a0becc4f8 (patch)
tree775f318ee07701a451a9f28cacebc0b901082640
parent5a63a9aefda7a4507e37519d238f4cfbb15ef8bd (diff)
downloadeclipse.platform.text-b5ffeccb0006c448880f32af5a75b88a0becc4f8.tar.gz
eclipse.platform.text-b5ffeccb0006c448880f32af5a75b88a0becc4f8.tar.xz
eclipse.platform.text-b5ffeccb0006c448880f32af5a75b88a0becc4f8.zip
Fixed bug 8624: [misc] Double click should auto select comment
-rw-r--r--org.eclipse.jface.text/.settings/.api_filters15
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java91
2 files changed, 77 insertions, 29 deletions
diff --git a/org.eclipse.jface.text/.settings/.api_filters b/org.eclipse.jface.text/.settings/.api_filters
index 35fcd3390..c45311fa8 100644
--- a/org.eclipse.jface.text/.settings/.api_filters
+++ b/org.eclipse.jface.text/.settings/.api_filters
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jface.text" version="2">
+ <resource path="src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java" type="org.eclipse.jface.text.DefaultTextDoubleClickStrategy">
+ <filter id="337793096">
+ <message_arguments>
+ <message_argument value="org.eclipse.jface.text.DefaultTextDoubleClickStrategy"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jface/text/revisions/RevisionInformation.java" type="org.eclipse.jface.text.revisions.RevisionInformation">
<filter id="643846161">
<message_arguments>
@@ -17,4 +24,12 @@
</message_arguments>
</filter>
</resource>
+ <resource path="META-INF/MANIFEST.MF">
+ <filter id="923795461">
+ <message_arguments>
+ <message_argument value="3.5.0.qualifier"/>
+ <message_argument value="3.4.0.v20080603-2000"/>
+ </message_arguments>
+ </filter>
+ </resource>
</component>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
index d5ba81db3..a30b1d6dc 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
@@ -21,12 +21,8 @@ import com.ibm.icu.text.BreakIterator;
* <p>
* Selects words using <code>java.text.BreakIterator</code> for the default
* locale.</p>
- * <p>
- * This class is not intended to be subclassed.
- * </p>
*
* @see java.text.BreakIterator
- * @noextend This class is not intended to be subclassed by clients.
*/
public class DefaultTextDoubleClickStrategy implements ITextDoubleClickStrategy {
@@ -183,42 +179,79 @@ public class DefaultTextDoubleClickStrategy implements ITextDoubleClickStrategy
*/
public void doubleClicked(ITextViewer text) {
- int position= text.getSelectedRange().x;
+ int offset= text.getSelectedRange().x;
- if (position < 0)
+ if (offset < 0)
return;
- try {
+ final IDocument document= text.getDocument();
+ IRegion region= findExtendedDoubleClickSelection(document, offset);
+ if (region == null)
+ region= findWord(document, offset);
+ if (region != null)
+ text.setSelectedRange(region.getOffset(), region.getLength());
+
+ }
- IDocument document= text.getDocument();
- IRegion line= document.getLineInformationOfOffset(position);
- if (position == line.getOffset() + line.getLength())
- return;
+ /**
+ * Tries to find a suitable double click selection for the given offset.
+ * <p>
+ * <strong>Note:</> This method must return <code>null</code> if it simply selects the word at
+ * the given offset.
+ * </p>
+ *
+ * @param document the document
+ * @param offset the offset
+ * @return the selection or <code>null</code> if none to indicate simple word selection
+ * @since 3.5
+ */
+ protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) {
+ return null;
+ }
- fDocIter.setDocument(document, line);
+ /**
+ * Tries to find the word at the given offset.
+ *
+ * @param document the document
+ * @param offset the offset
+ * @return the word or <code>null</code> if none
+ * @since 3.5
+ */
+ protected IRegion findWord(IDocument document, int offset) {
+ IRegion line;
+ try {
+ line= document.getLineInformationOfOffset(offset);
+ } catch (BadLocationException e) {
+ return null;
+ }
- BreakIterator breakIter= BreakIterator.getWordInstance();
- breakIter.setText(fDocIter);
+ if (offset == line.getOffset() + line.getLength())
+ return null;
- int start= breakIter.preceding(position);
- if (start == BreakIterator.DONE)
- start= line.getOffset();
+ fDocIter.setDocument(document, line);
- int end= breakIter.following(position);
- if (end == BreakIterator.DONE)
- end= line.getOffset() + line.getLength();
+ BreakIterator breakIter= BreakIterator.getWordInstance();
+ breakIter.setText(fDocIter);
- if (breakIter.isBoundary(position)) {
- if (end - position > position- start)
- start= position;
- else
- end= position;
- }
+ int start= breakIter.preceding(offset);
+ if (start == BreakIterator.DONE)
+ start= line.getOffset();
- if (start != end)
- text.setSelectedRange(start, end - start);
+ int end= breakIter.following(offset);
+ if (end == BreakIterator.DONE)
+ end= line.getOffset() + line.getLength();
- } catch (BadLocationException x) {
+ if (breakIter.isBoundary(offset)) {
+ if (end - offset > offset - start)
+ start= offset;
+ else
+ end= offset;
}
+
+ if (end == start)
+ return null;
+
+ return new Region(start, end - start);
+
}
}

Back to the top