|
236 | 236 | if (!startA) { |
237 | 237 | startA = container.querySelector(':focus'); |
238 | 238 | } |
239 | | - var startLI = startA; |
240 | | - while (startLI && startLI.tagName !== 'LI') { |
241 | | - startLI = startLI.parentElement; |
242 | | - } |
| 239 | + var startLI = startA && startA.closest('li'); |
243 | 240 | if (!startLI) { |
244 | 241 | if (isBackward) { |
245 | 242 | startLI = container.firstElementChild; |
|
254 | 251 | var siblingLI = startLI; |
255 | 252 | do { |
256 | 253 | if (isBackward) { |
257 | | - siblingLI = siblingLI.previousElementSibling; |
258 | | - if (!siblingLI) { |
259 | | - siblingLI = container.lastElementChild; |
260 | | - } |
| 254 | + siblingLI = siblingLI.previousElementSibling || container.lastElementChild; |
261 | 255 | } else { |
262 | | - siblingLI = siblingLI.nextElementSibling; |
263 | | - if (!siblingLI) { |
264 | | - siblingLI = container.firstElementChild; |
265 | | - } |
| 256 | + siblingLI = siblingLI.nextElementSibling || container.firstElementChild; |
266 | 257 | } |
267 | 258 | } while (siblingLI !== startLI && ( |
268 | 259 | siblingLI.classList.contains(classNone) || |
|
287 | 278 | } |
288 | 279 |
|
289 | 280 | function getMatchedFocusableSibling(container, isBackward, startA, buf) { |
290 | | - var skipRound = buf.length === 1; // find next prefix |
291 | | - var matchKeyA; |
| 281 | + var skipRound = buf.length === 1; // find next single-char prefix |
292 | 282 | var firstCheckA; |
293 | 283 | var secondCheckA; |
294 | 284 | var a = startA; |
|
314 | 304 | } |
315 | 305 |
|
316 | 306 | var textContent = (a.querySelector('.name') || a).textContent.toLowerCase(); |
317 | | - if (buf.length <= textContent.length && textContent.substring(0, buf.length) === buf) { |
| 307 | + if (textContent.startsWith(buf)) { |
318 | 308 | return a; |
319 | 309 | } |
320 | 310 | } while (a = getFocusableSibling(container, isBackward, a)); |
321 | | - return matchKeyA; |
322 | 311 | } |
323 | 312 |
|
324 | 313 | var ARROW_UP = 'ArrowUp'; |
|
354 | 343 |
|
355 | 344 | var currentLookupStartA; |
356 | 345 | if (key === lookupKey) { |
357 | | - // same as last key, lookup next for the same key as prefix |
| 346 | + // same as last key, lookup next single-char prefix |
358 | 347 | currentLookupStartA = container.querySelector(':focus'); |
359 | 348 | } else { |
360 | 349 | if (!lookupStartA) { |
|
364 | 353 | if (lookupKey === undefined) { |
365 | 354 | lookupKey = key; |
366 | 355 | } else { |
367 | | - // key changed, no more prefix match |
| 356 | + // key changed, no more single-char prefix match |
368 | 357 | lookupKey = ''; |
369 | 358 | } |
370 | 359 | } |
|
0 commit comments