Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
scroll to top when clicking fresh link
Browse files Browse the repository at this point in the history
but don't disrupt the already working scroll history

We can detect if a hash change occurs due to history navigation
(forward/back) or a direct link click by putting an empty object in
History.state, and checking if it is null or not upon hash change.
  • Loading branch information
andrewrk committed Mar 10, 2024
1 parent 8b8a63b commit 6d96a63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ what you want.
* add source view links, currently you have to use the keyboard shortcut
* make the search box and nav bar stretch to fit the window
* redundant search results (search "format")
* scroll to top when clicking fresh link. but don't disrupt the already working scroll history
* convert TODO comments into roadmap

## Post-Merge Roadmap

* infer comptime_int constants (example: members of `#std.time`)
* when global const has a type of `type`, categorize it as a type despite its value
- example: `std.DynLib` (requires patching to add type annotation)
* show abbreviated doc comments in types and namespaces listings
Expand Down
12 changes: 9 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@

updateModuleList();

window.addEventListener('hashchange', onHashChange, false);
window.addEventListener('popstate', onPopState, false);
domSearch.addEventListener('keydown', onSearchKeyDown, false);
domSearch.addEventListener('input', onSearchChange, false);
window.addEventListener('keydown', onWindowKeyDown, false);
onHashChange();
onHashChange(null);
});
});

Expand Down Expand Up @@ -579,8 +579,14 @@
}
}

function onHashChange() {
function onHashChange(state) {
history.replaceState({}, "");
navigate(location.hash);
if (state == null) window.scrollTo({top: 0});
}

function onPopState(ev) {
onHashChange(ev.state);
}

function navigate(location_hash) {
Expand Down
2 changes: 1 addition & 1 deletion src/Walk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub const File = struct {
const node_tags = ast.nodes.items(.tag);
const node_datas = ast.nodes.items(.data);
const main_tokens = ast.nodes.items(.main_token);
log.debug("categorize_expr tag {s}", .{@tagName(node_tags[node])});
//log.debug("categorize_expr tag {s}", .{@tagName(node_tags[node])});
return switch (node_tags[node]) {
.container_decl,
.container_decl_trailing,
Expand Down

0 comments on commit 6d96a63

Please sign in to comment.