Skip to content

Commit

Permalink
undo redo, trying to debug something catching and going wrong but now…
Browse files Browse the repository at this point in the history
… dont feel like it
  • Loading branch information
mcnuttandrew committed Jan 30, 2025
1 parent e6f6cee commit d079be8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 23 deletions.
2 changes: 2 additions & 0 deletions apps/lil-buddy/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import LintPicker from "./linting/LintPicker.svelte";
import NewLintSuggestion from "./linting/NewLintSuggestion.svelte";
import KeyboardHooks from "./components/KeyboardHooks.svelte";
$: lint = $store.lints.find((lint) => lint.id === $store.focusedLint)!;
</script>

Expand Down Expand Up @@ -45,3 +46,4 @@
</div>
{/if}
</main>
<KeyboardHooks />
36 changes: 36 additions & 0 deletions apps/lil-buddy/src/components/KeyboardHooks.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script lang="ts">
import store from "../stores/store";
function onKeyDown(e: any) {
const tagName = e.target.tagName.toLowerCase();
const tagType = e.target.type;
const classes = e.target.getAttribute("class") || "";
if (tagName === "input" && !classes.includes("color-slider")) {
const isUIElement =
tagType === "number" || tagType === "range" || tagType === "text";
if (isUIElement) {
return;
}
}
// block code mirror editing
if (classes.includes("cm-content")) {
return;
}
if (tagName === "textarea") {
return;
}
const key = e.key.toLowerCase();
const metaKey = e.metaKey || e.ctrlKey;
// UNDO REDO
if (key === "z" && metaKey) {
e.preventDefault();
store.undo();
}
if ((key === "y" && metaKey) || (key === "z" && metaKey && e.shiftKey)) {
e.preventDefault();
store.redo();
}
}
</script>

<svelte:window on:keydown={onKeyDown} />
25 changes: 24 additions & 1 deletion apps/lil-buddy/src/linting/FocusedTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$: errors = lintRun.errors;
$: pairData = blameData as number[][];
$: program = lint.program;
let editTime: null | number = null;
</script>

{#if currentLintAppliesToCurrentPalette && testPal}
Expand Down Expand Up @@ -67,6 +68,10 @@
}}
pal={testPal}
updatePal={(newPal) => {
if (editTime === null) {
editTime = Date.now();
store.setOkayToExecute(false);
}
const oldTests =
focusedTest.type === "passing"
? lint.expectedPassingTests
Expand All @@ -78,6 +83,15 @@
} else {
store.setCurrentLintExpectedFailingTests(newTests);
}
editTime = Date.now();
setTimeout(() => {
if (!editTime) {
store.setOkayToExecute(true);
} else if (Date.now() - editTime > 1000) {
store.setOkayToExecute(true);
editTime = null;
}
}, 1000);
}}
/>
{/if}
Expand Down Expand Up @@ -125,7 +139,16 @@
{:else}
<div class="text-red-500">
This lint does not apply to the current palette due to a mismatch between
its tags and the palette's tags
its tags and the palette's tags. This lint requires the following tags: {lint.requiredTags
.map((x) => `"${x}"`)
.join(", ")}.
{#if testPal?.tags?.length}
The palette has the following tags: {(testPal?.tags || [])
.map((x) => `"${x}"`)
.join(", ")}
{:else}
The palette has no tags.
{/if}
</div>
{/if}
</div>
2 changes: 1 addition & 1 deletion apps/lil-buddy/src/linting/LintMeta.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</div>
<div class="flex flex-wrap">
{#each lint.requiredTags as tag}
<div>
<div class="mr-2 border rounded px-2 py-1">
{tag}
<button
class={""}
Expand Down
18 changes: 0 additions & 18 deletions apps/lil-buddy/src/linting/LintTests.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@
}}
>
<PalPreview pal={failing.pal} showTags={true} />
<!-- <LintTest
clickFocus={() =>
store.setFocusedTest({ type: "failing", index: idx })}
pivotRight={true}
removeCase={() => {
const newTests = [...lint.expectedFailingTests].filter(
(_, i) => i !== idx
);
store.setCurrentLintExpectedFailingTests(newTests);
}}
pal={failing.pal}
blamedSet={new Set(failing.blame)}
updatePal={(newPal) => {
const newTests = [...lint.expectedFailingTests];
newTests[idx] = newPal;
store.setCurrentLintExpectedFailingTests(newTests);
}}
/> -->
{#if failing.result.kind === "success"}
{#if !failing.result?.passes}
<div class="text-green-500">Correct</div>
Expand Down
12 changes: 9 additions & 3 deletions apps/lil-buddy/src/linting/VisualSummarizer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
import type { Palette } from "color-buddy-palette";
import DispatchNode from "./summary-nodes/DispatchNode.svelte";
import { GenerateAST } from "color-buddy-palette-lint";
import store from "../stores/store";
export let pal: Palette;
export let lint: string;
$: ast = getAST(lint);
$: ast = getAST(lint, $store.okayToExecute);
let error: any;
function getAST(lint: string) {
function getAST(lint: string, okayToExecute: boolean) {
console.log("ast");
if (!okayToExecute) {
error = "Changes in process";
return null;
}
try {
return GenerateAST(JSON.parse(lint)).value as any;
} catch (e) {
error = e;
}
}
$: console.log("summarizer");
$: console.log("summarizer", $store.okayToExecute);
</script>

<div class="flex">
Expand Down
4 changes: 4 additions & 0 deletions apps/lil-buddy/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface StoreData {
currentChecks: LintResult[];
loadState?: "loading" | "idle";
engine: "openai" | "anthropic";
okayToExecute: boolean;
}

const InitialStore: StoreData = {
Expand All @@ -36,6 +37,7 @@ const InitialStore: StoreData = {
loadState: "idle",
engine: "openai",
focusedTest: false,
okayToExecute: true,
};

function serializeStore(store: StoreData) {
Expand Down Expand Up @@ -220,6 +222,8 @@ function createStore() {
persistUpdate((old) => ({ ...old, engine })),
setFocusedTest: (test: StoreData["focusedTest"]) =>
persistUpdate((old) => ({ ...old, focusedTest: test })),
setOkayToExecute: (okay: StoreData["okayToExecute"]) =>
persistUpdate((old) => ({ ...old, okayToExecute: okay })),
};
}

Expand Down

0 comments on commit d079be8

Please sign in to comment.