Skip to content

Commit b93b184

Browse files
committed
prep marker model for circle, microsoft#14783
1 parent ddd44e0 commit b93b184

1 file changed

Lines changed: 15 additions & 26 deletions

File tree

src/vs/editor/contrib/gotoError/gotoError.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,40 +109,33 @@ class MarkerModel {
109109
}
110110
}
111111

112-
private move(fwd: boolean): void {
112+
public move(fwd: boolean, circle: boolean): boolean {
113113
if (!this.canNavigate()) {
114114
this._onCurrentMarkerChanged.fire(undefined);
115-
return;
115+
return false;
116116
}
117117

118+
let old = this._nextIdx;
118119
if (this._nextIdx === -1) {
119120
this._initIdx(fwd);
120-
121121
} else if (fwd) {
122-
this._nextIdx += 1;
123-
if (this._nextIdx >= this._markers.length) {
124-
this._nextIdx = 0;
125-
}
122+
this._nextIdx = (this._nextIdx + 1) % this._markers.length;
126123
} else {
127-
this._nextIdx -= 1;
128-
if (this._nextIdx < 0) {
129-
this._nextIdx = this._markers.length - 1;
130-
}
124+
this._nextIdx = (this._nextIdx - 1 + this._markers.length) % this._markers.length;
131125
}
132-
const marker = this._markers[this._nextIdx];
133-
this._onCurrentMarkerChanged.fire(marker);
134-
}
135126

136-
public canNavigate(): boolean {
137-
return this._markers.length > 0;
138-
}
127+
if (circle || old === -1 || fwd && old < this._nextIdx || !fwd && old > this._nextIdx) {
128+
const marker = this._markers[this._nextIdx];
129+
this._onCurrentMarkerChanged.fire(marker);
130+
return false;
131+
}
139132

140-
public next(): void {
141-
this.move(true);
133+
// we circled, didn't send an event, and return `true`
134+
return true;
142135
}
143136

144-
public previous(): void {
145-
this.move(false);
137+
public canNavigate(): boolean {
138+
return this._markers.length > 0;
146139
}
147140

148141
public findMarkerAtPosition(pos: Position): IMarker {
@@ -183,11 +176,7 @@ class MarkerNavigationAction extends EditorAction {
183176
}
184177

185178
const model = controller.getOrCreateModel();
186-
if (this._isNext) {
187-
model.next();
188-
} else {
189-
model.previous();
190-
}
179+
model.move(this._isNext, true);
191180
}
192181
}
193182

0 commit comments

Comments
 (0)