Skip to content

Commit

Permalink
added CTRL+ENTER as keydown for each cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Giuliano committed Oct 17, 2023
1 parent 9319cbd commit 4b3d308
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions zt_frontend/src/components/CodeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
theme="dracula"
lang="python"
:options="editorOptions"
@focus="handleFocus(true)"
@blur="handleFocus(false)"

/>
<v-expansion-panels v-else>
<v-expansion-panel>
Expand All @@ -23,6 +26,9 @@
lang="python"
:readonly=true
:options="editorOptions"
@focus="handleFocus(true)"
@blur="handleFocus(false)"

/>
</v-expansion-panel-text>
</v-expansion-panel>
Expand Down Expand Up @@ -140,6 +146,11 @@
required: true,
},
},
data() {
return {
isFocused: false, // add this line to keep track of the focus state
};
},
mounted() {
// Attach the event listener when the component is mounted
window.addEventListener('keydown', this.handleKeyDown);
Expand Down Expand Up @@ -205,13 +216,13 @@
},
methods: {
handleKeyDown(event: KeyboardEvent) {
if (event.ctrlKey && event.code === 'Enter') {
// Run your code here
console.log('Keydown!')
this.runCode(false, this.cellData.id, '');
}
},
if (this.isFocused && event.ctrlKey && event.key === 'Enter') {
this.runCode(false, this.cellData.id, '');
}
},
handleFocus(state: boolean) {
this.isFocused = state;
},
runCode(fromComponent:boolean , componentId: string, componentValue: any) {
if (!this.$devMode && fromComponent){
this.$emit('componentChange', this.cellData.id, componentId, componentValue);
Expand Down

0 comments on commit 4b3d308

Please sign in to comment.