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

[FIX, UI] Editor size depending on parent #4871

Merged
merged 6 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 21 additions & 21 deletions static/js/appbundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/appbundle.js.map

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions static/js/cm-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export class HedyCodeMirrorEditorCreator implements HedyEditorCreator {
export class HedyCodeMirrorEditor implements HedyEditor {
private view: EditorView;
private readMode = new Compartment; // Configuration for the editor read mode
private theme = new Compartment;
private themeStyles: Record<string, any>;
private editorEvent = new EventEmitter<EditorEvent>({
change: true,
guttermousedown: true,
Expand All @@ -75,9 +73,10 @@ export class HedyCodeMirrorEditor implements HedyEditor {
private incorrectLineMapping: Record<string, number> = {};

constructor(element: HTMLElement, isReadOnly: boolean, _: EditorType, __: string = "ltr") {
this.themeStyles = {

const mainEditorStyling = EditorView.baseTheme({
"&": {
height: "352px",
height: "22rem",
background: '#272822',
fontSize: '15.2px',
color: 'white',
Expand All @@ -91,16 +90,14 @@ export class HedyCodeMirrorEditor implements HedyEditor {

".cm-gutters": {
borderRadius: '4px'
}
}

const cursorStyle = { ".cm-cursor, .cm-dropCursor": {borderLeftColor: "white", borderLeftWidth: "2px"} }
const mainEditorStyling = EditorView.theme(this.themeStyles);
},
".cm-cursor, .cm-dropCursor": {borderLeftColor: "white", borderLeftWidth: "2px"}
});

const state = EditorState.create({
doc: '',
extensions: [
EditorView.theme(cursorStyle),
extensions: [
mainEditorStyling,
breakpointGutter,
lineNumbers(),
highlightActiveLineGutter(),
Expand All @@ -119,7 +116,6 @@ export class HedyCodeMirrorEditor implements HedyEditor {
...historyKeymap,
]),
monokai,
this.theme.of(mainEditorStyling),
this.readMode.of(EditorState.readOnly.of(isReadOnly)),
errorLineField,
debugLineField,
Expand All @@ -137,7 +133,15 @@ export class HedyCodeMirrorEditor implements HedyEditor {
if (theLevel) {
this.setHighlighterForLevel(theLevel);
}

// Size the editor depending on the height of its parent
this.view.requestMeasure({
read: () => {
return document.getElementById('editor')!.offsetHeight
},
write(measure, view) {
view.dom.style.height = `${measure}px`;
},
})
}

/**
Expand Down Expand Up @@ -222,12 +226,7 @@ export class HedyCodeMirrorEditor implements HedyEditor {
console.log('Error! When resizing a CodeMirror instance, you need to provide the new height');
return;
}
// Change the size of the container element of the editor
// Via reconfiguring the editors theme
this.themeStyles['&'].height = `${newHeight}px`;
this.view.dispatch({
effects: this.theme.reconfigure(EditorView.theme(this.themeStyles))
});
this.view.dom.style.height = `${newHeight}px`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/incl/editor-and-output.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>
<!-- Row 1: editor, output pane -->
<div class="flex flex-col order-1 relative" id="code_editor" {% if raw %} style="height: 14rem;" {% else %} style="min-height: 22rem;" {% endif %}>
<div class="flex flex-col order-1 relative" id="code_editor" {% if raw %} style="height: 14rem;" {% else %} style="height: 22rem;" {% endif %}>
<div id="fold_in_toggle_container" class="hidden md:flex absolute z-10 top-16 ltr:-right-1 rtl:-left-1 cursor-pointer" onclick="hedyApp.hide_editor();">
<div id="text_field" class="bg-green-500 text-white py-3 rounded-lg text-sm">
<span>←</span>
Expand Down
Loading