|
From: <caw...@us...> - 2007-08-22 13:56:44
|
Revision: 3041
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3041&view=rev
Author: cawilliams
Date: 2007-08-22 06:56:41 -0700 (Wed, 22 Aug 2007)
Log Message:
-----------
check if we're inside code or not before we try to create a hyperlink. If we're in a comment, string, regexp, or command just immediately return null.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java 2007-08-22 13:42:53 UTC (rev 3040)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java 2007-08-22 13:56:41 UTC (rev 3041)
@@ -1,7 +1,11 @@
package org.rubypeople.rdt.internal.ui.text.hyperlinks;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PartInitException;
@@ -12,6 +16,7 @@
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.actions.OpenActionUtil;
import org.rubypeople.rdt.internal.ui.actions.SelectionConverter;
+import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
import org.rubypeople.rdt.internal.ui.text.RubyWordFinder;
import org.rubypeople.rdt.ui.IWorkingCopyManager;
import org.rubypeople.rdt.ui.text.hyperlinks.IHyperlinkProvider;
@@ -59,6 +64,7 @@
}
public IHyperlink getHyperlink(IEditorInput input, ITextViewer textViewer, Node node, IRegion region, boolean canShowMultipleHyperlinks) {
+ if (!inCode(textViewer, region)) return null;
IRegion newRegion = RubyWordFinder.findWord(textViewer.getDocument(), region.getOffset());
try {
IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
@@ -73,4 +79,20 @@
}
return null;
}
+
+ private boolean inCode(ITextViewer textViewer, IRegion region) {
+ try {
+ ITypedRegion[] regions= TextUtilities.computePartitioning(textViewer.getDocument(), IRubyPartitions.RUBY_PARTITIONING, region.getOffset(), region.getLength(), false);
+ if (regions == null) return false;
+ for (int i = 0; i < regions.length; i++) {
+ String type = regions[i].getType();
+ if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
+ return true;
+ }
+ }
+ } catch (BadLocationException e1) {
+ // ignore
+ }
+ return false;
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|