liamcain / AutoFileName

Sublime Text plugin that autocompletes filenames
514 stars 78 forks source link

Add support for single quotes and fix edge cases that cause duplicate attributes and incorrect ordering. #55

Open manafire opened 10 years ago

manafire commented 10 years ago

I uncovered a couple of edge case bugs while working with the plugin. I would normally split all of this up, but the solution for one issue also solved the other and I inadvertently noticed and fixed a third issue along the way.

Issue 1. Trying to insert a tag that already has a single dimension attribute can cause duplicate attributes and/or incorrect order preference.

Settings: "afn_template_languages": false, "afn_insert_width_first": true <img src="img/wg-logo.png" width="55" class='logo'> becomes: <img src="img/wg-logo.png" height="62" width="311" class='logo'>

If you set "afn_template_languages": true, it's a little worse: img src="images/gmlmd-nav-offers.jpg" width="83" becomes: img src="images/gmlmd-nav-offers.jpg" width="83" height="25" width="83"

Issue 2. Incorrectly replaces dimensions in sibling tags (extract_scope selects more than just the current tag).

Settings: afn_template_languages: false <img src="img/first.png" width="666"><img src="img/auto_completing_this_img.png"> becomes: <img src="img/first.png" width="311"><img src="img/auto_completing_this_img.png" height="62">

In the example, you can see dimensions in the first image were incorrectly changed when auto-completing the second image.

Issue 3. Dimension attributes with single quotes are not replaced e.g. <img width='555' height='555' src="...">

Changes: