diff --git a/lib/provider.coffee b/lib/provider.coffee index ff4ca9d..34a9cba 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,15 @@ 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 if attribute is 'role' + "https://www.w3.org/TR/wai-aria-1.1/#usage_intro" + else + "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" firstCharsEqual = (str1, str2) -> str1[0].toLowerCase() is str2[0].toLowerCase() diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index 1637c6b..db5a0f0 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -12,7 +12,21 @@ describe "HTML autocompletions", -> bufferPosition: bufferPosition scopeDescriptor: cursor.getScopeDescriptor() prefix: prefix - provider.getSuggestions(request) + + filterByPrefix(provider.getSuggestions(request), prefix) + + + filterByPrefix = (rawSuggestionsList, prefix) -> + if prefix.length < 3 + rawSuggestionsList + else + filteredSuggestionsList = [] + for suggestion in rawSuggestionsList + attribute = suggestion.text or suggestion.displayText + if attribute.indexOf(prefix) isnt -1 + filteredSuggestionsList.push suggestion + + filteredSuggestionsList beforeEach -> waitsForPromise -> atom.packages.activatePackage('autocomplete-html') @@ -294,7 +308,7 @@ 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 "provides a descriptionMoreURL if the attribute does not have a unique description but starts with on*", -> editor.setText(' expect(completions[0].displayText).toBe 'onabort' expect(completions[0].description).toBe 'Global onabort attribute' - expect(completions[0].descriptionMoreURL).toBeNull() + expect(completions[0].descriptionMoreURL.endsWith('/Web/API/GlobalEventHandlers/onabort')).toBe true + + it "provides a descriptionMoreURL if the attribute is role", -> + editor.setText('