You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ar...@apache.org on 2019/12/02 09:04:47 UTC

[netbeans] branch master updated: [NETBEANS-3202] Fix issue in Text Block (#1570)

This is an automated email from the ASF dual-hosted git repository.

arusinha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a21981  [NETBEANS-3202] Fix issue in Text Block (#1570)
4a21981 is described below

commit 4a2198190e89ea41892491f7d4a516eb7f528e40
Author: Akshay-Gupta-Oracle <55...@users.noreply.github.com>
AuthorDate: Mon Dec 2 14:34:38 2019 +0530

    [NETBEANS-3202] Fix issue in Text Block (#1570)
    
    * {Netbeans:3202] Fix issue in Text Block
    
    * [NETBEANS-3202] Fix issue in Text Block
---
 .../org/netbeans/modules/editor/java/JavaKit.java  |  2 +-
 .../modules/editor/java/TypingCompletion.java      |  7 ++++
 .../editor/java/TypingCompletionUnitTest.java      | 46 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
index 69a69c4..6281256 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
@@ -428,7 +428,7 @@ public class JavaKit extends NbEditorKit {
         public void insert(MutableContext context) throws BadLocationException {
             int dotPos = context.getCaretOffset();
             Document doc = context.getDocument();
-            
+            if(TypingCompletion.posWithinTextBlock(doc, dotPos))return;
             if (TypingCompletion.posWithinString(doc, dotPos)) {
                 if (CodeStyle.getDefault(doc).wrapAfterBinaryOps()) {
                     context.setText("\" +\n \"", 3, 6); // NOI18N
diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java b/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
index f09bf49..d8867d0 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
@@ -547,6 +547,13 @@ class TypingCompletion {
         return posWithinQuotes(doc, caretOffset, JavaTokenId.STRING_LITERAL);
     }
     
+ static boolean posWithinTextBlock(Document doc, int caretOffset) {
+        TokenSequence<JavaTokenId> javaTS=javaTokenSequence(doc,caretOffset, false);
+        if(javaTS == null)return false;
+        boolean movePrevious = javaTS.movePrevious();
+        if(!movePrevious)return false;
+        return posWithinQuotes(doc, caretOffset, JavaTokenId.STRING_LITERAL) && javaTS.token().text().toString().equals("\"\"");
+    }
     private static boolean posWithinQuotes(Document doc, int caretOffset, JavaTokenId tokenId) {
         TokenSequence<JavaTokenId> javaTS = javaTokenSequence(doc, caretOffset, false);
         if (javaTS != null) {
diff --git a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/TypingCompletionUnitTest.java b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/TypingCompletionUnitTest.java
index 14f1990..3518d95 100644
--- a/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/TypingCompletionUnitTest.java
+++ b/java/java.editor/test/unit/src/org/netbeans/modules/editor/java/TypingCompletionUnitTest.java
@@ -966,6 +966,52 @@ public class TypingCompletionUnitTest extends NbTestCase {
                 + "}\n");
     }
     
+public void testPositionInTextBlock() throws Exception {
+              try {
+            SourceVersion.valueOf("RELEASE_13");
+        } catch (IllegalArgumentException ex) {
+            //OK, skip test
+            return ;
+        }
+        Context ctx = new Context(new JavaKit(),
+                "class Test {\n"
+                + "    {\n"
+                + "        \"\"\"|abcd\"\"\"\n"
+                + "    }\n"
+                + "}\n");
+        ctx.typeChar('\n');
+        ctx.assertDocumentTextEquals(
+                "class Test {\n"
+                + "    {\n"
+                + "        \"\"\"\n"
+                + "        |abcd\"\"\"\n"
+                + "    }\n"
+                + "}\n");
+    }
+        
+      public void testPositionInEmptyTextBlock() throws Exception {
+              try {
+            SourceVersion.valueOf("RELEASE_13");
+        } catch (IllegalArgumentException ex) {
+            //OK, skip test
+            return ;
+        }
+        Context ctx = new Context(new JavaKit(),
+                "class Test {\n"
+                + "    {\n"
+                + "        \"\"\"|\"\"\"\n"
+                + "    }\n"
+                + "}\n");
+        ctx.typeChar('\n');
+        ctx.assertDocumentTextEquals(
+                "class Test {\n"
+                + "    {\n"
+                + "        \"\"\"\n"
+                + "        |\"\"\"\n"
+                + "    }\n"
+                + "}\n");
+    }
+
     public void testCommentBlockCompletion() throws Exception {
         Preferences prefs = MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE).lookup(Preferences.class);
         try {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists