Commit 37864fb0 authored by Phil Hughes's avatar Phil Hughes

Multi-file editor dirty diff indicator

[ci skip]
parent 4d89f520
...@@ -14,8 +14,9 @@ export default { ...@@ -14,8 +14,9 @@ export default {
if (this.monaco) { if (this.monaco) {
this.initMonaco(); this.initMonaco();
} else { } else {
monacoLoader(['vs/editor/editor.main'], () => { monacoLoader(['vs/editor/editor.main', 'vs/editor/common/diff/diffComputer'], (_, { DiffComputer }) => {
this.monaco = monaco; this.monaco = monaco;
this.DiffComputer = DiffComputer;
this.initMonaco(); this.initMonaco();
}); });
...@@ -44,8 +45,6 @@ export default { ...@@ -44,8 +45,6 @@ export default {
}); });
this.languages = this.monaco.languages.getLanguages(); this.languages = this.monaco.languages.getLanguages();
this.addMonacoEvents();
} }
this.setupEditor(); this.setupEditor();
...@@ -62,11 +61,50 @@ export default { ...@@ -62,11 +61,50 @@ export default {
const newModel = this.monaco.editor.createModel( const newModel = this.monaco.editor.createModel(
content, foundLang ? foundLang.id : 'plaintext', content, foundLang ? foundLang.id : 'plaintext',
); );
const originalLines = this.monaco.editor.createModel(
this.activeFile.raw, foundLang ? foundLang.id : 'plaintext',
).getLinesContent();
this.monacoInstance.setModel(newModel); this.monacoInstance.setModel(newModel);
}, this.decorations = [];
addMonacoEvents() {
this.monacoInstance.onKeyUp(() => { const modifiedType = (change) => {
if (change.originalEndLineNumber === 0) {
return 'added';
} else if (change.modifiedEndLineNumber === 0) {
return 'removed';
}
return 'modified';
};
this.monacoModelChangeContents = newModel.onDidChangeContent(() => {
const diffComputer = new this.DiffComputer(
originalLines,
newModel.getLinesContent(),
{
shouldPostProcessCharChanges: true,
shouldIgnoreTrimWhitespace: true,
shouldMakePrettyDiff: true,
},
);
this.decorations = this.monacoInstance.deltaDecorations(this.decorations,
diffComputer.computeDiff().map(change => ({
range: new monaco.Range(
change.modifiedStartLineNumber,
1,
!change.modifiedEndLineNumber ?
change.modifiedStartLineNumber : change.modifiedEndLineNumber,
1,
),
options: {
isWholeLine: true,
linesDecorationsClassName: `dirty-diff dirty-diff-${modifiedType(change)}`,
},
})),
);
this.changeFileContent({ this.changeFileContent({
file: this.activeFile, file: this.activeFile,
content: this.monacoInstance.getValue(), content: this.monacoInstance.getValue(),
......
...@@ -302,3 +302,23 @@ ...@@ -302,3 +302,23 @@
.multi-file-table-col-name { .multi-file-table-col-name {
width: 350px; width: 350px;
} }
.dirty-diff {
// !important need to override monaco inline style
width: 4px !important;
left: 0 !important;
&-modified {
background-color: rgb(19, 117, 150);
}
&-added {
background-color: rgb(89, 119, 11);
}
&-removed {
height: 4px!important;
bottom: -2px;
background-color: red;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment