Skip to content

Commit

Permalink
fix: Number box choosing doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Dec 30, 2023
1 parent aac8690 commit ad93a36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,14 @@ export default class Utils {
public static firstLetterUpperCase(str: string): string {
return str.slice(0, 1).toUpperCase() + str.slice(1).toLowerCase();
}

public static rawHexTextToKatex(str: string): string {
return str.split("").join(" ")
.replaceAll("A", "\\text{A}")
.replaceAll("B", "\\text{B}")
.replaceAll("C", "\\text{C}")
.replaceAll("D", "\\text{D}")
.replaceAll("E", "\\text{E}")
.replaceAll("F", "\\text{F}");
}
}
22 changes: 10 additions & 12 deletions src/views/programming/ProgrammingOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,16 @@ const ProgrammingOutput: React.FC = () => {
}
}, [inputRef, handleResult]);

useEffect(() => {
Emitter.get().once("number-sys-chose", (type: NumberSys) => {
setNumberSys(type);

const value = numberValues[type];

if(!inputRef.current || value === "0") return;
inputRef.current.value = value.split("").join(" ") +" "+ cursor;
setOutputContent("");
dispatchNumberValue({ type: "set", payload: numberValues.dec });
});
}, [numberValues]);
Emitter.get().on("number-sys-chose", (type: NumberSys) => {
setNumberSys(type);

const value = numberValues[type];

if(!inputRef.current || value === "0") return;
inputRef.current.value = Utils.rawHexTextToKatex(value) +" "+ cursor;
setOutputContent("");
dispatchNumberValue({ type: "set", payload: numberValues.dec });
});

useEmitter([
["clear-input", () => setOutputContent("")],
Expand Down

0 comments on commit ad93a36

Please sign in to comment.