Skip to content

Commit 4e370ba

Browse files
committed
Add F7, Shift+F7
1 parent 44fceab commit 4e370ba

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
327327
return this._renderIndicators;
328328
}
329329

330+
public hasWidgetFocus(): boolean {
331+
return dom.isAncestor(document.activeElement, this._domElement);
332+
}
333+
334+
public diffReviewNext(): void {
335+
this._reviewPane.next();
336+
}
337+
338+
public diffReviewPrev(): void {
339+
this._reviewPane.prev();
340+
}
341+
330342
private static _getClassName(theme: ITheme, renderSideBySide: boolean): string {
331343
let result = 'monaco-diff-editor monaco-editor-background ';
332344
if (renderSideBySide) {

src/vs/editor/browser/widget/diffReview.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { editorLineNumbers } from "vs/editor/common/view/editorColorRegistry";
2424
import { KeyCode, KeyMod } from "vs/base/common/keyCodes";
2525
import { ActionBar } from "vs/base/browser/ui/actionbar/actionbar";
2626
import { Action } from "vs/base/common/actions";
27+
import { editorAction, EditorAction, ServicesAccessor } from "vs/editor/common/editorCommonExtensions";
28+
import { ContextKeyExpr } from "vs/platform/contextkey/common/contextkey";
29+
import { ICodeEditorService } from "vs/editor/common/services/codeEditorService";
2730

2831
const DIFF_LINES_PADDING = 3;
2932

@@ -166,6 +169,68 @@ export class DiffReview extends Disposable {
166169
this._currentDiff = null;
167170
}
168171

172+
public prev(): void {
173+
let index = 0;
174+
175+
if (!this._isVisible) {
176+
this._diffs = this._compute();
177+
}
178+
179+
if (this._isVisible) {
180+
let currentIndex = -1;
181+
for (let i = 0, len = this._diffs.length; i < len; i++) {
182+
if (this._diffs[i] === this._currentDiff) {
183+
currentIndex = i;
184+
break;
185+
}
186+
}
187+
index = (this._diffs.length + currentIndex - 1);
188+
}
189+
190+
if (this._diffs.length === 0) {
191+
// Nothing to do
192+
return;
193+
}
194+
195+
index = index % this._diffs.length;
196+
this._diffEditor.setPosition(new Position(this._diffs[index].entries[0].modifiedLineStart, 1));
197+
this._isVisible = true;
198+
this._diffEditor.doLayout();
199+
this._render();
200+
this._goToRow(this._getNextRow());
201+
}
202+
203+
public next(): void {
204+
let index = 0;
205+
206+
if (!this._isVisible) {
207+
this._diffs = this._compute();
208+
}
209+
210+
if (this._isVisible) {
211+
let currentIndex = -1;
212+
for (let i = 0, len = this._diffs.length; i < len; i++) {
213+
if (this._diffs[i] === this._currentDiff) {
214+
currentIndex = i;
215+
break;
216+
}
217+
}
218+
index = (currentIndex + 1);
219+
}
220+
221+
if (this._diffs.length === 0) {
222+
// Nothing to do
223+
return;
224+
}
225+
226+
index = index % this._diffs.length;
227+
this._diffEditor.setPosition(new Position(this._diffs[index].entries[0].modifiedLineStart, 1));
228+
this._isVisible = true;
229+
this._diffEditor.doLayout();
230+
this._render();
231+
this._goToRow(this._getNextRow());
232+
}
233+
169234
private accept(): void {
170235
let current = this._getCurrentFocusedRow();
171236
if (current) {
@@ -676,3 +741,61 @@ registerThemingParticipant((theme, collector) => {
676741
collector.addRule(`.monaco-diff-editor .diff-review-shadow { box-shadow: ${shadow} 0 -6px 6px -6px inset; }`);
677742
}
678743
});
744+
745+
@editorAction
746+
class DiffReviewNext extends EditorAction {
747+
constructor() {
748+
super({
749+
id: 'editor.action.diffReview.next',
750+
label: nls.localize('editor.action.diffReview.next', "Go to Next Difference"),
751+
alias: 'Go to Next Difference',
752+
precondition: ContextKeyExpr.has('isInDiffEditor'),
753+
kbOpts: {
754+
kbExpr: null,
755+
primary: KeyCode.F7
756+
}
757+
});
758+
}
759+
760+
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
761+
const diffEditor = findFocusedDiffEditor(accessor);
762+
if (diffEditor) {
763+
diffEditor.diffReviewNext();
764+
}
765+
}
766+
}
767+
768+
@editorAction
769+
class DiffReviewPrev extends EditorAction {
770+
constructor() {
771+
super({
772+
id: 'editor.action.diffReview.prev',
773+
label: nls.localize('editor.action.diffReview.prev', "Go to Previous Difference"),
774+
alias: 'Go to Previous Difference',
775+
precondition: ContextKeyExpr.has('isInDiffEditor'),
776+
kbOpts: {
777+
kbExpr: null,
778+
primary: KeyMod.Shift | KeyCode.F7
779+
}
780+
});
781+
}
782+
783+
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
784+
const diffEditor = findFocusedDiffEditor(accessor);
785+
if (diffEditor) {
786+
diffEditor.diffReviewPrev();
787+
}
788+
}
789+
}
790+
791+
function findFocusedDiffEditor(accessor: ServicesAccessor): DiffEditorWidget {
792+
const codeEditorService = accessor.get(ICodeEditorService);
793+
const diffEditors = codeEditorService.listDiffEditors();
794+
for (let i = 0, len = diffEditors.length; i < len; i++) {
795+
const diffEditor = <DiffEditorWidget>diffEditors[i];
796+
if (diffEditor.hasWidgetFocus()) {
797+
return diffEditor;
798+
}
799+
}
800+
return null;
801+
}

0 commit comments

Comments
 (0)