| ... | ... | @@ -31,6 +31,7 @@ |
| 31 | 31 | |
| 32 | 32 | // for each package, is an array with packages to get to this one |
| 33 | 33 | var canonPkgPaths = computeCanonicalPackagePaths(); |
| 34 | var canonDeclPaths = null; // lazy; use getCanonDeclPath |
| 34 | 35 | |
| 35 | 36 | var curNav = { |
| 36 | 37 | // each element is a package name, e.g. @import("a") then within there @import("b") |
| ... | ... | @@ -45,6 +46,7 @@ |
| 45 | 46 | declObjs: [], |
| 46 | 47 | }; |
| 47 | 48 | var curNavSearch = ""; |
| 49 | var curSearchIndex = -1; |
| 48 | 50 | |
| 49 | 51 | var rootIsStd = detectRootIsStd(); |
| 50 | 52 | var typeTypeId = findTypeTypeId(); |
| ... | ... | @@ -78,6 +80,7 @@ |
| 78 | 80 | domSectSearchNoResults.classList.add("hidden"); |
| 79 | 81 | domSectInfo.classList.add("hidden"); |
| 80 | 82 | domHdrName.classList.add("hidden"); |
| 83 | domSectNav.classList.add("hidden"); |
| 81 | 84 | |
| 82 | 85 | renderTitle(); |
| 83 | 86 | renderInfo(); |
| ... | ... | @@ -413,7 +416,7 @@ |
| 413 | 416 | pkg: rootPkg, |
| 414 | 417 | }]; |
| 415 | 418 | while (stack.length !== 0) { |
| 416 | | var item = stack.pop(); |
| 419 | var item = stack.shift(); |
| 417 | 420 | for (var key in item.pkg.table) { |
| 418 | 421 | var childPkgIndex = item.pkg.table[key]; |
| 419 | 422 | if (list[childPkgIndex] != null) continue; |
| ... | ... | @@ -430,6 +433,51 @@ |
| 430 | 433 | return list; |
| 431 | 434 | } |
| 432 | 435 | |
| 436 | function computeCanonDeclPaths() { |
| 437 | var list = new Array(zigAnalysis.decls.length); |
| 438 | |
| 439 | for (var pkgI = 0; pkgI < zigAnalysis.packages.length; pkgI += 1) { |
| 440 | var pkg = zigAnalysis.packages[pkgI]; |
| 441 | var pkgNames = canonPkgPaths[pkgI]; |
| 442 | var stack = [{ |
| 443 | declNames: [], |
| 444 | type: zigAnalysis.types[pkg.main], |
| 445 | }]; |
| 446 | while (stack.length !== 0) { |
| 447 | var item = stack.shift(); |
| 448 | |
| 449 | if (item.type.pubDecls != null) { |
| 450 | for (var declI = 0; declI < item.type.pubDecls.length; declI += 1) { |
| 451 | var mainDeclIndex = item.type.pubDecls[declI]; |
| 452 | if (list[mainDeclIndex] != null) continue; |
| 453 | |
| 454 | var decl = zigAnalysis.decls[mainDeclIndex]; |
| 455 | var declNames = item.declNames.concat([decl.name]); |
| 456 | list[mainDeclIndex] = { |
| 457 | pkgNames: pkgNames, |
| 458 | declNames: declNames, |
| 459 | }; |
| 460 | var containerType = getDeclContainerType(decl); |
| 461 | if (containerType != null) { |
| 462 | stack.push({ |
| 463 | declNames: declNames, |
| 464 | type: containerType, |
| 465 | }); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | return list; |
| 472 | } |
| 473 | |
| 474 | function getCanonDeclPath(index) { |
| 475 | if (canonDeclPaths == null) { |
| 476 | canonDeclPaths = computeCanonDeclPaths(); |
| 477 | } |
| 478 | return canonDeclPaths[index]; |
| 479 | } |
| 480 | |
| 433 | 481 | function markdown(mdText) { |
| 434 | 482 | return mdText.replace(/[&"<>]/g, function (m) { |
| 435 | 483 | return escapeHtmlReplacements[m]; |
| ... | ... | @@ -438,14 +486,63 @@ |
| 438 | 486 | |
| 439 | 487 | function onSearchKeyDown(ev) { |
| 440 | 488 | switch (ev.which) { |
| 489 | case 13: |
| 490 | var liDom = null; |
| 491 | if (domListSearchResults.children.length === 1) { |
| 492 | liDom = domListSearchResults.children[0]; |
| 493 | } else { |
| 494 | liDom = domListSearchResults.children[curSearchIndex]; |
| 495 | } |
| 496 | if (liDom != null) { |
| 497 | var aDom = liDom.children[0]; |
| 498 | location.href = aDom.getAttribute("href"); |
| 499 | curSearchIndex = -1; |
| 500 | ev.preventDefault(); |
| 501 | ev.stopPropagation(); |
| 502 | return; |
| 503 | } |
| 441 | 504 | case 27: |
| 442 | 505 | domSearch.value = ""; |
| 443 | 506 | domSearch.blur(); |
| 507 | curSearchIndex = -1; |
| 444 | 508 | ev.preventDefault(); |
| 445 | | break; |
| 509 | ev.stopPropagation(); |
| 510 | startSearch(); |
| 511 | return; |
| 512 | case 38: |
| 513 | moveSearchCursor(-1); |
| 514 | ev.preventDefault(); |
| 515 | ev.stopPropagation(); |
| 516 | return; |
| 517 | case 40: |
| 518 | moveSearchCursor(1); |
| 519 | ev.preventDefault(); |
| 520 | ev.stopPropagation(); |
| 521 | return; |
| 522 | default: |
| 523 | curSearchIndex = -1; |
| 524 | ev.stopPropagation(); |
| 525 | startAsyncSearch(); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | function moveSearchCursor(dir) { |
| 530 | if (curSearchIndex < 0 || curSearchIndex >= domListSearchResults.children.length) { |
| 531 | if (dir > 0) { |
| 532 | curSearchIndex = -1 + dir; |
| 533 | } else if (dir < 0) { |
| 534 | curSearchIndex = domListSearchResults.children.length + dir; |
| 535 | } |
| 536 | } else { |
| 537 | curSearchIndex += dir; |
| 538 | } |
| 539 | if (curSearchIndex < 0) { |
| 540 | curSearchIndex = 0; |
| 541 | } |
| 542 | if (curSearchIndex >= domListSearchResults.children.length) { |
| 543 | curSearchIndex = domListSearchResults.children.length - 1; |
| 446 | 544 | } |
| 447 | | ev.stopPropagation(); |
| 448 | | startAsyncSearch(); |
| 545 | renderSearchCursor(); |
| 449 | 546 | } |
| 450 | 547 | |
| 451 | 548 | function onWindowKeyDown(ev) { |
| ... | ... | @@ -496,16 +593,20 @@ |
| 496 | 593 | } |
| 497 | 594 | } |
| 498 | 595 | function renderSearch() { |
| 499 | | var matchedDecls = []; |
| 596 | var matchedItems = []; |
| 500 | 597 | var terms = curNavSearch.split(/[ \r\n\t]+/); |
| 598 | |
| 501 | 599 | decl_loop: for (var declIndex = 0; declIndex < zigAnalysis.decls.length; declIndex += 1) { |
| 600 | var canonPath = getCanonDeclPath(declIndex); |
| 601 | if (canonPath == null) continue; |
| 602 | |
| 502 | 603 | var decl = zigAnalysis.decls[declIndex]; |
| 503 | 604 | for (var termIndex = 0; termIndex < terms.length; termIndex += 1) { |
| 504 | 605 | var term = terms[termIndex]; |
| 505 | 606 | if (decl.name.indexOf(term) >= 0) { |
| 506 | 607 | continue; |
| 507 | 608 | } |
| 508 | | var astNode = zigAnalysis.astNodes[decl.src] |
| 609 | var astNode = zigAnalysis.astNodes[decl.src]; |
| 509 | 610 | if (astNode.docs != null && astNode.docs.indexOf(term) >= 0) { |
| 510 | 611 | continue; |
| 511 | 612 | } |
| ... | ... | @@ -517,21 +618,38 @@ |
| 517 | 618 | continue decl_loop; |
| 518 | 619 | } |
| 519 | 620 | |
| 520 | | matchedDecls.push(decl); |
| 621 | matchedItems.push({ |
| 622 | decl: decl, |
| 623 | path: canonPath, |
| 624 | }); |
| 521 | 625 | } |
| 522 | 626 | |
| 523 | | if (matchedDecls.length !== 0) { |
| 524 | | resizeDomList(domListSearchResults, matchedDecls.length, '<li></li>'); |
| 627 | if (matchedItems.length !== 0) { |
| 628 | resizeDomList(domListSearchResults, matchedItems.length, '<li><a href="#"></a></li>'); |
| 525 | 629 | |
| 526 | | for (var i = 0; i < matchedDecls.length; i += 1) { |
| 630 | for (var i = 0; i < matchedItems.length; i += 1) { |
| 527 | 631 | var liDom = domListSearchResults.children[i]; |
| 528 | | var decl = matchedDecls[i]; |
| 529 | | liDom.textContent = decl.name; |
| 632 | var aDom = liDom.children[0]; |
| 633 | var match = matchedItems[i]; |
| 634 | aDom.textContent = match.path.declNames.join('.'); |
| 635 | aDom.setAttribute('href', navLink(match.path.pkgNames, match.path.declNames)); |
| 530 | 636 | } |
| 637 | renderSearchCursor(); |
| 531 | 638 | |
| 532 | 639 | domSectSearchResults.classList.remove("hidden"); |
| 533 | 640 | } else { |
| 534 | 641 | domSectSearchNoResults.classList.remove("hidden"); |
| 535 | 642 | } |
| 536 | 643 | } |
| 644 | |
| 645 | function renderSearchCursor() { |
| 646 | for (var i = 0; i < domListSearchResults.children.length; i += 1) { |
| 647 | var liDom = domListSearchResults.children[i]; |
| 648 | if (curSearchIndex === i) { |
| 649 | liDom.classList.add("selected"); |
| 650 | } else { |
| 651 | liDom.classList.remove("selected"); |
| 652 | } |
| 653 | } |
| 654 | } |
| 537 | 655 | })(); |