mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: editor: remember fontSize
This commit is contained in:
1 parent
abeab99cd8
commit
1d72362d49
2 files changed
+26
-35
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
import monaco from 'vj/components/monaco/index';
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
value: state.editor.code,
|
value: state.editor.code,
|
||||||
@@ -19,45 +19,36 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
|
|
||||||
noSemanticValidation: false,
|
|
||||||
noSyntaxValidation: false,
|
|
||||||
});
|
|
||||||
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
|
||||||
target: monaco.languages.typescript.ScriptTarget.ES6,
|
|
||||||
allowNonTsExtensions: true,
|
|
||||||
});
|
|
||||||
const libSource = [
|
|
||||||
'declare function readline(): string;',
|
|
||||||
'declare function print(content: string): void',
|
|
||||||
].join('\n');
|
|
||||||
const libUri = 'ts:filename/basic.d.ts';
|
|
||||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
|
|
||||||
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor extends React.PureComponent {
|
export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor extends React.PureComponent {
|
||||||
|
disposable = [];
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const value = this.props.value || '';
|
const value = this.props.value || '';
|
||||||
const { language, theme } = this.props;
|
const { language, theme } = this.props;
|
||||||
this.model = monaco.editor.createModel(value, language, monaco.Uri.parse('file://model'));
|
this.model = monaco.editor.createModel(value, language, monaco.Uri.parse('file://model'));
|
||||||
if (this.containerElement) {
|
if (this.containerElement) {
|
||||||
this.editor = monaco.editor.create(
|
/** @type {monaco.editor.IStandaloneEditorConstructionOptions} */
|
||||||
this.containerElement,
|
const config = {
|
||||||
{
|
theme,
|
||||||
theme,
|
lineNumbers: true,
|
||||||
lineNumbers: true,
|
glyphMargin: true,
|
||||||
glyphMargin: true,
|
lightbulb: { enabled: true },
|
||||||
lightbulb: {
|
model: this.model,
|
||||||
enabled: true,
|
};
|
||||||
},
|
const fontSize = localStorage.getItem('scratchpad.editor.fontSize');
|
||||||
model: this.model,
|
if (fontSize && !Number.isNaN(+fontSize)) config.fontSize = +fontSize;
|
||||||
}
|
this.editor = monaco.editor.create(this.containerElement, config);
|
||||||
|
this.disposable.push(
|
||||||
|
this.editor.onDidChangeModelContent((event) => {
|
||||||
|
if (!this.__prevent_trigger_change_event) {
|
||||||
|
this.props.handleUpdateCode(this.editor.getValue(), event);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
this.editor.onDidChangeConfiguration(() => {
|
||||||
|
const current = this.editor.getOptions()._values[40].fontSize;
|
||||||
|
localStorage.setItem('scratchpad.editor.fontSize', current);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
this._subscription = this.editor.onDidChangeModelContent((event) => {
|
|
||||||
if (!this.__prevent_trigger_change_event) {
|
|
||||||
this.props.handleUpdateCode(this.editor.getValue(), event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
window.editor = this.editor;
|
window.editor = this.editor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,7 +88,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
|
|||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this.editor) this.editor.dispose();
|
if (this.editor) this.editor.dispose();
|
||||||
if (this.model) this.model.dispose();
|
if (this.model) this.model.dispose();
|
||||||
if (this._subscription) this._subscription.dispose();
|
this.disposable.map((i) => i());
|
||||||
}
|
}
|
||||||
|
|
||||||
assignRef = (component) => {
|
assignRef = (component) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.8.41",
|
"version": "4.8.42",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
Reference in new issue
Block a user