Skip to content

Commit

Permalink
double click visual cell to edit, ctrl+enter to run code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushKun committed May 27, 2024
1 parent 9e78293 commit 736eeab
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion next_app/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ const CodeCell = ({
else monaco.editor.setTheme("vs-light");
// set font family
editor.updateOptions({ fontFamily: "DM mono" });
// run function on ctrl+enter
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => {
runCellCode();
});
}}
onChange={(value) => {
// console.log(value);
Expand Down Expand Up @@ -246,10 +250,22 @@ const VisualCell = (
) => {
const [mouseHovered, setMouseHovered] = useState(false);
const [editing, setEditing] = useState(file.content.cells[cellId].editing);
const [clickCount, setClickCount] = useState(0);
const { theme } = useTheme();

const cellType = file.content.cells[cellId].type

function checkDoubleClick() {
if (editing) return
setClickCount(clickCount + 1);
setTimeout(() => {
if (clickCount == 1) {
setEditing(true);
}
setClickCount(0);
}, 200);
}

return <div data-editing={editing} className="rounded-md relative bg-accent/30"
onMouseEnter={() => setMouseHovered(true)}
onMouseLeave={() => setMouseHovered(false)}
Expand Down Expand Up @@ -297,6 +313,11 @@ const VisualCell = (
else monaco.editor.setTheme("vs-light");
// set font family
editor.updateOptions({ fontFamily: "DM mono" });
// run function on ctrl+enter
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => {
setEditing(false);
});
editor.focus();
}}
onChange={(value) => {
// console.log(value);
Expand All @@ -316,7 +337,7 @@ const VisualCell = (
language={file.content.cells[cellId].type == "MARKDOWN" ? "markdown" : "latex"}
options={monacoConfig.CodeCell}
/>
</div> : <div className="markdown m-5">
</div> : <div className="markdown m-5" onClick={checkDoubleClick}>
{cellType == "MARKDOWN" ? <Markdown remarkPlugins={[remarkGfm]}>{file.content.cells[cellId].code}</Markdown> :
<Latex>{file.content.cells[cellId].code}</Latex>
}
Expand Down

0 comments on commit 736eeab

Please sign in to comment.