Skip to content

Commit 48489f7

Browse files
authored
Size editor to content and force pan-y for touch events (#271)
1 parent ca3e5f8 commit 48489f7

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

ggsql-wasm/demo/src/quarto/editor.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,8 @@ export interface EditorInstance {
176176
editor: monaco.editor.IStandaloneCodeEditor;
177177
}
178178

179-
const LINE_HEIGHT = 20;
180179
const PADDING_TOP = 8;
181180
const PADDING_BOTTOM = 8;
182-
const MAX_EDITOR_HEIGHT = 400;
183-
184-
function editorHeight(lineCount: number): number {
185-
const contentHeight = lineCount * LINE_HEIGHT + PADDING_TOP + PADDING_BOTTOM;
186-
return Math.min(contentHeight, MAX_EDITOR_HEIGHT);
187-
}
188181

189182
export async function createEditor(
190183
container: HTMLElement,
@@ -193,9 +186,6 @@ export async function createEditor(
193186
): Promise<EditorInstance> {
194187
await ensureLanguageRegistered(siteRoot);
195188

196-
const lineCount = initialValue.split("\n").length;
197-
container.style.height = editorHeight(lineCount) + "px";
198-
199189
const editor = monaco.editor.create(container, {
200190
value: initialValue,
201191
language: "ggsql",
@@ -224,8 +214,8 @@ export async function createEditor(
224214

225215
// Auto-resize editor height to content
226216
editor.onDidContentSizeChange(() => {
227-
const newLineCount = editor.getModel()?.getLineCount() || lineCount;
228-
container.style.height = editorHeight(newLineCount) + "px";
217+
const contentHeight = editor.getContentHeight();
218+
container.style.height = contentHeight + "px";
229219
editor.layout();
230220
});
231221

ggsql-wasm/demo/src/quarto/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
display: none;
3030
}
3131

32+
.ggsql-editor-wrapper .monaco-editor .overflow-guard {
33+
touch-action: pan-y !important;
34+
}
35+
3236
.ggsql-error-display.visible {
3337
display: block;
3438
}

0 commit comments

Comments
 (0)