Implements multiline expression input.

This commit is contained in:
Henning Dieterichs
2020-02-12 15:14:11 +01:00
parent 5f3b320067
commit d1a058b836
2 changed files with 31 additions and 21 deletions

View File

@@ -2,7 +2,6 @@ import React = require("react");
import { Model } from "../Model/Model";
import { observer, disposeOnUnmount } from "mobx-react";
import { observable, action, autorun } from "mobx";
import * as monaco from "monaco-editor";
export function getModel(): monaco.editor.ITextModel {
@@ -15,16 +14,22 @@ export function getModel(): monaco.editor.ITextModel {
@observer
export class ExpressionInput extends React.Component<{ model: Model }> {
@action.bound
submit() {
const val = this.model.getValue();
console.log(val);
this.props.model.setExpression(val);
}
@observable private editor: monaco.editor.IStandaloneCodeEditor | undefined;
@observable private contentHeight: number | undefined = undefined;
private model = getModel();
render() {
return (
<div className="component-monaco-editor">
<div
style={{ height: this.contentHeight }}
className="part-editor"
ref={this.setEditorDiv}
/>
</div>
);
}
componentWillUnmount() {
if (this.editor) {
this.editor.dispose();
@@ -65,20 +70,28 @@ export class ExpressionInput extends React.Component<{ model: Model }> {
},
});
this.editor.onDidContentSizeChange(e => {
this.contentHeight = e.contentHeight;
});
this.editor.onKeyDown(e => {
if (e.keyCode == monaco.KeyCode.Enter) {
e.preventDefault();
e.stopPropagation();
this.submit();
if (
(this.model.getLineCount() <= 1 || e.ctrlKey) &&
!e.shiftKey
) {
e.preventDefault();
e.stopPropagation();
this.submit();
}
}
});
};
render() {
return (
<div className="component-monaco-editor2">
<div className="part-editor" ref={this.setEditorDiv} />
</div>
);
@action.bound
submit() {
const val = this.model.getValue();
console.log(val);
this.props.model.setExpression(val);
}
}

View File

@@ -120,8 +120,7 @@ body,
}
}
.component-monaco-editor2 {
height: 23px;
.component-monaco-editor {
width: 100%;
min-width: 0;
box-sizing: border-box;
@@ -129,8 +128,6 @@ body,
padding: 2px;
background-color: white;
// overflow: hidden;
.part-editor {
min-width: 0;
min-height: 0;