Merge changes I4cf84a6a,Id074683f into stable-3.11

* changes:
  Ignore key locations if diff is outside of focus range.
  Make intraline background transparent when the row is out of focus range
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor.ts b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor.ts
index d138414..89bb49e 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor.ts
@@ -181,18 +181,29 @@
     return chunkIndex;
   }
 
+  /**
+   * Check if a chunk is collapsible.
+   *
+   * A chunk is collapsible if it is either common or skippable, and it is not
+   * a key location, or it is outside of the focus range.
+   *
+   * @param chunk The chunk to check.
+   * @param offsetLeft The offset of the left side of the chunk.
+   * @param offsetRight The offset of the right side of the chunk.
+   * @return True if the chunk is collapsible, false otherwise.
+   */
   private isCollapsibleChunk(
     chunk: DiffContent,
     offsetLeft: number,
     offsetRight: number
   ) {
-    return (
-      (chunk.ab ||
-        chunk.common ||
-        chunk.skip ||
-        this.isChunkOutsideOfFocusRange(chunk, offsetLeft, offsetRight)) &&
-      !chunk.keyLocation
+    const isCommonOrSkip = chunk.ab || chunk.common || chunk.skip;
+    const isOutsideOfFocusRange = this.isChunkOutsideOfFocusRange(
+      chunk,
+      offsetLeft,
+      offsetRight
     );
+    return (isCommonOrSkip && !chunk.keyLocation) || isOutsideOfFocusRange;
   }
 
   private isChunkOutsideOfFocusRange(
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
index 3f01096..19a687e 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
@@ -1054,6 +1054,32 @@
           assert.equal(result.groups[0].lines.length, 5);
           assert.equal(result.groups[1].type, GrDiffGroupType.DELTA);
         });
+
+        test('collapse chunks with key locations if out of focus range', () => {
+          const keyLocationLineText = 'key location behind a context group';
+          state = {
+            lineNums: {left: 7, right: 6},
+            chunkIndex: 4,
+          };
+          const result = processor.processNext(state, [
+            ...chunks,
+            {
+              ab: Array.from<string>({length: 2}).fill(
+                'all work and no play make jill a dull boy'
+              ),
+              keyLocation: false,
+            },
+            {
+              ab: Array.from<string>({length: 5}).fill(keyLocationLineText),
+              keyLocation: true,
+            },
+          ]);
+          assert.equal(result.groups.length, 3);
+          assert.equal(
+            result.groups[2].contextGroups[0].lines[0].text,
+            keyLocationLineText
+          );
+        });
       });
     });
 
diff --git a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-styles.ts b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-styles.ts
index 98a2093..2913fc8 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-styles.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-styles.ts
@@ -369,6 +369,9 @@
     background-color: var(--dark-add-highlight-color);
     &:has(.is-out-of-focus-range) {
       background-color: transparent;
+      .intraline {
+        background-color: transparent;
+      }
     }
   }
   gr-diff-row td.content.add div.contentText,
@@ -376,6 +379,9 @@
     background-color: var(--light-add-highlight-color);
     &:has(.is-out-of-focus-range) {
       background-color: transparent;
+      .intraline {
+        background-color: transparent;
+      }
     }
   }
   /* If there are no intraline info, consider everything changed */