diff options
Diffstat (limited to 'app/assets/javascripts/ide/lib/editor.js')
-rw-r--r-- | app/assets/javascripts/ide/lib/editor.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/app/assets/javascripts/ide/lib/editor.js b/app/assets/javascripts/ide/lib/editor.js index 25224abd77c..4dfc27117c0 100644 --- a/app/assets/javascripts/ide/lib/editor.js +++ b/app/assets/javascripts/ide/lib/editor.js @@ -1,11 +1,11 @@ import { debounce } from 'lodash'; -import { editor as monacoEditor, KeyCode, KeyMod } from 'monaco-editor'; +import { editor as monacoEditor, KeyCode, KeyMod, Range } from 'monaco-editor'; import store from '../stores'; import DecorationsController from './decorations/controller'; import DirtyDiffController from './diff/controller'; import Disposable from './common/disposable'; import ModelManager from './common/model_manager'; -import editorOptions, { defaultEditorOptions } from './editor_options'; +import { editorOptions, defaultEditorOptions, defaultDiffEditorOptions } from './editor_options'; import { themes } from './themes'; import languages from './languages'; import keymap from './keymap.json'; @@ -37,6 +37,10 @@ export default class Editor { ...defaultEditorOptions, ...options, }; + this.diffOptions = { + ...defaultDiffEditorOptions, + ...options, + }; setupThemes(); registerLanguages(...languages); @@ -66,19 +70,14 @@ export default class Editor { } } - createDiffInstance(domElement, readOnly = true) { + createDiffInstance(domElement) { if (!this.instance) { clearDomElement(domElement); this.disposable.add( (this.instance = monacoEditor.createDiffEditor(domElement, { - ...this.options, - quickSuggestions: false, - occurrencesHighlight: false, + ...this.diffOptions, renderSideBySide: Editor.renderSideBySide(domElement), - readOnly, - renderLineHighlight: readOnly ? 'all' : 'none', - hideCursorInOverviewRuler: !readOnly, })), ); @@ -187,6 +186,21 @@ export default class Editor { }); } + replaceSelectedText(text) { + let selection = this.instance.getSelection(); + const range = new Range( + selection.startLineNumber, + selection.startColumn, + selection.endLineNumber, + selection.endColumn, + ); + + this.instance.executeEdits('', [{ range, text }]); + + selection = this.instance.getSelection(); + this.instance.setPosition({ lineNumber: selection.endLineNumber, column: selection.endColumn }); + } + get isDiffEditorType() { return this.instance.getEditorType() === 'vs.editor.IDiffEditor'; } |