Skip to content

Commit 8611205

Browse files
authored
Merge pull request #134 from smacker/fix_codemirror
Reload codemirror when fonts are loaded
2 parents 39c1ba8 + 4f34402 commit 8611205

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

frontend/src/components/QueryBox.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class QueryBox extends Component {
5252
schema: undefined,
5353
codeMirrorTables: {}
5454
};
55+
56+
this.codemirror = React.createRef();
5557
}
5658

5759
static getDerivedStateFromProps(nextProps, prevState) {
@@ -65,6 +67,18 @@ class QueryBox extends Component {
6567
};
6668
}
6769

70+
componentDidMount() {
71+
// IE or old browsers
72+
if (!document.fonts || !document.fonts.ready) {
73+
return;
74+
}
75+
76+
// we use custom font, codemirror needs refresh when the font is loaded
77+
document.fonts.ready.then(() => {
78+
this.codemirror.current.editor.refresh();
79+
});
80+
}
81+
6882
static schemaToCodeMirror(schema) {
6983
if (!schema) {
7084
return {};
@@ -105,6 +119,7 @@ class QueryBox extends Component {
105119
<Row className="codemirror-row no-spacing">
106120
<Col xs={12} className="codemirror-col no-spacing">
107121
<CodeMirror
122+
ref={this.codemirror}
108123
value={this.props.sql}
109124
options={options}
110125
onBeforeChange={(editor, data, value) => {

0 commit comments

Comments
 (0)