|
227 | 227 | }
|
228 | 228 | }
|
229 | 229 |
|
| 230 | + function displayHint(name, type) { |
| 231 | + return `<p>\ |
| 232 | +<span class="${type}-name hint-name">${name}</span>\ |
| 233 | +<span class="hint-hidden">, </span>\ |
| 234 | +<span class="hint-type">${type}</span>\ |
| 235 | +<span class="hint-hidden">, </span>\ |
| 236 | +<a href="https://p5js.org/reference/#/p5/${name}" role="link" onclick="event.stopPropagation()" target="_blank">\ |
| 237 | +<span class="hint-hidden">open ${name} reference</span>\ |
| 238 | +<span aria-hidden="true">➔</span></a></p>`; |
| 239 | + } |
| 240 | + |
230 | 241 | function Widget(completion, data) {
|
| 242 | + this.id = "cm-complete-" + Math.floor(Math.random(1e6)); |
231 | 243 | this.completion = completion;
|
232 | 244 | this.data = data;
|
233 | 245 | this.picked = false;
|
|
240 | 252 | var hints = this.hints = ownerDocument.createElement("ul");
|
241 | 253 | hints.setAttribute("role", "listbox")
|
242 | 254 | hints.setAttribute("aria-expanded", "true")
|
| 255 | + hints.id = this.id |
243 | 256 | var theme = completion.cm.options.theme;
|
244 | 257 | hints.className = "CodeMirror-hints " + theme;
|
245 | 258 | this.selectedHint = data.selectedHint || 0;
|
|
252 | 265 | if (cur.className != null) className = cur.className + " " + className;
|
253 | 266 | elt.className = className;
|
254 | 267 | if (i == this.selectedHint) elt.setAttribute("aria-selected", "true")
|
| 268 | + elt.id = this.id + "-" + i |
255 | 269 | elt.setAttribute("role", "option")
|
256 | 270 | if (cur.render) cur.render(elt, data, cur);
|
257 | 271 | else {
|
258 | 272 | const e = ownerDocument.createElement('p');
|
259 | 273 | const name = getText(cur);
|
260 | 274 | if (cur.item && cur.item.type) {
|
261 |
| - cur.displayText = `<span class="${cur.item.type}-name hint-name">${name}</span><span class="hint-type">${cur.item.type}</span>*`; |
262 |
| - cur.displayText = cur.displayText.replace('*', `<a href="https://p5js.org/reference/#/p5/${name}" onclick="event.stopPropagation()" target="_blank">➔</a>`); |
| 275 | + cur.displayText = displayHint(name, cur.item.type); |
263 | 276 | }
|
264 | 277 | elt.appendChild(e);
|
265 | 278 | e.outerHTML = cur.displayText || getText(cur);
|
|
288 | 301 | var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
|
289 | 302 | container.appendChild(hints);
|
290 | 303 | cm.getInputField().setAttribute("aria-autocomplete", "list")
|
| 304 | + cm.getInputField().setAttribute("aria-owns", this.id) |
| 305 | + cm.getInputField().setAttribute("aria-activedescendant", this.id + "-" + this.selectedHint) |
291 | 306 |
|
292 | 307 | var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect();
|
293 | 308 | var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false;
|
|
0 commit comments