Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate active cell on Shift+Enter #70

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/components/ShellView/CypherEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:style="{ width: editorWidth + 'px' }"
>
<textarea
ref="gptQuestionTextArea"
v-model="gptQuestion"
class="form-control"
placeholder="Type your question here..."
Expand Down Expand Up @@ -44,7 +45,7 @@
data-bs-toggle="tooltip"
data-bs-placement="right"
title="Run"
@click="evaluateCurrentCell"
@click="evaluateCell"
/>
</div>
<div
Expand Down Expand Up @@ -194,11 +195,6 @@ emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'
fontSize: 16,
scrollBeyondLastLine: false,
});

this.editor.addCommand(window.Monaco.KeyMod.Shift | window.Monaco.KeyCode.Enter, () => {
this.evaluateCypher();
});

new PlaceholderContentWidget('Type your Cypher code here...', this.editor);
},
toggleMaximize() {
Expand All @@ -220,7 +216,7 @@ emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'
generateAndEvaluateQuery() {
this.$emit("generateAndEvaluateQuery", this.gptQuestion);
},
evaluateCurrentCell() {
evaluateCell() {
if (this.isQueryGenerationMode) {
this.generateAndEvaluateQuery();
} else {
Expand All @@ -232,6 +228,10 @@ emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'
},
removeCell() {
this.$emit("remove");
},
isActive(){
return (this.isQueryGenerationMode && this.$refs.gptQuestionTextArea === document.activeElement) ||
(!this.isQueryGenerationMode && this.editor && this.editor.hasTextFocus());
}
},
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/ShellView/ShellCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export default {
},

methods: {
isActive(){
return this.$refs.editor.isActive();
},
evaluateCypher(query) {
this.queryResult = null;
this.errorMessage = "";
Expand Down Expand Up @@ -188,6 +191,9 @@ export default {
}
})
},
evaluateCell() {
this.$refs.editor.evaluateCell();
},
toggleMaximize() {
if (this.isMaximized) {
this.minimize();
Expand Down
26 changes: 26 additions & 0 deletions src/components/ShellView/ShellMainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ShellCell
v-for="(cell, index) in shellCell"
v-show="index === maximizedCellIndex || maximizedCellIndex < 0"
:ref="getCellRef(index)"
:key="cell.cellId"
:schema="schema"
:navbar-height="navbarHeight"
Expand Down Expand Up @@ -56,10 +57,12 @@ export default {
this.updateContainerHeight();
});
window.addEventListener("resize", this.updateContainerHeight);
document.addEventListener("keydown",this.handleKeyDown);
},

beforeUnmount() {
window.removeEventListener("resize", this.updateContainerHeight);
document.removeEventListener("keydown",this.handleKeyDown);
},

methods: {
Expand Down Expand Up @@ -97,6 +100,29 @@ export default {
reloadSchema() {
this.$emit("reloadSchema");
},
getCellRef(index) {
return `shell-cell-${this.shellCell[index].cellId}`;
},
handleKeyDown(event) {
if (event.shiftKey && event.key === "Enter") {
event.preventDefault();
this.evaluateCurrentCell();
}
},
evaluateCurrentCell() {
for(let i = 0; i < this.shellCell.length; ++i) {
const currentCell = this.$refs[this.getCellRef(i)][0];
if(currentCell.isActive()) {
return currentCell.evaluateCell();
}
}
try{
const currentCell = this.$refs[this.getCellRef(0)][0];
return currentCell.evaluateCell();
}catch(e){
// Do nothing, there is no cell to evaluate
}
},
},

}
Expand Down