diff --git a/libs/remix-ui/editor/src/lib/actions/editor.ts b/libs/remix-ui/editor/src/lib/actions/editor.ts index 04774f6b57..2ba1f57611 100644 --- a/libs/remix-ui/editor/src/lib/actions/editor.ts +++ b/libs/remix-ui/editor/src/lib/actions/editor.ts @@ -14,103 +14,103 @@ export const reducerActions = (models = initialState, action: Action) => { const monaco = action.monaco const editors = action.editors as any[] switch (action.type) { - case 'ADD_MODEL': { - if (!editors) return models - const uri = action.payload.uri - const value = action.payload.value - const language = action.payload.language - const readOnly = action.payload.readOnly - if (models[uri]) return models // already existing - models[uri] = { language, uri, readOnly } - let model - - try { - model = monaco.editor.createModel(value, language, monaco.Uri.parse(uri)) - } catch (e) { + case 'ADD_MODEL': { + if (!editors) return models + const uri = action.payload.uri + const value = action.payload.value + const language = action.payload.language + const readOnly = action.payload.readOnly + if (models[uri]) return models // already existing + models[uri] = { language, uri, readOnly } + let model + + try { + model = monaco.editor.createModel(value, language, monaco.Uri.parse(uri)) + } catch (e) { - } - models[uri].model = model - model.onDidChangeContent(() => action.payload.events.onDidChangeContent(uri)) - return models - } - case 'DISPOSE_MODEL': { - const uri = action.payload.uri - const model = models[uri]?.model - if (model) model.dispose() - delete models[uri] - return models - } - case 'ADD_DIFF': { - if (!editors) return models - return models } - case 'SET_VALUE': { - if (!editors) return models - const uri = action.payload.uri - const value = action.payload.value - const model = models[uri]?.model - if (model) { - model.setValue(value) - } - return models + models[uri].model = model + model.onDidChangeContent(() => action.payload.events.onDidChangeContent(uri)) + return models + } + case 'DISPOSE_MODEL': { + const uri = action.payload.uri + const model = models[uri]?.model + if (model) model.dispose() + delete models[uri] + return models + } + case 'ADD_DIFF': { + if (!editors) return models + return models + } + case 'SET_VALUE': { + if (!editors) return models + const uri = action.payload.uri + const value = action.payload.value + const model = models[uri]?.model + if (model) { + model.setValue(value) } - case 'REVEAL_LINE': { - if (!editors) return models - const line = action.payload.line - const column = action.payload.column + return models + } + case 'REVEAL_LINE': { + if (!editors) return models + const line = action.payload.line + const column = action.payload.column - editors.map((editor) => { + editors.map((editor) => { - editor.revealLine(line) - editor.setPosition({ column, lineNumber: line }) - }) - return models + editor.revealLine(line) + editor.setPosition({ column, lineNumber: line }) + }) + return models + } + case 'REVEAL_RANGE': { + if (!editors) return models + const range: monacoTypes.IRange = { + startLineNumber: action.payload.startLineNumber + 1, + startColumn: action.payload.startColumn, + endLineNumber: action.payload.endLineNumber + 1, + endColumn: action.payload.endColumn } - case 'REVEAL_RANGE': { - if (!editors) return models - const range: monacoTypes.IRange = { - startLineNumber: action.payload.startLineNumber + 1, - startColumn: action.payload.startColumn, - endLineNumber: action.payload.endLineNumber + 1, - endColumn: action.payload.endColumn - } - // reset to start of line - if (action.payload.startColumn < 100) { - editors.map(editor => editor.revealRange({ - startLineNumber: range.startLineNumber, - startColumn: 1, - endLineNumber: range.endLineNumber, - endColumn: 1 - })) + // reset to start of line + if (action.payload.startColumn < 100) { + editors.map(editor => editor.revealRange({ + startLineNumber: range.startLineNumber, + startColumn: 1, + endLineNumber: range.endLineNumber, + endColumn: 1 + })) + } else { + editors.map(editor => editor.revealRangeInCenter(range)) + } + return models + } + case 'FOCUS': { + if (!editors) return models + editors.map(editor => editor.focus()) + return models + } + case 'SET_FONTSIZE': { + if (!editors) return models + const size = action.payload.size + editors.map((editor) => { + if (size === 1) { + editor.trigger('keyboard', 'editor.action.fontZoomIn', {}); } else { - editors.map(editor => editor.revealRangeInCenter(range)) + editor.trigger('keyboard', 'editor.action.fontZoomOut', {}); } - return models - } - case 'FOCUS': { - if (!editors) return models - editors.map(editor => editor.focus()) - return models - } - case 'SET_FONTSIZE': { - if (!editors) return models - const size = action.payload.size - editors.map((editor) => { - if (size === 1) { - editor.trigger('keyboard', 'editor.action.fontZoomIn', {}); - } else { - editor.trigger('keyboard', 'editor.action.fontZoomOut', {}); - } - }) - return models - } - case 'SET_WORDWRAP': { - if (!editors) return models - const wrap = action.payload.wrap - editors.map(editor => - editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' })) - return models - } + }) + return models + } + case 'SET_WORDWRAP': { + if (!editors) return models + const wrap = action.payload.wrap + editors.map(editor => + editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' })) + return models + } } } diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index c797a7141f..a749dd1fb9 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -637,7 +637,7 @@ export const EditorUI = (props: EditorUIProps) => { // if(diffEditorRef.current && diffEditorRef.current.getModifiedEditor() && !editorRef.current){ // reducerListener(props.plugin, dispatch, monacoRef.current, [diffEditorRef.current.getModifiedEditor()], props.events) // } - if(diffEditorRef.current && diffEditorRef.current.getModifiedEditor() && editorRef.current){ + if (diffEditorRef.current && diffEditorRef.current.getModifiedEditor() && editorRef.current){ reducerListener(props.plugin, dispatch, monacoRef.current, [diffEditorRef.current.getModifiedEditor(), editorRef.current], props.events) } } @@ -975,7 +975,7 @@ export const EditorUI = (props: EditorUIProps) => { width='100%' height={props.isDiff ? '100%' : '0%'} className={props.isDiff ? "d-block" : "d-none"} - + /> { export const add = async (filepath: addInput) => { try { - if(typeof filepath.filepath === "string") { + if (typeof filepath.filepath === "string") { filepath.filepath = removeSlash(filepath.filepath) } await plugin.call('dgitApi', 'add', filepath);