[hg] contrib: #209401 - DefaultKeyTypedAction#replaceSelection i...

  • From: Milutin Kristofic < >
  • To:
  • Subject: [hg] contrib: #209401 - DefaultKeyTypedAction#replaceSelection i...
  • Date: Tue, 07 Jan 2014 14:49:54 +0000

changeset b3b011ed82ed in contrib ((none))
details: http://hg.netbeans.org/contrib/rev/b3b011ed82ed
description:
        #209401 - DefaultKeyTypedAction#replaceSelection is against 
assumption called with empty string as argument - 

 patch

diffstat:

 gsf/src/org/netbeans/modules/gsf/GsfEditorKitFactory.java |  26 
++++++++++----
 1 files changed, 19 insertions(+), 7 deletions(-)

diffs (54 lines):

diff --git a/gsf/src/org/netbeans/modules/gsf/GsfEditorKitFactory.java 
b/gsf/src/org/netbeans/modules/gsf/GsfEditorKitFactory.java
--- a/gsf/src/org/netbeans/modules/gsf/GsfEditorKitFactory.java
+++ b/gsf/src/org/netbeans/modules/gsf/GsfEditorKitFactory.java
@@ -296,7 +296,10 @@
             @Override
             protected void replaceSelection(JTextComponent target, int 
dotPos, Caret caret,
                 String str, boolean overwrite) throws BadLocationException {
-                char insertedChar = str.charAt(0);
+                Character insertedChar = null;
+                if(str.length() > 0) {
+                    insertedChar = str.charAt(0);
+                }
                 Document document = target.getDocument();
 
                 if (document instanceof BaseDocument) {
@@ -309,9 +312,15 @@
                             try {
                                 int caretPosition = caret.getDot();
 
-                                boolean handled =
-                                    
bracketCompletion.beforeCharInserted(doc, caretPosition,
-                                        target, insertedChar);
+                                boolean handled = false;
+
+                                if(insertedChar != null) {
+                                    handled = 
bracketCompletion.beforeCharInserted(
+                                            doc, 
+                                            caretPosition,
+                                            target, 
+                                            insertedChar);
+                                }
 
                                 int p0 = Math.min(caret.getDot(), 
caret.getMark());
                                 int p1 = Math.max(caret.getDot(), 
caret.getMark());
@@ -320,13 +329,16 @@
                                     doc.remove(p0, p1 - p0);
                                 }
 
-                                if (!handled) {
+                                if ( (! handled) && insertedChar != null) {
                                     if ((str != null) && (str.length() > 0)) 
{
                                         doc.insertString(p0, str, null);
                                     }
 
-                                    bracketCompletion.afterCharInserted(doc, 
caret.getDot() - 1,
-                                        target, insertedChar);
+                                    bracketCompletion.afterCharInserted(
+                                            doc,
+                                            caret.getDot() - 1,
+                                            target,
+                                            insertedChar);
                                 }
                             } catch (BadLocationException e) {
                                 e.printStackTrace();

[hg] contrib: #209401 - DefaultKeyTypedAction#replaceSelection i...

Milutin Kristofic 01/07/2014

Project Features

About this Project

Contrib was started in November 2009, is owned by Jiří Kovalský, and has 254 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close