pull/4791/head
filip mertens 6 months ago
parent 3866568488
commit e8b6a2fe92
  1. 178
      libs/remix-ui/editor/src/lib/actions/editor.ts
  2. 4
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx
  3. 2
      libs/remix-ui/git/src/lib/gitactions.ts

@ -14,103 +14,103 @@ export const reducerActions = (models = initialState, action: Action) => {
const monaco = action.monaco const monaco = action.monaco
const editors = action.editors as any[] const editors = action.editors as any[]
switch (action.type) { switch (action.type) {
case 'ADD_MODEL': { case 'ADD_MODEL': {
if (!editors) return models if (!editors) return models
const uri = action.payload.uri const uri = action.payload.uri
const value = action.payload.value const value = action.payload.value
const language = action.payload.language const language = action.payload.language
const readOnly = action.payload.readOnly const readOnly = action.payload.readOnly
if (models[uri]) return models // already existing if (models[uri]) return models // already existing
models[uri] = { language, uri, readOnly } models[uri] = { language, uri, readOnly }
let model let model
try { try {
model = monaco.editor.createModel(value, language, monaco.Uri.parse(uri)) model = monaco.editor.createModel(value, language, monaco.Uri.parse(uri))
} catch (e) { } 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': { models[uri].model = model
if (!editors) return models model.onDidChangeContent(() => action.payload.events.onDidChangeContent(uri))
const uri = action.payload.uri return models
const value = action.payload.value }
const model = models[uri]?.model case 'DISPOSE_MODEL': {
if (model) { const uri = action.payload.uri
model.setValue(value) const model = models[uri]?.model
} if (model) model.dispose()
return models 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': { return models
if (!editors) return models }
const line = action.payload.line case 'REVEAL_LINE': {
const column = action.payload.column if (!editors) return models
const line = action.payload.line
const column = action.payload.column
editors.map((editor) => { editors.map((editor) => {
editor.revealLine(line) editor.revealLine(line)
editor.setPosition({ column, lineNumber: line }) editor.setPosition({ column, lineNumber: line })
}) })
return models 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': { // reset to start of line
if (!editors) return models if (action.payload.startColumn < 100) {
const range: monacoTypes.IRange = { editors.map(editor => editor.revealRange({
startLineNumber: action.payload.startLineNumber + 1, startLineNumber: range.startLineNumber,
startColumn: action.payload.startColumn, startColumn: 1,
endLineNumber: action.payload.endLineNumber + 1, endLineNumber: range.endLineNumber,
endColumn: action.payload.endColumn endColumn: 1
} }))
// reset to start of line } else {
if (action.payload.startColumn < 100) { editors.map(editor => editor.revealRangeInCenter(range))
editors.map(editor => editor.revealRange({ }
startLineNumber: range.startLineNumber, return models
startColumn: 1, }
endLineNumber: range.endLineNumber, case 'FOCUS': {
endColumn: 1 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 { } else {
editors.map(editor => editor.revealRangeInCenter(range)) editor.trigger('keyboard', 'editor.action.fontZoomOut', {});
} }
return models })
} return models
case 'FOCUS': { }
if (!editors) return models case 'SET_WORDWRAP': {
editors.map(editor => editor.focus()) if (!editors) return models
return models const wrap = action.payload.wrap
} editors.map(editor =>
case 'SET_FONTSIZE': { editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' }))
if (!editors) return models 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
}
} }
} }

@ -637,7 +637,7 @@ export const EditorUI = (props: EditorUIProps) => {
// 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()], props.events) // 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) reducerListener(props.plugin, dispatch, monacoRef.current, [diffEditorRef.current.getModifiedEditor(), editorRef.current], props.events)
} }
} }
@ -975,7 +975,7 @@ export const EditorUI = (props: EditorUIProps) => {
width='100%' width='100%'
height={props.isDiff ? '100%' : '0%'} height={props.isDiff ? '100%' : '0%'}
className={props.isDiff ? "d-block" : "d-none"} className={props.isDiff ? "d-block" : "d-none"}
/> />
<Editor <Editor
width="100%" width="100%"

@ -218,7 +218,7 @@ export const addall = async (files: fileStatusResult[]) => {
export const add = async (filepath: addInput) => { export const add = async (filepath: addInput) => {
try { try {
if(typeof filepath.filepath === "string") { if (typeof filepath.filepath === "string") {
filepath.filepath = removeSlash(filepath.filepath) filepath.filepath = removeSlash(filepath.filepath)
} }
await plugin.call('dgitApi', 'add', filepath); await plugin.call('dgitApi', 'add', filepath);

Loading…
Cancel
Save