This commit is contained in:
Zef Hemel
2024-01-25 14:51:40 +01:00
parent e508628826
commit 604bea3ee0
13 changed files with 129 additions and 9 deletions
+23 -2
View File
@@ -320,7 +320,8 @@ export class Client {
if (
pageState.scrollTop !== undefined &&
!(pageState.scrollTop === 0 &&
(pageState.pos !== undefined || pageState.anchor !== undefined))
(pageState.pos !== undefined || pageState.anchor !== undefined ||
pageState.header !== undefined))
) {
setTimeout(() => {
console.log("Kicking off scroll to", pageState.scrollTop);
@@ -330,7 +331,10 @@ export class Client {
}
// Was a particular cursor/selection set?
if (pageState.selection?.anchor && !pageState.pos && !pageState.anchor) { // Only do this if we got a specific cursor position
if (
pageState.selection?.anchor && !pageState.pos && !pageState.anchor &&
!pageState.header
) { // Only do this if we got a specific cursor position
console.log("Changing cursor position to", pageState.selection);
this.editorView.dispatch({
selection: pageState.selection,
@@ -344,6 +348,7 @@ export class Client {
console.log("Navigating to anchor", pageState.anchor);
const pageText = this.editorView.state.sliceDoc();
// This is somewhat of a simplistic way to find the anchor, but it works for now
pos = pageText.indexOf(`$${pageState.anchor}`);
if (pos === -1) {
@@ -355,6 +360,22 @@ export class Client {
adjustedPosition = true;
}
if (pageState.header) {
console.log("Navigating to header", pageState.header);
const pageText = this.editorView.state.sliceDoc();
// This is somewhat of a simplistic way to find the header, but it works for now
pos = pageText.indexOf(`# ${pageState.header}\n`) + 2;
if (pos === -1) {
return this.flashNotification(
`Could not find header "${pageState.header}"`,
"error",
);
}
adjustedPosition = true;
}
if (pos !== undefined) {
// setTimeout(() => {
console.log("Doing this pos set to", pos);
-1
View File
@@ -162,7 +162,6 @@ export class MarkdownWidget extends WidgetType {
div.querySelectorAll("span.hashtag").forEach((el_) => {
const el = el_ as HTMLElement;
// Override default click behavior with a local navigate (faster)
console.log("Found hashtag", el.innerText);
el.addEventListener("click", (e) => {
console.log("Hashtag clicked", el.innerText);
if (e.ctrlKey || e.metaKey) {
+4
View File
@@ -146,5 +146,9 @@ export function parsePageRefFromURI(): PageRef {
location.pathname.substring(1),
));
if (location.hash) {
pageRef.header = decodeURI(location.hash.substring(1));
}
return pageRef;
}