This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 227176

Summary: Typinghooks API doesn't work properly
Product: editor Reporter: Ondrej Brejla <obrejla>
Component: -- Other --Assignee: Milutin Kristofic <mkristofic>
Status: RESOLVED FIXED    
Severity: normal Keywords: API
Priority: P2    
Version: 7.3   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Ondrej Brejla 2013-03-07 15:52:37 UTC
If I have a custom implementation of TypedTextInterceptor and want to use "selection" feature (user selects some text, types e.g. ", and the result is that the selected text is encapsulated by "..") with the caret at the end of the inserted text, it fails on Assertion error (BaseKit:1286).

API says that one can use:

String selection = context.getReplacedText();
String text = "\"" + selection + "\"";
context.setText(text, text.getLength()); // here is the problem

Possible fix is to change assert in BaseKit:1286 to:

assert caretPosition >= 0 && (caretPosition <= insertionText.length() || (insertionText.isEmpty() && caretPosition == 0));

The difference is equals sign in: caretPosition <= insertionText.length()

Thanks.
Comment 1 Milutin Kristofic 2013-03-07 15:59:09 UTC
Thank you, you are right, I added special case with empty text, but it should be able with any length and any caret on the end of text.

http://hg.netbeans.org/jet-main/rev/e13d6a595745
Comment 2 Quality Engineering 2013-03-09 01:57:09 UTC
Integrated into 'main-golden', will be available in build *201303082300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e13d6a595745
User: Milutin Kristofic <mkristofic@netbeans.org>
Log: #227176 - Typinghooks API doesn't work properly