diff --git a/packages/ui-default/components/editor/index.ts b/packages/ui-default/components/editor/index.ts index 10bc5c8aa..8267d9580 100644 --- a/packages/ui-default/components/editor/index.ts +++ b/packages/ui-default/components/editor/index.ts @@ -143,7 +143,7 @@ export default class Editor extends DOMAttachedObject { }); } this.editor.onDidChangeModelContent(() => { - const val = this.editor.getValue(); + const val = this.editor.getValue({ lineEnding: '\n', preserveBOM: false }); $dom.val(val); $dom.text(val); if (onChange) onChange(val); @@ -208,7 +208,7 @@ export default class Editor extends DOMAttachedObject { value(val?: string) { this.ensureValid(); if (typeof val === 'string') return (this.editor || this.vditor).setValue(val); - return (this.editor || this.vditor).getValue(); + return (this.editor || this.vditor).getValue({ lineEnding: '\n', preserveBOM: false }); } focus() { diff --git a/packages/ui-default/components/monaco/index.ts b/packages/ui-default/components/monaco/index.ts index d0f0ad7fc..a2d2209da 100644 --- a/packages/ui-default/components/monaco/index.ts +++ b/packages/ui-default/components/monaco/index.ts @@ -134,7 +134,7 @@ function handlePasteEvent(editor: monaco.editor.IStandaloneCodeEditor) { export function registerAction( editor: monaco.editor.IStandaloneCodeEditor, model: monaco.editor.IModel, - element, + element?, ) { if (element) { editor.addAction({ diff --git a/packages/ui-default/components/scratchpad/ScratchpadEditorContainer.jsx b/packages/ui-default/components/scratchpad/ScratchpadEditorContainer.jsx index af055197d..630970baa 100644 --- a/packages/ui-default/components/scratchpad/ScratchpadEditorContainer.jsx +++ b/packages/ui-default/components/scratchpad/ScratchpadEditorContainer.jsx @@ -1,5 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; +import { load } from 'vj/components/monaco/loader'; const mapStateToProps = (state) => ({ value: state.editor.code, @@ -23,7 +24,6 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e async componentDidMount() { const value = this.props.value || ''; const { language } = this.props; - const { load } = await import('vj/components/monaco/loader'); const { monaco, registerAction, customOptions } = await load([language]); const uri = monaco.Uri.parse(`hydro://${UiContext.pdoc.pid || UiContext.pdoc.docId}.${language}`); this.model = monaco.editor.createModel(value, language, uri); @@ -42,7 +42,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e this.disposable.push( this.editor.onDidChangeModelContent((event) => { if (!this.__prevent_trigger_change_event) { - this.props.handleUpdateCode(this.editor.getValue(), event); + this.props.handleUpdateCode(this.editor.getValue({ lineEnding: '\n', preserveBOM: false }), event); } }), ); @@ -56,7 +56,9 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e value, language, mainSize, recordSize, pretestSize, } = this.props; const { editor, model } = this; - if (this.props.value != null && this.props.value !== model.getValue()) { + const { monaco } = await load([language]); + const { LF } = monaco.editor.EndOfLinePreference; + if (this.props.value != null && this.props.value !== model.getValue(LF, false)) { this.__prevent_trigger_change_event = true; editor.pushUndoStop(); model.pushEditOperations( @@ -71,10 +73,8 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e editor.pushUndoStop(); this.__prevent_trigger_change_event = false; } - const { load } = await import('vj/components/monaco/loader'); - const { monaco } = await load([language]); if (prevProps.language !== language) { - const val = model.getValue(); + const val = model.getValue(LF, false); model.dispose(); const uri = monaco.Uri.parse(`hydro://${UiContext.pdoc.pid || UiContext.pdoc.docId}.${language}`); this.model = monaco.editor.createModel(val, language, uri); diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index b45c1e83f..186992995 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.34.0", + "version": "4.34.1", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js",