-
Notifications
You must be signed in to change notification settings - Fork 80
GlobalEventHandlers have different docs URL on mdn then attribute #77
base: master
Are you sure you want to change the base?
Conversation
Thanks. Can you add a test for this please to make sure it doesn't regress? |
Hi, ok, I think you mean add test assertions in specs, never done that before but I'll try. |
@lalitsom what do you think about the following change instead (based off of master)? diff --git a/lib/provider.coffee b/lib/provider.coffee
index ff4ca9d..edb509a 100644
--- a/lib/provider.coffee
+++ b/lib/provider.coffee
@@ -118,7 +118,7 @@ module.exports =
displayText: attribute
type: 'attribute'
description: description ? "Global #{attribute} attribute"
- descriptionMoreURL: if description then @getGlobalAttributeDocsURL(attribute) else null
+ descriptionMoreURL: @getGlobalAttributeDocsURL(attribute)
getAttributeValueCompletions: ({prefix, editor, bufferPosition}) ->
completions = []
@@ -181,7 +181,13 @@ module.exports =
"#{@getTagDocsURL(tag)}#attr-#{attribute}"
getGlobalAttributeDocsURL: (attribute) ->
- "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}"
+ if attribute.startsWith('on')
+ "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}"
+ else if attribute.startsWith('aria-')
+ # As of September 2017, MDN does not have pages for ARIA attributes
+ "https://www.w3.org/TR/wai-aria-1.1/##{attribute}"
+ else
+ "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}"
firstCharsEqual = (str1, str2) ->
str1[0].toLowerCase() is str2[0].toLowerCase() That should cover all global attributes. |
yup, this one looks better. @50Wliu can you tell me how can I run the tests from spec.coffee on my local computer. |
Sounds good. You can run specs from Atom: search the command palette for |
lib/provider.coffee
Outdated
else if attribute.startsWith('aria-') | ||
# As of September 2017, MDN does not have pages for ARIA attributes | ||
"https://www.w3.org/TR/wai-aria-1.1/##{attribute}" | ||
else if attribute.startsWith('role') |
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.
attribute is 'role'
lib/provider.coffee
Outdated
@@ -180,8 +180,16 @@ module.exports = | |||
getLocalAttributeDocsURL: (attribute, tag) -> | |||
"#{@getTagDocsURL(tag)}#attr-#{attribute}" | |||
|
|||
getGlobalAttributeDocsURL: (attribute) -> | |||
"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" | |||
getGlobalAttributeDocsURL: (attribute, description) -> |
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.
description
is not used and can be removed
lib/provider.coffee
Outdated
@@ -118,7 +118,7 @@ module.exports = | |||
displayText: attribute | |||
type: 'attribute' | |||
description: description ? "Global #{attribute} attribute" | |||
descriptionMoreURL: if description then @getGlobalAttributeDocsURL(attribute) else null | |||
descriptionMoreURL: @getGlobalAttributeDocsURL(attribute, description) |
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.
description
is not used and can be removed
spec/provider-spec.coffee
Outdated
@@ -294,15 +294,15 @@ describe "HTML autocompletions", -> | |||
expect(-> completions = getCompletions()).not.toThrow() | |||
expect(completions[0].displayText).toBe 'onafterprint' | |||
|
|||
it "does not provide a descriptionMoreURL if the attribute does not have a unique description", -> | |||
it "provide a descriptionMoreURL if the attribute does not have a unique description but starts with on*", -> |
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.
"provide" -> "provides"
Similar tests can also be added now for aria-
and role
.
ok, thanks for the review. autocomplete-html/lib/provider.coffee Lines 95 to 106 in 4049b13
It returns an array of attributes whose first element matches with prefix, |
What's happening is that we provide the raw completions list to autocomplete-plus, which then does additional filtering. However, the specs are testing the raw completions and not the filtered list. This spec should work: it "provides a descriptionMoreURL if the attribute does not have a unique description but starts with aria-*", ->
editor.setText('<div aria-b')
editor.setCursorBufferPosition([0, 11])
completions = getCompletions()
console.log completions
expect(completions[0].displayText).toBe 'aria-busy'
expect(completions[0].description).toBe 'Global aria-busy attribute'
expect(completions[0].descriptionMoreURL.endsWith('/TR/wai-aria-1.1/#aria-busy')).toBe true |
Nevermind, even that doesn't work. I'll have to get back to you on how best to solve this. |
What if we filter the raw suggestions in spec file, according to prefix value. As of now filterByPrefix function will filter the list, only if prefix is of atleast length 3, so that test cases like "autcompletes tag names without a prefix" would still work. I also noticed that autocomplete-plus does not have the right order for suggestions ( check screenshot in my last comment), 'aria-atomic' and 'aria-activedescendant' should be above than 'aria-busy''. |
@50Wliu , can you give me a review on my last commit. Not sure, if this should be the way to solve this problem. |
Will look at it soon. |
Duplicate of # |
Duplicate of what? |
getGlobalAtributeDocsURL function in lib/provider.coffee was returning
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/{attributename} for all attributes,
but Events like onlick, onselect have different URL on mdn
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/{eventname}.
That's why I filtered the return value of this function depending on attribute name,
if attribute starts with "on" which means an event
then doc URL will be https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/{eventname}
else
same as it were before.