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 173691 - [69cat] XML autocomplete doesn't override highlighted text
Summary: [69cat] XML autocomplete doesn't override highlighted text
Alias: None
Product: xml
Classification: Unclassified
Component: Text-Edit (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 8 votes (vote)
Assignee: Svata Dedic
Keywords: NETFIX
: 181288 (view as bug list)
Depends on:
Reported: 2009-10-03 19:13 UTC by qbeukes
Modified: 2015-09-17 13:17 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

Fix for xml.text module (3.76 KB, patch)
2010-04-15 16:44 UTC, Michel Graciano
Details | Diff
Fix for xml.schema.completion module (1.83 KB, patch)
2010-04-15 16:50 UTC, Michel Graciano
Details | Diff
Proposed patch to fix xml.text (2.67 KB, patch)
2010-04-16 01:03 UTC, Michel Graciano
Details | Diff
Editor just prior to finishing code completion (55.73 KB, image/png)
2010-07-18 23:27 UTC, swpalmer
Editor just after finishing code completion (21.60 KB, image/png)
2010-07-18 23:27 UTC, swpalmer
sample XML for use with plugin.xsd (916 bytes, text/xml)
2010-10-22 14:06 UTC, swpalmer
Schema for plugin.xml (7.13 KB, application/xml)
2010-10-22 14:07 UTC, swpalmer

Note You need to log in before you can comment on or make changes to this bug.
Description qbeukes 2009-10-03 19:13:21 UTC
In my persistence.xml I have an attribute: transaction-type="RESOURCE_LOCAL"

When highlighting RESOURCE_LOCAL, pressing Ctrl+Space (auto complete shortcut) and selecting another option, ie. JTA it
ends up as: transaction-type="RESOURCE_LOCALJTA"
instead of: transaction-type="JTA"

The same goes for element tags, ex. <provider>, and highlighting "provider" becomes something like:
<providerdescription> instead of "<description>".
Comment 1 Peter Nabbefeld 2009-11-10 01:52:24 UTC
This annoying bug isn't fixed since several weeks, already: XML editing with code completion, e.g. for xsl files, inserts additional characters - or, better: it doesn't replace the already manually typed characters correctly.

Here it is how it works (t = manually typed characters, c = characters from code completion, e.g. "xsl:text":

If You have typed "<tttt", after completion You'll have "<cccccccctttt".

Seems the bug is in xml.text/src/org/netbeans/modules/xml/text/completion/, method "public void defaultAction(JTextComponent component)". For some unknown reason, probably "substituteOffset" has not been set (yet), resulting in a replace length of zero (thus, not replacing anything, only inserting). Sorry, I've neither the environment to debug this, nor the time to dig deeper into the source.
Comment 2 qbeukes 2009-11-15 06:54:10 UTC
It seems like part of the bug was fixed. I originally reported it for attributes and they do override the highlighted part when using auto complete, though element names are still buggy and not overridden.
Comment 3 Jiri Kovalsky 2010-04-08 09:24:14 UTC
Are you sure? I can still reproduce this in 6.9 development build #201004070201:

1. Generate new Java Desktop Application with Database shell using built-in Derby database.
2. Open "Source Packages > META-INF > persistence.xml" file.
3. Switch from GUI to XML based editor.
4. Double click RESOURCE_LOCAL to select it and push Ctrl+Space.
5. Select JTA and press Enter. Result will be RESOURCE_LOCALJTA instead of JTA.
6. The same applies for attributes or elements.

Adding this bug to NetFIX Pool [1]. If module owner disagrees, please speak up!

Comment 4 Michel Graciano 2010-04-08 16:08:30 UTC
*** Bug 181288 has been marked as a duplicate of this bug. ***
Comment 5 Michel Graciano 2010-04-08 16:10:59 UTC
This is valid for ant script file too.
Comment 6 Michel Graciano 2010-04-08 19:47:35 UTC
I will take a look at this.
Comment 7 Michel Graciano 2010-04-14 02:47:43 UTC
Well, I found the problem for XML/ant files but looks like I will need to fix it in diferrent modules. Should I break this issue in several, one for each module?
Comment 8 Michel Graciano 2010-04-14 03:32:28 UTC
Imagine the following scenario for an ant file, with no selection:

<import file="nbproject/build-impl.xml" optional="|f"/>

which is the desired behaviour?
1. <import file="nbproject/build-impl.xml" optional="false|"/>
2. <import file="nbproject/build-impl.xml" optional="false|f"/>
3. <import file="nbproject/build-impl.xml" optional="falsef|"/>

Well, my personal felling is that the best choice is the item 1.
Comment 9 Sergey Lunegov 2010-04-14 09:04:31 UTC
Alex, please take a look.
Comment 10 Michel Graciano 2010-04-14 12:12:49 UTC
Just to be clear, the desired behaviour is when user hit cc and choose an option, in this case user selected always option 'false'. I already create a patch that works for some kind of XML files but I need to know about it to make several tests to avoid regressions. The source code is marked with thousands issues already fixed so I will have a lot of work to test it.
Comment 11 misterm 2010-04-15 13:09:49 UTC
I think option 1 is the right one.
Comment 12 Jiri Kovalsky 2010-04-15 14:19:02 UTC
Comment 13 Michel Graciano 2010-04-15 16:44:47 UTC
Created attachment 97469 [details]
Fix for xml.text module

This patch fix the problems for XML in general as well for ANT files. In this fix the the attribute value is always overwritten when you pick up an option using CC. For example, <... option="|abc"/> and you pick up the option 'false' from cc the result will be <... option="false|"/>.
Comment 14 Michel Graciano 2010-04-15 16:50:18 UTC
Created attachment 97470 [details]
Fix for xml.schema.completion module

This patch fix the problems for XML which use schemas, as persistence XML for example. In this fix has a little bit different behaviour, the value is overwritten just when you pick up an option using CC and the previous text is selected or the caret is after typed text. When the caret is before the previous typed characters, those you remain. For example, <... option="|abc"/> and you pick up the option 'false' from cc the result will be <... option="false|abc"/>.
Comment 15 Michel Graciano 2010-04-15 16:55:59 UTC
Well, I hope I was clear about the behaviours in both file types. I choose this approach to avoid regressions in current implementations and implement schema based cc as ant script is too risky for now. BTW, both implementation cover what is requested in this issue (replace the selected value) so I consider it fixed.
Comment 16 Michel Graciano 2010-04-15 18:17:05 UTC
Comment on attachment 97469 [details]
Fix for xml.text module

I've just found out an issue in this patch. I will replace this patch soon.
Comment 17 Michel Graciano 2010-04-16 01:03:02 UTC
Created attachment 97495 [details]
Proposed patch to fix xml.text

Well, it fix the first patch. The behaviour now is exactly the same as for schema. I found an use case where is desired to keep the characters previously typed: ant properties completion. The following scenario is valid:
<... file="${|**/*.java"/> when you call cc and choose the choose the option ${basedir} for example the desired behaviour is <...file="${basedir}|**/*.java"/> instead file="${basedir}|"/>. BTW, for completions like <option="f|"/> the behaviour is <option="false|"/> where false is the selected cc option and as well now selection is completely replaced as requested.
Comment 18 Michel Graciano 2010-04-16 01:09:52 UTC
Any chance to see this integrated HR?
Comment 19 Jiri Kovalsky 2010-04-16 13:50:55 UTC
I tested the patch and it works like a charm. Sergey, can your team review and integrate this patch ASAP? Thanks a lot!
Comment 20 Sergey Lunegov 2010-04-16 14:14:21 UTC
Alex, please review the patch and if it's ok apply it.
Comment 21 _ alexpetrov 2010-04-17 17:02:15 UTC
I'll review proposed patches ASAP and integrate them into the trunk repository on Monday (Apr, 19th).
Comment 22 _ alexpetrov 2010-04-20 09:48:04 UTC
I've checked the patch for xml.text.
Please, attach an XML and XSD files which you use for making the patch for xml.schema.completion and/or describe a scenario for exact reproducing of this bug.
Comment 23 Jiri Kovalsky 2010-04-20 09:49:54 UTC
Alex please see my comment #3 for the exact scenario. Thanks!
Comment 24 _ alexpetrov 2010-04-20 11:36:46 UTC
Fixed in trunk:
Comment 25 Jiri Kovalsky 2010-04-20 11:41:44 UTC
Thanks a lot Alex for your review and integration and special thanks to Michel for you patch!
Comment 26 Quality Engineering 2010-04-21 04:37:11 UTC
Integrated into 'main-golden', will be available in build *201004210200* on (upload may still be in progress)
User: Alex Petrov <>
Log: Fix for issue [#173691]. XML autocompletion doesn't override highlighted text.
Comment 27 swpalmer 2010-07-18 23:26:08 UTC
There is more to it.  XML auto-complete is still badly broken.  Attribute names (not values) are left in a mangled state when using auto-complete.  I will attach screen shots.  Also sometimes the auto-complete offers no suggestions at all when it should.
Comment 28 swpalmer 2010-07-18 23:27:14 UTC
Created attachment 100908 [details]
Editor just prior to finishing code completion
Comment 29 swpalmer 2010-07-18 23:27:52 UTC
Created attachment 100909 [details]
Editor just after finishing code completion
Comment 30 swpalmer 2010-07-18 23:29:51 UTC
My screen shots were taken with the 6.9 release on Windows XP.
Comment 31 Jiri Kovalsky 2010-07-19 13:47:23 UTC
Michel, any chance you could review this bug fix?
Comment 32 Michel Graciano 2010-07-19 14:30:41 UTC
Yes, I will review this new scenario and try to propose a new patch for this. Thanks swpalmer for new details, I will investigate this soon and ask you if I need more details. I need to know which kind of XML are you editing, is it based on schema? I ask this because there are a implementation for some kind of file (Ant, schema, DTD etc).
Comment 33 Michel Graciano 2010-07-22 22:07:19 UTC
I can't reproduce your issue. Could you send me a xsd and xml sample about your problem? Which NB version are you using exactly?

Comment 34 Michel Graciano 2010-10-20 13:11:09 UTC
Could more info be added to this? I wish to fix it if I can reproduce it.

Comment 35 Jiri Kovalsky 2010-10-20 13:26:07 UTC
Scott, can you please answer Michel's questions? I tried it in the NetBeans 6.9.1 build #201007282301 and everything worked fine for me.
Comment 36 swpalmer 2010-10-21 19:18:36 UTC
I'm told by my coworker, "Yes, it still sucks.  Start typing the attribute name, then use the auto complete and it fills in the whole name  (eg.   desdescription)"

The XML is based on a schema, we have added the schema to the user catalog.

It is just as bad or worse than before.

We have seen a few different behaviours...

In addition to the quoted issue above:
If you start typing an attribute name then hit ctrol-space nothing is offered as a completion.

If you type a space the whole list of attributes is offered automatically as completions. (If you choose one the cursor should be left between the quotes but it isn't)

Closing an element doesn't out-dent the closing tag.
Comment 37 Jiri Kovalsky 2010-10-22 07:24:47 UTC
Scott, this is not helpful unfortunately. We need to know what NetBeans IDE are you and your colleague using. Is it NetBeans IDE 7.0 development build #201010190000 or is it NetBeans IDE 6.9.1 or only 6.9? Can you attach the not working XML and XSD files here? Thanks for your cooperation!
Comment 38 swpalmer 2010-10-22 14:05:15 UTC
We are using NetBeans 6.9.1

Are you really having difficulty reproducing this?  I have yet to see it work properly.

I will soon attach two files...

  "plugin.xsd" - go to Tools-> DTDs and XML Schemas and add this to the User Catalog by selecting "System ID" entering :plugin.xsd" for the system ID then browsing to the file to fill in the URI

  "plugin.xml" - open this file in the editor and try to edit it.. see what it suggests for elements an attributes.  See how it behaves when you type part of an attribute.  See how it formats the document when it auto-completes the closing tag for an element.  In nearly every case it fails to do what I would expect.

files coming in a few seconds...
Comment 39 swpalmer 2010-10-22 14:06:24 UTC
Created attachment 102568 [details]
sample XML for use with plugin.xsd
Comment 40 swpalmer 2010-10-22 14:07:06 UTC
Created attachment 102569 [details]
Schema for plugin.xml
Comment 41 Michel Graciano 2010-10-22 14:13:15 UTC
Thanks Scott. I will try to address this next week if time permits.

Comment 42 swpalmer 2010-10-22 16:11:22 UTC
It would also be nice when I select New File -> XML -> XML Document ...-> XML Schema-Constrained Document -> ??? why can't I pick from the schemas I have added to the User Catalog? If I enter "plugin.xsd" in the Schema field of the New File wizard it won't take (reverts to empty field).  If I choose "Browse" it expects the Schema to be contained in my project if I browse "By File", if I browse "By Namespace" it is empty.
Comment 43 Michel Graciano 2010-10-22 16:15:34 UTC
(In reply to comment #42)
> It would also be nice when I select New File -> XML -> XML Document ...-> XML
> Schema-Constrained Document -> ??? why can't I pick from the schemas I have
> added to the User Catalog? If I enter "plugin.xsd" in the Schema field of the
> New File wizard it won't take (reverts to empty field).  If I choose "Browse"
> it expects the Schema to be contained in my project if I browse "By File", if I
> browse "By Namespace" it is empty.

Scott, please file another issue about it and CC me. Maybe I can try to do this in the future, or another NetFIXer, but for now I would like to do my best about this problem at code completion and mark this as FIXED again :)
Comment 44 swpalmer 2010-10-22 19:05:31 UTC
Thanks, I've entered Bug 191271
Comment 45 Martin Balin 2015-09-17 13:17:10 UTC
Report from old NetBeans version. Due to code changes since it was reported likely not reproducible now. Feel free to reopen if happens in 8.0.2 or 8.1.