Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 264246

Summary: [content assist] Use Linked Positions for cursor positioning in applied content assist proposals
Product: [WebTools] WTP Source Editing Reporter: Nick Sandonato <nsand.dev>
Component: wst.xmlAssignee: Nick Sandonato <nsand.dev>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: enhancement    
Priority: P3 CC: karenfbutzke
Version: 3.0Keywords: plan
Target Milestone: 3.4 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard: EaseOfUse
Attachments:
Description Flags
a start
none
a start
none
patch - fix
none
patch - fix 2 none

Description Nick Sandonato CLA 2009-02-09 15:32:45 EST
The source editors should use linked positions when applying a proposal. This would allow tabbing between attribute values and the element content.
Comment 1 Nick Sandonato CLA 2009-02-09 15:36:33 EST
It would also be nice to use ProposalPositions to add proposals to attribute values that are enumerated.
Comment 2 Nick Sandonato CLA 2011-09-07 16:20:37 EDT
Created attachment 202932 [details]
a start
Comment 3 Nick Sandonato CLA 2011-09-07 16:42:13 EDT
Created attachment 202934 [details]
a start

This is a starting point. One of the things that we might need to discuss are where should linked positions be established and where the exit position should be.

Right now, there are positions at:
1. Spanning the entire content of each attribute value
2. Before the closing > in the start-tag
3. Between the start- and end-tag.
4. After the end-tag.

The exit position is after the end-tag.
Comment 4 Nitin Dahyabhai CLA 2012-01-02 13:17:50 EST
Nick, is there any way to unit test this?
Comment 5 Nick Sandonato CLA 2012-01-10 13:08:08 EST
I added a unit test based on checking that linked positions were added to the viewer's document after applying the proposal. The changes have been released for M5.
Comment 6 Karen Butzke CLA 2012-02-09 11:44:52 EST
I think this bug has caused some issues with xml source editing.

Create a new XML file using the catalog entry for http://java.sun.com/xml/ns/persistence/orm_2_0.xsd.

Using WTP 3.4M4:
1. Use content assist and add the orm:entity element. This adds the entity element with a class attribute.
<orm:entity class=""></orm:entity>

2.Type in a class name and then use the arrow key to get between the entity open and close tags and press enter. 
3.Now I can begin adding elements inside of the entity element.

<orm:entity class="Foo"></orm:entity>

Using WTP 3.4M5:
Completing step 2 takes me to the end of the line. I see no way to get it to just go to between the open/close tags of entity. Using tab after typing the class name will put me there, but then I press enter the same thing happens, the cursor jumps to the end of the line. I have to reposition the cursor in between the open close tags and press enter again.

This is an annoying change in the behavior when typing directly in the source. The nice thing it has added is the ability to tab, where in M4 if I pressed tab after editing the class attribute it would just add a tab in the string. Now I can press tab twice to get to between the open and close tabs.
Comment 7 Karen Butzke CLA 2012-02-14 14:15:10 EST
I am reopening this bug, any thoughts on comment 6?
Comment 8 Nick Sandonato CLA 2012-02-14 15:22:24 EST
(In reply to comment #7)
> I am reopening this bug, any thoughts on comment 6?

Hi Karen,

I'm sorry this introduced an annoyance. So if I'm understanding this right, you want the functionality of being able to begin formatting the child of <orm:entity> by pressing enter when in the area between the start and end tag? The one thing you can do in the meantime is hit escape, which cancels linked mode, and then enter to add the newline in between the tags.

I think the trouble with this one when I was implementing it was what makes the most sense as an exit position (where you jump to when you hit enter in linked mode) for tags: between the start and end tags or after the end tag. I probably could move the exit position to the middle, as I guess that would probably be consistent with how it was before, but I vaguely remember this causing some weird jumping when tabbing.

What are your feelings on the proper position for an exit position? I could see removing the exit position, but people might be used to it for the general idea of linked positions. And then maybe re-order the positions so that the cursor initially jumps to between the tags, in the case of no attributes, so functionality is similar to before. I'm definitely open to suggestions.
Comment 9 Nick Sandonato CLA 2012-02-22 17:06:02 EST
Hi Karen,

Just pinging to see if you had any opinions on what you'd like to see in regards to comment 8.
Comment 10 Nick Sandonato CLA 2012-03-01 17:58:08 EST
Created attachment 211921 [details]
patch - fix

Hi Karen,

So I tweaked things a little. Now, you will only get linked positions if you have attributes to fill. The exit position is now in between the start and end tags. Hopefully this fits closer to expectations.
Comment 11 Karen Butzke CLA 2012-03-02 13:37:08 EST
Nick, sorry I never got back to you about this! I've just tested out your patch and things look good for this particular use case.  But it seems like things might be a little weird now when there isn't an end tag. I have an element with 1 required attribute and no subelements. Once I enter the required element 'name' and press enter the cursor just goes to the next line. Thought you might want to try out that use case and see if it's what you were expecting.

With the same schema you would enter the following. After using code assist for the transient attribute, entering a name and then pressing enter, the cursor appears on the line with the closing attributes tag. I'm not sure how this worked before.
<orm:entity class="Foo">
    <orm:attributes>
        <orm:transient name="bar"/>
    </orm:attributes>
</orm:entity>
Comment 12 Nick Sandonato CLA 2012-03-08 15:13:03 EST
Created attachment 212326 [details]
patch - fix 2

Good catch! I think this patch should correct this weirdness.
Comment 13 Karen Butzke CLA 2012-03-13 13:21:06 EDT
I tried it out, looks good to me!
Comment 14 Nick Sandonato CLA 2012-03-28 10:10:51 EDT
Thanks, Karen. I've released the latest fix.