Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: opening a new tab from favorites in sidebar #74

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ function getPageRef(element: HTMLElement) {
getBlockContentPageRef(el) ??
getSidebarPageRef(el) ??
getReferencesPageRef(el) ??
getSearchMenuPageRef(el)
getSearchMenuPageRef(el) ??
getFavoritesOrRecentPageRef(el)
);
}

Expand Down Expand Up @@ -250,6 +251,17 @@ function getReferencesPageRef(element: HTMLElement) {
}
}

function getFavoritesOrRecentPageRef(element: HTMLElement) {
const el = element as HTMLAnchorElement;
if (el.tagName === "SPAN" && el.classList.contains("page-title")) {
const parentListItem = el.closest("li");

if (parentListItem?.classList.contains("favorite-item") || parentListItem?.classList.contains("recent-item")) {
return parentListItem.getAttribute("data-ref");
}
}
}

function getClosestSearchMenuLink(element: HTMLElement): HTMLElement | null {
return element.closest(".search-results-wrap .menu-link");
}
Expand All @@ -276,6 +288,7 @@ function getBlockUUID(element: HTMLElement) {
function stop(e: Event) {
e.stopPropagation();
e.stopImmediatePropagation();
e.preventDefault(); // prevent scrolling from middle mouse button click
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it also stop scrolling with wheel event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? If it is also stopping the normal scroll wheel event (not from the middle mouse button)?
The stop method is only called on middle mouse button click or on Ctrl + left mouse button click.

}

/**
Expand Down