Make distinction between move to line number with and without
intentional move.
If user intentionally wants to move to a specific line number,
default behavior regarding focus should be applied.
Change-Id: Iefbc8b3fe55fb5c95f364acddcd3e7d1aabe22c4
diff --git a/polygerrit-ui/app/api/diff.ts b/polygerrit-ui/app/api/diff.ts
index 905d6be..90d9289 100644
--- a/polygerrit-ui/app/api/diff.ts
+++ b/polygerrit-ui/app/api/diff.ts
@@ -484,5 +484,20 @@
createCommentInPlace(): void;
resetScrollMode(): void;
- moveToLineNumber(lineNum: number, side: Side, path?: string): void;
+
+ /**
+ * Moves to a specific line number in the diff
+ *
+ * @param lineNum which line number should be selected
+ * @param side which side should be selected
+ * @param path file path for the file that should be selected
+ * @param intentionalMove Defines if move-related controls should be applied
+ * (e.g. GrCursorManager.focusOnMove)
+ **/
+ moveToLineNumber(
+ lineNum: number,
+ side: Side,
+ path?: string,
+ intentionalMove?: boolean
+ ): void;
}
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
index 958f367..89ab885 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
@@ -222,11 +222,16 @@
return result;
}
- moveToLineNumber(number: number, side: Side, path?: string) {
+ moveToLineNumber(
+ number: number,
+ side: Side,
+ path?: string,
+ intentionalMove?: boolean
+ ) {
const row = this._findRowByNumberAndFile(number, side, path);
if (row) {
this.side = side;
- this.cursorManager.setCursor(row);
+ this.cursorManager.setCursor(row, undefined, intentionalMove);
}
}
diff --git a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.ts b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.ts
index 9f65dd4..81b6fd4 100644
--- a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.ts
+++ b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.ts
@@ -221,8 +221,10 @@
*
* @param noScroll prevent any potential scrolling in response
* setting the cursor.
+ * @param applyFocus indicates if it should try to focus after move operation
+ * (e.g. focusOnMove).
*/
- setCursor(element: HTMLElement, noScroll?: boolean) {
+ setCursor(element: HTMLElement, noScroll?: boolean, applyFocus?: boolean) {
if (!this.targetableStops.includes(element)) {
this.unsetCursor();
return;
@@ -238,6 +240,9 @@
this._updateIndex();
this._decorateTarget();
+ if (applyFocus) {
+ this._focusAfterMove();
+ }
if (noScroll && behavior) {
this.scrollMode = behavior;
}
@@ -341,15 +346,17 @@
this._targetHeight = this.target.scrollHeight;
}
- if (this.focusOnMove) {
- this.target.focus();
- }
-
this._decorateTarget();
-
+ this._focusAfterMove();
return clipped ? CursorMoveResult.CLIPPED : CursorMoveResult.MOVED;
}
+ _focusAfterMove() {
+ if (this.focusOnMove) {
+ this.target?.focus();
+ }
+ }
+
_decorateTarget() {
if (this.target && this.cursorTargetClass) {
this.target.classList.add(this.cursorTargetClass);