Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
14 changes: 11 additions & 3 deletions lib/provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

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


getAttributeValueCompletions: ({prefix, editor, bufferPosition}) ->
completions = []
Expand Down Expand Up @@ -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) ->
Copy link
Contributor

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

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.startsWith('role')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
4 changes: 2 additions & 2 deletions spec/provider-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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*", ->
Copy link
Contributor

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.

editor.setText('<input on')
editor.setCursorBufferPosition([0, 9])

completions = getCompletions()

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 "autocompletes attribute values without a prefix", ->
editor.setText('<marquee behavior=""')
Expand Down