-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render conflict actions (#2002)
* feat: implement conflict actions base code * chore: improve code
- Loading branch information
Showing
13 changed files
with
319 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/monaco/src/browser/contrib/merge-editor/model/conflict-actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Injectable, Optional } from '@opensumi/di'; | ||
import { Disposable } from '@opensumi/ide-core-common'; | ||
import { IEditorDecorationsCollection } from '@opensumi/monaco-editor-core/esm/vs/editor/common/editorCommon'; | ||
import { ModelDecorationOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/common/model/textModel'; | ||
|
||
import { ICodeEditor, IModelDeltaDecoration } from '../../../monaco-api/editor'; | ||
import { IActionsDescription } from '../types'; | ||
import { BaseCodeEditor } from '../view/editors/baseCodeEditor'; | ||
|
||
import { LineRange } from './line-range'; | ||
|
||
@Injectable({ multiple: false }) | ||
export class ConflictActions extends Disposable { | ||
private decorationsCollection: IEditorDecorationsCollection; | ||
private actionsCollect: Map<number, LineRange>; | ||
|
||
private get editor(): ICodeEditor { | ||
return this.codeEditor.getEditor(); | ||
} | ||
|
||
constructor(@Optional() private readonly codeEditor: BaseCodeEditor) { | ||
super(); | ||
|
||
this.decorationsCollection = this.editor.createDecorationsCollection(); | ||
this.actionsCollect = new Map(); | ||
} | ||
|
||
public override dispose(): void { | ||
super.dispose(); | ||
this.decorationsCollection.clear(); | ||
this.actionsCollect.clear(); | ||
} | ||
|
||
public setActions(actions: IActionsDescription[]): void { | ||
const newDecorations: IModelDeltaDecoration[] = actions.map((action) => { | ||
const { range } = action; | ||
this.actionsCollect.set(range.startLineNumber, range); | ||
|
||
return { | ||
range: { | ||
startLineNumber: range.startLineNumber, | ||
startColumn: 0, | ||
endLineNumber: range.startLineNumber, | ||
endColumn: 0, | ||
}, | ||
options: ModelDecorationOptions.register(action.decorationOptions), | ||
}; | ||
}); | ||
|
||
this.decorationsCollection.set(newDecorations); | ||
} | ||
|
||
public getActions(line: number): LineRange | undefined { | ||
return this.actionsCollect.get(line); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/monaco/src/browser/contrib/merge-editor/model/sticky-piece.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/monaco/src/browser/contrib/merge-editor/view/actions-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Disposable } from '@opensumi/ide-core-common'; | ||
import { IEditorMouseEvent, MouseTargetType } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser'; | ||
|
||
import { IActionsDescription } from '../types'; | ||
|
||
import { BaseCodeEditor } from './editors/baseCodeEditor'; | ||
|
||
export class ActionsManager extends Disposable { | ||
private currentView: BaseCodeEditor | undefined; | ||
private resultView: BaseCodeEditor | undefined; | ||
private incomingView: BaseCodeEditor | undefined; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
public mount(currentView: BaseCodeEditor, resultView: BaseCodeEditor, incomingView: BaseCodeEditor): void { | ||
this.currentView = currentView; | ||
this.resultView = resultView; | ||
this.incomingView = incomingView; | ||
|
||
const handleMouseDown = (e: IEditorMouseEvent, _this: BaseCodeEditor) => { | ||
const provider = _this.actionsProvider; | ||
if (!provider) { | ||
return; | ||
} | ||
|
||
let { mouseDownGuard } = provider; | ||
const { onActionsClick, provideActionsItems } = provider; | ||
|
||
if (typeof mouseDownGuard === 'undefined') { | ||
const items = provideActionsItems(); | ||
mouseDownGuard = (e: IEditorMouseEvent) => { | ||
if (e.event.rightButton) { | ||
return false; | ||
} | ||
|
||
if (e.target.type !== MouseTargetType.GUTTER_LINE_DECORATIONS) { | ||
return false; | ||
} | ||
|
||
const { position } = e.target; | ||
|
||
if (!items.some((item: IActionsDescription) => item.range.startLineNumber === position.lineNumber)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
} | ||
|
||
if (mouseDownGuard(e) === true && onActionsClick) { | ||
onActionsClick.call(_this, e, currentView, resultView, incomingView); | ||
} | ||
}; | ||
|
||
this.addDispose(currentView.getEditor().onMouseDown((e: IEditorMouseEvent) => handleMouseDown(e, currentView))); | ||
this.addDispose(incomingView.getEditor().onMouseDown((e: IEditorMouseEvent) => handleMouseDown(e, incomingView))); | ||
this.addDispose(resultView.getEditor().onMouseDown((e: IEditorMouseEvent) => handleMouseDown(e, resultView))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.