add content from original editor to modified editor
This commit is contained in:
parent
c1f8778e95
commit
12eafbbd18
@ -5,8 +5,15 @@ ngx-monaco-editor {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
%arrow {
|
||||
border: solid black;
|
||||
border-width: 0 2px 2px 0;
|
||||
}
|
||||
|
||||
::ng-deep ngx-monaco-diff-editor .arrow-left {
|
||||
background: darkred;
|
||||
@extend %arrow;
|
||||
transform: rotate(-45deg);
|
||||
-webkit-transform: rotate(-45deg);
|
||||
cursor: pointer;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Component, Input, OnChanges, OnInit } from '@angular/core';
|
||||
import { Debounce, List } from '@iqser/common-ui';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Debounce, List, OnChange } from '@iqser/common-ui';
|
||||
import IStandaloneEditorConstructionOptions = monaco.editor.IStandaloneEditorConstructionOptions;
|
||||
import ICodeEditor = monaco.editor.ICodeEditor;
|
||||
import IDiffEditor = monaco.editor.IDiffEditor;
|
||||
import IModelDeltaDecoration = monaco.editor.IModelDeltaDecoration;
|
||||
import ILineChange = monaco.editor.ILineChange;
|
||||
import IEditorMouseEvent = monaco.editor.IEditorMouseEvent;
|
||||
|
||||
const MIN_WORD_LENGTH = 2;
|
||||
const lineChangeToDecoration = ({ originalEndLineNumber, originalStartLineNumber }: ILineChange) =>
|
||||
@ -22,11 +23,15 @@ const isPositive = (lineChange: ILineChange) => lineChange.originalEndLineNumber
|
||||
templateUrl: './editor.component.html',
|
||||
styleUrls: ['./editor.component.scss'],
|
||||
})
|
||||
export class EditorComponent implements OnInit, OnChanges {
|
||||
export class EditorComponent implements OnInit {
|
||||
editorOptions: IStandaloneEditorConstructionOptions = {};
|
||||
@Input() showDiffEditor = false;
|
||||
@Input() initialEntries: List;
|
||||
@Input() canEdit = false;
|
||||
@Input()
|
||||
showDiffEditor = false;
|
||||
@Input()
|
||||
@OnChange<List, EditorComponent>('revert')
|
||||
initialEntries: List;
|
||||
@Input()
|
||||
canEdit = false;
|
||||
currentEntries: string[] = [];
|
||||
codeEditor: ICodeEditor;
|
||||
diffEditor: IDiffEditor;
|
||||
@ -68,13 +73,10 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
};
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
this.revert();
|
||||
}
|
||||
|
||||
onDiffEditorInit(editor: IDiffEditor): void {
|
||||
this.diffEditor = editor;
|
||||
this._addMarginButtons();
|
||||
this.diffEditor.getOriginalEditor().onMouseDown(event => this._handleMarginButtonClick(event));
|
||||
}
|
||||
|
||||
onCodeEditorInit(editor: ICodeEditor): void {
|
||||
@ -101,6 +103,21 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
this.currentEntries = [...this.initialEntries];
|
||||
}
|
||||
|
||||
private _handleMarginButtonClick(event: IEditorMouseEvent) {
|
||||
const isNotMarginButtonClick = event.target.position.column !== 1;
|
||||
if (isNotMarginButtonClick) {
|
||||
return;
|
||||
}
|
||||
this._addContentFromOriginalAtLine(event.target.position.lineNumber);
|
||||
}
|
||||
|
||||
private _addContentFromOriginalAtLine(lineNumber: number) {
|
||||
const lineContent = this.diffEditor.getOriginalEditor().getModel().getLineContent(lineNumber);
|
||||
const entriesBefore = this.currentEntries.slice(0, lineNumber);
|
||||
const entriesAfter = this.currentEntries.slice(lineNumber);
|
||||
this.currentEntries = [...entriesBefore, lineContent, ...entriesAfter];
|
||||
}
|
||||
|
||||
private _addMarginButtons() {
|
||||
let glyphDecorations = [];
|
||||
this.diffEditor.onDidUpdateDiff(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user