|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; |
| 7 | +import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; |
| 8 | +import { EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions'; |
| 9 | +import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; |
| 10 | +import { localize } from 'vs/nls'; |
| 11 | +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; |
| 12 | +import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; |
| 13 | + |
| 14 | +class DiffReviewNext extends EditorAction { |
| 15 | + constructor() { |
| 16 | + super({ |
| 17 | + id: 'editor.action.diffReview.next', |
| 18 | + label: localize('editor.action.diffReview.next', "Go to Next Difference"), |
| 19 | + alias: 'Go to Next Difference', |
| 20 | + precondition: ContextKeyExpr.has('isInDiffEditor'), |
| 21 | + kbOpts: { |
| 22 | + kbExpr: null, |
| 23 | + primary: KeyCode.F7, |
| 24 | + weight: KeybindingWeight.EditorContrib |
| 25 | + } |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + public run(accessor: ServicesAccessor, editor: ICodeEditor): void { |
| 30 | + const diffEditor = findFocusedDiffEditor(accessor); |
| 31 | + diffEditor?.diffReviewNext(); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +class DiffReviewPrev extends EditorAction { |
| 36 | + constructor() { |
| 37 | + super({ |
| 38 | + id: 'editor.action.diffReview.prev', |
| 39 | + label: localize('editor.action.diffReview.prev', "Go to Previous Difference"), |
| 40 | + alias: 'Go to Previous Difference', |
| 41 | + precondition: ContextKeyExpr.has('isInDiffEditor'), |
| 42 | + kbOpts: { |
| 43 | + kbExpr: null, |
| 44 | + primary: KeyMod.Shift | KeyCode.F7, |
| 45 | + weight: KeybindingWeight.EditorContrib |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + public run(accessor: ServicesAccessor, editor: ICodeEditor): void { |
| 51 | + const diffEditor = findFocusedDiffEditor(accessor); |
| 52 | + diffEditor?.diffReviewPrev(); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +function findFocusedDiffEditor(accessor: ServicesAccessor): IDiffEditor | null { |
| 57 | + const codeEditorService = accessor.get(ICodeEditorService); |
| 58 | + const diffEditors = codeEditorService.listDiffEditors(); |
| 59 | + const activeCodeEditor = codeEditorService.getFocusedCodeEditor() ?? codeEditorService.getActiveCodeEditor(); |
| 60 | + if (!activeCodeEditor) { |
| 61 | + return null; |
| 62 | + } |
| 63 | + |
| 64 | + for (let i = 0, len = diffEditors.length; i < len; i++) { |
| 65 | + const diffEditor = <IDiffEditor>diffEditors[i]; |
| 66 | + if (diffEditor.getModifiedEditor().getId() === activeCodeEditor.getId() || diffEditor.getOriginalEditor().getId() === activeCodeEditor.getId()) { |
| 67 | + return diffEditor; |
| 68 | + } |
| 69 | + } |
| 70 | + return null; |
| 71 | +} |
| 72 | + |
| 73 | +registerEditorAction(DiffReviewNext); |
| 74 | +registerEditorAction(DiffReviewPrev); |
0 commit comments