Skip to content

auto-resize editor with max height and scroll #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 33 additions & 3 deletions src/components/InputPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Feedback from "./Feedback.vue";

const GlobalVariables = inject("GlobalVariables");

const emits = defineEmits(["run", "clear"]);
const emits = defineEmits(["run", "clear", "editorHeightChanged"]);

const props = defineProps([
"cypherInput",
Expand All @@ -21,6 +21,22 @@ const tab = ref("");
let cypher = "";
let text = "";
let editor = null;
const minHeight = 3;
const maxHeight = 10;
const lineHeight = 20;
const padding = 10;

const updateEditorHeight = () => {
const lineCount = editor.getModel().getLineCount();
const newHeight = Math.min (
Math.max(lineCount * lineHeight, minHeight * lineHeight), maxHeight * lineHeight
)+ padding;
code.value.style.height = `${newHeight}px`;
if(lineCount<maxHeight){
emits('editorHeightChanged', newHeight);
}
editor.layout();
};

const runQuery = () => {
const getValue = editor.getValue();
Expand Down Expand Up @@ -93,7 +109,20 @@ onMounted(() => {
},
automaticLayout: true,
contextmenu: false,
scrollBeyondLastLine: false,
lineHeight: lineHeight
});

let previousLineCount = editor.getModel().getLineCount();

editor.onDidChangeModelContent(() => {
const currentLineCount = editor.getModel().getLineCount();
if (currentLineCount !== previousLineCount) {
previousLineCount = currentLineCount;
updateEditorHeight();
}
});

window.addEventListener("hitResult", () => {
// console.log(e)
});
Expand Down Expand Up @@ -183,7 +212,8 @@ onMounted(() => {
<style scoped>
.input-container {
width: 100%;
height: 100px;
min-height: v-bind("minHeight * lineHeight + padding + 'px'");
max-height: v-bind("maxHeight * lineHeight + padding + 'px'");
padding-top: 4px;
padding-bottom: 4px;
background-color: #f9fcff;
Expand All @@ -193,7 +223,7 @@ onMounted(() => {
}
.code {
width: 100%;
height: 100%;
height: v-bind("minHeight * lineHeight + padding + 'px'");
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 4px;
Expand Down
9 changes: 9 additions & 0 deletions src/components/OutputPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const errorText = ref("");
const outputPanel = ref();
const isFullscreen = ref(false);
const heightBeforeFullscreen = ref("");
let previousEditorHeight = 0;

const runCypher = async (cypher) => {
loading.value = true;
Expand Down Expand Up @@ -99,6 +100,13 @@ const fullscreenQuery = (isFullscreen) => {
}
};

const handleEditorHeightChange = (newHeight) => {
const diff = newHeight - previousEditorHeight;
previousEditorHeight = newHeight;
const height = outputPanel.value.offsetHeight;
outputPanel.value.style.height = `${height + diff}px`;
};

onMounted(() => {
run(props.query, props.queryTypeInput);
if (!props.disableResizer) {
Expand Down Expand Up @@ -152,6 +160,7 @@ onMounted(() => {
:serve-in-output="true"
@run="run"
@clear="emits('clear')"
@editorHeightChanged="handleEditorHeightChange"
/>
<q-skeleton v-if="loading" width="100%" height="100%" animation="wave" />
<div v-else class="output-container">
Expand Down
Loading