Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

GlobalEventHandlers have different docs URL on mdn then attribute #77

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
12 changes: 10 additions & 2 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)

getAttributeValueCompletions: ({prefix, editor, bufferPosition}) ->
completions = []
Expand Down Expand Up @@ -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()
40 changes: 37 additions & 3 deletions spec/provider-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -294,15 +308,35 @@ 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('<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 "provides a descriptionMoreURL if the attribute is role", ->
editor.setText('<div aria')
editor.setCursorBufferPosition([0, 9])

completions = getCompletions()

expect(completions[0].displayText).toBe 'aria-activedescendant'
expect(completions[0].description).toBe 'Global aria-activedescendant attribute'
expect(completions[0].descriptionMoreURL.endsWith('/TR/wai-aria-1.1/#aria-activedescendant')).toBe true

it "provides a descriptionMoreURL if the attribute is role", ->
editor.setText('<div ro')
editor.setCursorBufferPosition([0, 7])

completions = getCompletions()

expect(completions[0].displayText).toBe 'role'
expect(completions[0].description).toBe 'Global role attribute'
expect(completions[0].descriptionMoreURL.endsWith('/TR/wai-aria-1.1/#usage_intro')).toBe true

it "autocompletes attribute values without a prefix", ->
editor.setText('<marquee behavior=""')
Expand Down