-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
"clip-rule": { | ||
"attribOptions": ["evenodd", "inherit", "nonzero"] | ||
}, | ||
"color": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to align this with ColorUtils.js.
Unfortunately, we only have a comprehensive regexp right now, including rgb, hex, ...
You should at least include rebeccapurple
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebeccapurple
was not available in SVG 1.1 spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently do not provide the list of defined colors for CSS Code Hints. For the sake of consistency, seems like we should provide them in both places or neither. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though rebeccapurple
is not in the spec, I just tested using it in Chrome (in a SVG, of course) and it worked. I guess some will use it, and it won't hurt if we have it in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelgerber I have removed all color properties for now to be consistent with CSS hinting. Will add it later including rebeccapurple
once we get them in CSS too.
@@ -0,0 +1,242 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the spec, attributes are organized into groups such as "conditional processing attributes", "core attributes", "graphical event attributes", "presentation attributes", "xlink attributes", etc.
I think it would reduce a lot of redunancy which would make future maintenance easier if this organization could be captured in the json data. For example, define each of the "attribute groups" as a list of attributes, and then any tag that uses a particular attribute group could simply specify a flag (e.g. "coreAttrs": true
).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'll get that organized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format looks great!
Since this data has both tags and attributes, I think the term "groups" is a little vague. What about using "attributeGroups" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like attributeGroups
.
@sprintr This is an awesome contribution! Thanks for all of the unit tests. I made a first pass through the extension. Things generally look and work good. I'll need to make a more detailed pass through the code, but I wanted to give my initial feedback. |
function _getTagAttributes(editor, constPos) { | ||
var pos, ctx, ctxPrev, ctxNext, ctxTemp, tagName, exclusionList = [], shouldReplace; | ||
|
||
pos = $.extend({}, constPos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use _.clone(constPos)
here. It's more obvious (but you'll need to getModule
thirdparty/lodash
)
(same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$.extend({}, constPos)
is OK here. It's used in many places in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that since constPos
is multiple levels deep, I think you need to do a deep copy:
pos = $.extend(true, {}, constPos);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, constPos
is not multiple levels deep, but ctx
(a few lines below) is, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I thought it was a range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, pos works both ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it works both ways, but only use deep copying if needed.
Alright, will make the proposed changes today. I don't know about copyright of it. |
@redmunds @marcelgerber I have made the changes, Do I have to write unit tests for SVGUtils too after I rename it to XMLUtils and keep it in languages directory? |
@redmunds @marcelgerber The new format of SVGTags.json |
@redmunds I will work on caching attributes tomorrow. |
TokenValue = 3; | ||
|
||
// Regex to find whether or not an attribute value is quoted in single or double quotation marks. | ||
var regexQuotedValue = /^['"][\W\w]*?['"]?$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[\W\w]
is everything (like .
), right?
In that case, you should rather use .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that done because JSLint complained about using .*?
? If so, you can add the regexp: true
jslint var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was the reason.
Very nice! So much easier to read and update. |
That would be great! The token values set in CodeMirror have changed in the past and broken things, so this will make it easier to detect and fix any cases in the future. There are really only 2 API calls that you're providing (the others are static values), so it only needs to be a few tests that the API call returns expected values. |
* Return the tagName and a list of attributes used by the tag. | ||
* | ||
* @param {Editor} editor An instance of active editor | ||
* @param {line: int, ch: int} constPos The position of cursor in the active editor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be something like {!{line: number, ch: number}}
I am facing a problem with When I use [Extension] failed to load G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints - Error: Module name "language/XMLUtils" has not been loaded yet for context: _ and using GET file:///G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints/language/XMLUtils.js net::ERR_FILE_NOT_FOUND Working with |
Yeah, you have to require it in |
Note that SVG code hints do not work in |
}); | ||
|
||
it("should exclude hints if they are already been used.", function () { | ||
// In first <rect, after <rect+space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: should be "should exclude hints if they have already been used."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, How did I miss that, will get it fixed tomorrow.
Done with code review. |
@redmunds I will work on caching and those grammatical mistakes today. I think caching also needs a review. |
@redmunds caching has been implemented in |
cachedAttributes[tagName] = cachedAttributes[tagName].concat(tagData.attributeGroups[group]); | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caching looks good. The only change I would make would be to sort the list here so it doesn't have to be sorted every time the cached list is used. It's ok if getHints()
calls sort()
on list every time since it is fast if list is already sorted.
@sprintr Just Note that after that's fixed the commits will need to be squashed into a single commit to keep the code base cleaner. |
@redmunds For HTML, brackets is not using fuzzy matching. That's what I kept in mind. |
OK. Implement it if you want, but it's ok if not. |
@redmunds Fuzzy hinting has been implemented, you can try it. If you think it is OK, then I can squash commits. |
@sprintr Looks good. Squash away! |
@redmunds squashed! |
Update copyright notice. Change SVGTags.json to newer format. Adjust to the new format. Remove color from hints Add new line to unittests.js Format Simplify attribute options exclusion list More simplification to SVGUtils.js Updated comment Updated unittests.js for the changes. Improved format of SVGTags.json Refactoring Removed an error Remove alias properties to increase simplicity Add missing SVG attributes Cleanup Some more refactoring Updated unit tests Moved XMLUtils to core Added XMLUtils to brackets.js Added tests for XMLUtils-test.js Require XMLUtils Removed tabs Removed some more tabs. New line at the end. Removed tab. Removed unused variables. Remove XMLUtils from integration testing modules. Correct whitespace regex. Made proposed changes. Removed unused variables. Use a better name for attribute groups. Removed mistakes in unit tests Implement caching of attributes More optimization Refactor XMLUtils Sort cached attributes. Move preferences up Some more restrictions in XMLUtils Add fuzzy hinting Format Fix a bug with hinting Merge SVG code hints
Thanks for this awesome contribution! Merging. |
Cool! It has been a privilege to work on Brackets. |
@sprintr I tried embedding svg code directly in the html file since brackets supports HTML5, and was able to view it in the browser but Live Preview doesn't work in this case ??? I have to explicitly refresh the page ?? |
|
@sprintr okkay. |
Brackets uses |
This is a follow up of #10084, adds Code Hints for SVG.
CC: @redmunds