mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: editor: always use LF as line ending
This commit is contained in:
1 parent
32bf5b9a7e
commit
c4521d9ce3
4 files changed
+10
-10
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.34.0",
|
||||
"version": "4.34.1",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
Reference in new issue
Block a user