mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-04 07:18:18 +00:00
Own browser UI sessions and shared navigation
This commit is contained in:
1 parent
cfdc698775
commit
273079e827
28 files changed
+1948
-121
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { stepCyclicIndex } from "octagonal-wheels/collection";
|
||||
|
||||
export function navigateDiffNodes(
|
||||
root: ParentNode,
|
||||
selector: string,
|
||||
navigation: {
|
||||
currentDiffIndex: number;
|
||||
diffNavIndicator: { setText(text: string): void };
|
||||
},
|
||||
direction: "prev" | "next"
|
||||
): void {
|
||||
const diffElements = root.querySelectorAll<HTMLElement>(selector);
|
||||
if (diffElements.length === 0) return;
|
||||
|
||||
const previousFocused = root.querySelector(".diff-focused");
|
||||
if (previousFocused) {
|
||||
previousFocused.classList.remove("diff-focused");
|
||||
}
|
||||
|
||||
navigation.currentDiffIndex = stepCyclicIndex(navigation.currentDiffIndex, diffElements.length, direction);
|
||||
const target = diffElements[navigation.currentDiffIndex];
|
||||
target.classList.add("diff-focused");
|
||||
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
navigation.diffNavIndicator.setText(`${navigation.currentDiffIndex + 1}/${diffElements.length}`);
|
||||
}
|
||||
Reference in new issue
Block a user