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 135297 - XML template expansion doesn't preserve cursor position.
Summary: XML template expansion doesn't preserve cursor position.
Status: VERIFIED FIXED
Alias: None
Product: xml
Classification: Unclassified
Component: Text-Edit (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P2 blocker (vote)
Assignee: Samaresh Panda
URL:
Keywords:
: 147262 (view as bug list)
Depends on: 137768
Blocks:
  Show dependency tree
 
Reported: 2008-05-19 09:40 UTC by redentis
Modified: 2008-09-15 14:11 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description redentis 2008-05-19 09:40:14 UTC
Expanding any template defined in Tools > Options > Editor options > Code templates > Language = XML while editing an
XML Scheme in source view causes the cursor to be repositioned at line 1, column 1.

I have classified this as a P2 based on the guidelines at http://qa.netbeans.org/bugzilla/bug_priority_guidelines.html
on the basis of:
1. usability: Critical usability problem
2. doesn't work, workarround exists: the editor itself is perfectly functional and has good code completion support

Test case:
1. File > New > XML Schema
2. Switch to source view
3. Enter "cl" and press expansion shortcut (I am using Tab but the behavior is the same for other key combinations)

Environment details:
  Product Version: NetBeans IDE 6.1 (Build 200804211638)
  Java: 1.6.0_04; Java HotSpot(TM) Client VM 10.0-b19
  System: Windows XP version 5.1 running on x86; Cp1252; en_GB (nb)
  Userdir: C:\Documents and Settings\MLEdwards\.netbeans\6.1

Plugin details:
  Version: 1.2
  Source: deadlock (
http://deadlock.netbeans.org/hudson/job/javadoc-nbms/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz)
Comment 1 Samaresh Panda 2008-05-21 17:53:20 UTC
Visible problem, will try to fix it for M1.
Comment 2 Samaresh Panda 2008-05-30 22:43:51 UTC
Browsing through the xml code-base, it seems like it just relies on the core editor template framework. Kindly take a
look. If you think the problem is in my code, please assign it back to me.
Comment 3 Dusan Balek 2008-06-02 09:21:39 UTC
Cursor is repositioned by the XMLLexerFormatter.reformat(...) method which is called at the end of the template
insertion. Reassigning back.
Comment 4 Samaresh Panda 2008-06-02 21:31:58 UTC
Fix in issue 132586 will fix this one as well.

*** This issue has been marked as a duplicate of 132586 ***
Comment 5 Samaresh Panda 2008-06-20 18:28:25 UTC
while working on the fix for issue 132586, i realized, this may not actually be a duplicate of that. For the other
issue, I position the caret where it was before the formatting, so someone else is repositioning to line1, col1 in
replacing code template.
Comment 6 Samaresh Panda 2008-06-20 18:31:59 UTC
dbalek, can you pl. take a look. I'm actually positioning the caret to where it was before.
Comment 7 Dusan Balek 2008-06-23 13:25:54 UTC
I don't think that it is a good practice to do reformat using

doc.replace(0, doc.getLength(), formattedDoc.getText(0, formattedDoc.getLength()), null);

If there were any marks in the reformatted document implemented using javax.swing.text.Position objects (like bookmarks,
code template parameter regions, etc.), all of these marks would be moved to position 0 after reformat. Better approach
would be to compute diffs between doc and foramttedDoc and apply only these diffs. This would preserve all Position
markers to stay on proper places.

Reassigning back.
Comment 8 Sonali Kochar 2008-07-29 18:46:11 UTC
Fixed
changeset bd8460d637b8 in main
details: http://hg.netbeans.org/main?cmd=changeset;node=bd8460d637b8
Comment 9 Quality Engineering 2008-07-30 04:10:40 UTC
Integrated into 'main-golden', available in build *200807300201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/bd8460d637b8
User: sonali@netbeans.org
Log: Fix for issue#135297 XML template expansion doesn't preserve cursor position.
Comment 10 tonybeckham 2008-08-01 18:44:12 UTC
Verified

Product Version: NetBeans IDE Dev (Build 200808010201)
Java: 1.5.0_13; Java HotSpot(TM) Client VM 1.5.0_13-119
System: Mac OS X version 10.5.4 running on i386; MacRoman; en_US (nb)
Comment 11 Samaresh Panda 2008-09-15 14:11:05 UTC
*** Issue 147262 has been marked as a duplicate of this issue. ***