|
|
@ -12,10 +12,10 @@ export const initialState = {} |
|
|
|
|
|
|
|
|
|
|
|
export const reducerActions = (models = initialState, action: Action) => { |
|
|
|
export const reducerActions = (models = initialState, action: Action) => { |
|
|
|
const monaco = action.monaco |
|
|
|
const monaco = action.monaco |
|
|
|
const editor = action.editor |
|
|
|
const editors = action.editor as any[] |
|
|
|
switch (action.type) { |
|
|
|
switch (action.type) { |
|
|
|
case 'ADD_MODEL': { |
|
|
|
case 'ADD_MODEL': { |
|
|
|
if (!editor) 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 |
|
|
@ -40,11 +40,11 @@ export const reducerActions = (models = initialState, action: Action) => { |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'ADD_DIFF': { |
|
|
|
case 'ADD_DIFF': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'SET_VALUE': { |
|
|
|
case 'SET_VALUE': { |
|
|
|
if (!editor) 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 model = models[uri]?.model |
|
|
|
const model = models[uri]?.model |
|
|
@ -54,15 +54,17 @@ export const reducerActions = (models = initialState, action: Action) => { |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'REVEAL_LINE': { |
|
|
|
case 'REVEAL_LINE': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
const line = action.payload.line |
|
|
|
const line = action.payload.line |
|
|
|
const column = action.payload.column |
|
|
|
const column = action.payload.column |
|
|
|
|
|
|
|
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': { |
|
|
|
case 'REVEAL_RANGE': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
const range: monacoTypes.IRange = { |
|
|
|
const range: monacoTypes.IRange = { |
|
|
|
startLineNumber: action.payload.startLineNumber + 1, |
|
|
|
startLineNumber: action.payload.startLineNumber + 1, |
|
|
|
startColumn: action.payload.startColumn, |
|
|
|
startColumn: action.payload.startColumn, |
|
|
@ -71,48 +73,51 @@ export const reducerActions = (models = initialState, action: Action) => { |
|
|
|
} |
|
|
|
} |
|
|
|
// reset to start of line
|
|
|
|
// reset to start of line
|
|
|
|
if (action.payload.startColumn < 100) { |
|
|
|
if (action.payload.startColumn < 100) { |
|
|
|
editor.revealRange({ |
|
|
|
editors.map(editor => editor.revealRange({ |
|
|
|
startLineNumber: range.startLineNumber, |
|
|
|
startLineNumber: range.startLineNumber, |
|
|
|
startColumn: 1, |
|
|
|
startColumn: 1, |
|
|
|
endLineNumber: range.endLineNumber, |
|
|
|
endLineNumber: range.endLineNumber, |
|
|
|
endColumn: 1 |
|
|
|
endColumn: 1 |
|
|
|
}) |
|
|
|
})) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
editor.revealRangeInCenter(range) |
|
|
|
editors.map(editor => editor.revealRangeInCenter(range)) |
|
|
|
} |
|
|
|
} |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'FOCUS': { |
|
|
|
case 'FOCUS': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
editor.focus() |
|
|
|
editors.map(editor => editor.focus()) |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'SET_FONTSIZE': { |
|
|
|
case 'SET_FONTSIZE': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
const size = action.payload.size |
|
|
|
const size = action.payload.size |
|
|
|
|
|
|
|
editors.map((editor) => { |
|
|
|
if (size === 1) { |
|
|
|
if (size === 1) { |
|
|
|
editor.trigger('keyboard', 'editor.action.fontZoomIn', {}); |
|
|
|
editor.trigger('keyboard', 'editor.action.fontZoomIn', {}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
editor.trigger('keyboard', 'editor.action.fontZoomOut', {}); |
|
|
|
editor.trigger('keyboard', 'editor.action.fontZoomOut', {}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
case 'SET_WORDWRAP': { |
|
|
|
case 'SET_WORDWRAP': { |
|
|
|
if (!editor) return models |
|
|
|
if (!editors) return models |
|
|
|
const wrap = action.payload.wrap |
|
|
|
const wrap = action.payload.wrap |
|
|
|
editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' }) |
|
|
|
editors.map(editor => |
|
|
|
|
|
|
|
editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' })) |
|
|
|
return models |
|
|
|
return models |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
export const reducerListener = (plugin, dispatch, monaco, editors: any[], events) => { |
|
|
|
plugin.on('editor', 'addModel', (value, language, uri, readOnly) => { |
|
|
|
plugin.on('editor', 'addModel', (value, language, uri, readOnly) => { |
|
|
|
dispatch({ |
|
|
|
dispatch({ |
|
|
|
type: 'ADD_MODEL', |
|
|
|
type: 'ADD_MODEL', |
|
|
|
payload: { uri, value, language, readOnly, events }, |
|
|
|
payload: { uri, value, language, readOnly, events }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -121,7 +126,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'ADD_DIFF', |
|
|
|
type: 'ADD_DIFF', |
|
|
|
payload: { value }, |
|
|
|
payload: { value }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -130,7 +135,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'DISPOSE_MODEL', |
|
|
|
type: 'DISPOSE_MODEL', |
|
|
|
payload: { uri }, |
|
|
|
payload: { uri }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -139,7 +144,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'SET_VALUE', |
|
|
|
type: 'SET_VALUE', |
|
|
|
payload: { uri, value }, |
|
|
|
payload: { uri, value }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -148,7 +153,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'REVEAL_LINE', |
|
|
|
type: 'REVEAL_LINE', |
|
|
|
payload: { line, column }, |
|
|
|
payload: { line, column }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -162,7 +167,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
endColumn |
|
|
|
endColumn |
|
|
|
}, |
|
|
|
}, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -171,7 +176,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'FOCUS', |
|
|
|
type: 'FOCUS', |
|
|
|
payload: {}, |
|
|
|
payload: {}, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -180,7 +185,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'SET_FONTSIZE', |
|
|
|
type: 'SET_FONTSIZE', |
|
|
|
payload: { size }, |
|
|
|
payload: { size }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -189,7 +194,7 @@ export const reducerListener = (plugin, dispatch, monaco, editor, events) => { |
|
|
|
type: 'SET_WORDWRAP', |
|
|
|
type: 'SET_WORDWRAP', |
|
|
|
payload: { wrap }, |
|
|
|
payload: { wrap }, |
|
|
|
monaco, |
|
|
|
monaco, |
|
|
|
editor |
|
|
|
editors |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|