[hg] main-silver: #201008 - Add hint to remove surrounding tags ...

  • From: Marek Fukala < >
  • To: ,
  • Subject: [hg] main-silver: #201008 - Add hint to remove surrounding tags ...
  • Date: Tue, 10 Sep 2013 08:34:30 -0700

changeset 035d1133852b in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/035d1133852b
description:
        #201008 - Add hint to remove surrounding tags from caret position

diffstat:

 
csl.api/src/org/netbeans/modules/csl/hints/infrastructure/SuggestionsTask.java
   |   7 ++-
 
html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java 
   |   4 +
 
html.editor/src/org/netbeans/modules/html/editor/hints/RemoveSurroundingTag.java
 |  27 ++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)

diffs (103 lines):

diff --git 
a/csl.api/src/org/netbeans/modules/csl/hints/infrastructure/SuggestionsTask.java
 
b/csl.api/src/org/netbeans/modules/csl/hints/infrastructure/SuggestionsTask.java
--- 
a/csl.api/src/org/netbeans/modules/csl/hints/infrastructure/SuggestionsTask.java
+++ 
b/csl.api/src/org/netbeans/modules/csl/hints/infrastructure/SuggestionsTask.java
@@ -162,7 +162,7 @@
                             return;
                         }
                         // #224654 - suggestions may be returned for text 
unrelated to caret position
-                        if (linerange != OffsetRange.NONE && 
!hint.getRange().overlaps(linerange)) {
+                        if (linerange != OffsetRange.NONE && 
!overlaps(linerange, hint.getRange())) {
                             continue;
                         }
                         ErrorDescription desc = 
manager.createDescription(hint, ruleContext, false, i == hints.size()-1);
@@ -181,6 +181,11 @@
         }
     }
     
+    private static boolean overlaps(OffsetRange line, OffsetRange hint) {
+        //rule w/ empty hint range should still be shown at the very line 
beginning / end
+        return hint.overlaps(line) || hint.isEmpty() && 
line.containsInclusive(hint.getStart());
+    }
+    
     private static OffsetRange findLineBoundaries(CharSequence s, int 
position) {
         int l = s.length();
         if (position == -1 || position > l) {
diff --git 
a/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java
 
b/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java
--- 
a/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java
+++ 
b/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java
@@ -180,6 +180,10 @@
                 }
             }
         }
+        
+        if(RemoveSurroundingTag.RULE.appliesTo(context)) {
+            suggestions.add(new RemoveSurroundingTag(context, new 
OffsetRange(context.caretOffset, context.caretOffset)));
+        }
     }
 
     /**
diff --git 
a/html.editor/src/org/netbeans/modules/html/editor/hints/RemoveSurroundingTag.java
 
b/html.editor/src/org/netbeans/modules/html/editor/hints/RemoveSurroundingTag.java
--- 
a/html.editor/src/org/netbeans/modules/html/editor/hints/RemoveSurroundingTag.java
+++ 
b/html.editor/src/org/netbeans/modules/html/editor/hints/RemoveSurroundingTag.java
@@ -50,10 +50,12 @@
 import org.netbeans.modules.csl.api.Rule;
 import org.netbeans.modules.csl.api.RuleContext;
 import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.lib.api.elements.CloseTag;
 import org.netbeans.modules.html.editor.lib.api.elements.Element;
 import org.netbeans.modules.html.editor.lib.api.elements.ElementType;
 import org.netbeans.modules.html.editor.lib.api.elements.Node;
 import org.netbeans.modules.html.editor.lib.api.elements.OpenTag;
+import org.netbeans.modules.parsing.api.Snapshot;
 import org.openide.util.NbBundle;
 
 /**
@@ -62,7 +64,7 @@
  */
 public class RemoveSurroundingTag extends Hint {
 
-    private static final Rule RULE = new RemoveSurroundingTagRule();
+    public static final Rule RULE = new RemoveSurroundingTagRule();
     private static final String DISPLAYNAME = 
NbBundle.getMessage(RemoveSurroundingTag.class, "MSG_RemoveSurroundingTag");
 
     public RemoveSurroundingTag(RuleContext context, OffsetRange range) {
@@ -152,11 +154,25 @@
     }
 
     private static Element[] findPairNodesAtSelection(RuleContext context) {
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
         if (context.selectionStart == -1 || context.selectionEnd == -1) {
-            return null;
+            //no selection - find the containing element
+            Snapshot snap = result.getSnapshot();
+            int embeddedCaret = snap.getEmbeddedOffset(context.caretOffset);
+            if (embeddedCaret != -1) {
+                Node containing = result.findBySemanticRange(embeddedCaret, 
false);
+                if (containing != null) {
+                    if (containing.type() == ElementType.OPEN_TAG) {
+                        OpenTag ot = (OpenTag) containing;
+                        CloseTag ct = ot.matchingCloseTag();
+                        if (ct != null) {
+                            return new Element[]{ot, ct};
         }
-
-        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+                    }
+                }
+            }
+        } else {
+            //selection - find the element inside selection
 
         //check whether the selection starts at a tag and ends at a tag
         //open tag
@@ -178,7 +194,10 @@
         }
 
         return new Element[]{open, close};
+
     }
     
+        return null;
+    }
     
 }

[hg] main-silver: #201008 - Add hint to remove surrounding tags ...

Marek Fukala 09/10/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close