Skip to content

Commit

Permalink
clean up scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasithea0 committed Oct 7, 2024
1 parent e5615ae commit 905da62
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,44 @@
import DOMPurify from "isomorphic-dompurify";
import { markdownTheme } from "$lib/stores/themeStore";
$: theme = $markdownTheme;
let leftWidth = 50;
let isResizing = false;
let selectedTab: "write" | "preview" = "write";
let editorScrollTop = 0;
let rendererScrollTop = 0;
let isScrollSyncEnabled = true; // Variable to toggle scroll sync
let isScrollSyncEnabled = true;
let carta: CartaType;
let source = localStorageStore.get("markdown") || "";
setContext("source", source);
$: localStorageStore.set("markdown", source);
$: carta = new Carta({
sanitizer: DOMPurify.sanitize,
theme: $markdownTheme === "light" ? "light-plus" : "dark-plus",
});
function handleEditorScroll(event: Event) {
if (!isScrollSyncEnabled) return; // Only sync if enabled
if (!isScrollSyncEnabled) return;
const editor = event.target as HTMLDivElement;
editorScrollTop = editor.scrollTop;
rendererScrollTop = editorScrollTop;
const renderer = document.querySelector(".renderer") as HTMLDivElement;
if (renderer) {
renderer.scrollTop = rendererScrollTop; // Only scroll if renderer exists
renderer.scrollTop = rendererScrollTop;
}
}
function handleRendererScroll(event: Event) {
if (!isScrollSyncEnabled) return; // Only sync if enabled
if (!isScrollSyncEnabled) return;
const renderer = event.target as HTMLDivElement;
rendererScrollTop = renderer.scrollTop;
editorScrollTop = rendererScrollTop;
const editor = document.querySelector(".editor .w-full") as HTMLDivElement;
if (editor) {
editor.scrollTop = editorScrollTop; // Only scroll if editor exists
editor.scrollTop = editorScrollTop;
}
}
Expand All @@ -58,25 +66,6 @@
document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseUp);
}
function toggleScrollSync() {
isScrollSyncEnabled = !isScrollSyncEnabled;
}
let source: string = localStorageStore.get("markdown") || "";
setContext("source", source);
$: {
localStorageStore.set("markdown", source);
}
let carta: CartaType;
$: {
carta = new Carta({
sanitizer: DOMPurify.sanitize,
theme: $markdownTheme === "light" ? "light-plus" : "dark-plus",
});
}
</script>

<div class={`flex h-[100dvh] ${$markdownTheme === "light" ? "bg-white" : "bg-mono-background"}`}>
Expand Down

0 comments on commit 905da62

Please sign in to comment.