|
239 | 239 | if (!startA) { |
240 | 240 | startA = container.querySelector(':focus'); |
241 | 241 | } |
242 | | - var startLI = startA; |
243 | | - while (startLI && startLI.tagName !== 'LI') { |
244 | | - startLI = startLI.parentElement; |
245 | | - } |
| 242 | + var startLI = startA && startA.closest('li'); |
246 | 243 | if (!startLI) { |
247 | 244 | if (isBackward) { |
248 | 245 | startLI = container.firstElementChild; |
|
257 | 254 | var siblingLI = startLI; |
258 | 255 | do { |
259 | 256 | if (isBackward) { |
260 | | - siblingLI = siblingLI.previousElementSibling; |
261 | | - if (!siblingLI) { |
262 | | - siblingLI = container.lastElementChild; |
263 | | - } |
| 257 | + siblingLI = siblingLI.previousElementSibling || container.lastElementChild; |
264 | 258 | } else { |
265 | | - siblingLI = siblingLI.nextElementSibling; |
266 | | - if (!siblingLI) { |
267 | | - siblingLI = container.firstElementChild; |
268 | | - } |
| 259 | + siblingLI = siblingLI.nextElementSibling || container.firstElementChild; |
269 | 260 | } |
270 | 261 | } while (siblingLI !== startLI && ( |
271 | 262 | siblingLI.classList.contains(classNone) || |
|
290 | 281 | } |
291 | 282 |
|
292 | 283 | function getMatchedFocusableSibling(container, isBackward, startA, buf) { |
293 | | - var skipRound = buf.length === 1; // find next prefix |
294 | | - var matchKeyA; |
| 284 | + var skipRound = buf.length === 1; // find next single-char prefix |
295 | 285 | var firstCheckA; |
296 | 286 | var secondCheckA; |
297 | 287 | var a = startA; |
|
317 | 307 | } |
318 | 308 |
|
319 | 309 | var textContent = (a.querySelector('.name') || a).textContent.toLowerCase(); |
320 | | - if (buf.length <= textContent.length && textContent.substring(0, buf.length) === buf) { |
| 310 | + if (textContent.startsWith(buf)) { |
321 | 311 | return a; |
322 | 312 | } |
323 | 313 | } while (a = getFocusableSibling(container, isBackward, a)); |
324 | | - return matchKeyA; |
325 | 314 | } |
326 | 315 |
|
327 | 316 | var ARROW_UP = 'ArrowUp'; |
|
357 | 346 |
|
358 | 347 | var currentLookupStartA; |
359 | 348 | if (key === lookupKey) { |
360 | | - // same as last key, lookup next for the same key as prefix |
| 349 | + // same as last key, lookup next single-char prefix |
361 | 350 | currentLookupStartA = container.querySelector(':focus'); |
362 | 351 | } else { |
363 | 352 | if (!lookupStartA) { |
|
367 | 356 | if (lookupKey === undefined) { |
368 | 357 | lookupKey = key; |
369 | 358 | } else { |
370 | | - // key changed, no more prefix match |
| 359 | + // key changed, no more single-char prefix match |
371 | 360 | lookupKey = ''; |
372 | 361 | } |
373 | 362 | } |
|
0 commit comments