Skip to content

Conversation

@spliffone
Copy link
Member

@spliffone spliffone commented Jan 21, 2026

Describe in detail what your merge request does and why. Add relevant
screenshots and reference related issues via Closes #XY or Related to #XY.


@spliffone spliffone requested a review from a team as a code owner January 21, 2026 12:21
@spliffone spliffone marked this pull request as draft January 21, 2026 12:21
@gemini-code-assist
Copy link

Summary of Changes

Hello @spliffone, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the cursor position was not correctly retained in the IPv6 input component after character insertion, particularly when the input value was automatically formatted. The changes introduce a mechanism to calculate and apply a cursor adjustment, significantly improving the user experience by preventing unexpected cursor jumps and ensuring a more natural typing flow.

Highlights

  • Cursor Position Retention: Implemented logic to ensure the cursor's position is correctly maintained when inserting characters into an IPv6 input field, even when automatic formatting (like adding colons) occurs.
  • splitIpV6Sections Function Enhancement: The splitIpV6Sections utility function now returns an additional cursorDelta value, which quantifies the shift in cursor position due to automatically inserted characters (e.g., colons).
  • SiIp6InputDirective Update: The SiIp6InputDirective now utilizes the cursorDelta from splitIpV6Sections to accurately set the cursor's selection range after an 'insert' type input event, preventing unexpected cursor jumps.
  • New Test Cases for Cursor Positioning: Comprehensive unit tests have been added to si-ip6-input.directive.spec.ts to validate the correct cursor positioning behavior under various scenarios, including typing in the middle of a section, handling multiple section splits, typing at the end, zero compression, and CIDR sections.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix an issue with cursor positioning in the IPv6 input component. The changes introduce a cursorDelta to adjust the cursor position after formatting. However, the logic for calculating this delta is flawed, as it compares indices from different coordinate systems (raw input vs. cleaned section value). This can lead to incorrect cursor placement when inserting characters in the middle of an IP address segment. Additionally, the new tests do not cover these middle-insertion scenarios, so the bug is not caught. I've provided a detailed explanation of the bug and a suggested fix, along with a new test case that would expose the issue and verify the correction.

Comment on lines +142 to +144
if (current && pos >= charsProcessed) {
cursorDelta++;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic to calculate cursorDelta is incorrect because it compares pos (an index in the raw input string) with charsProcessed (an index within a cleaned section value). This can lead to incorrect cursor positioning when inserting characters in the middle of an IP address segment, as pos and charsProcessed are in different coordinate systems.

To fix this, you need to determine the cursor's position relative to the hexadecimal characters within its section.

Here is a suggested approach:

  1. In the first for loop (lines 111-128), determine the cursor's position relative to the hex characters in its section and store it.

    let cursorRelativePos = -1;
    for (let i = 0; i <= input.length; i++) {
      if (pos === i) {
        sections.at(-1)!.current = true;
        cursorRelativePos = sections.at(-1)!.value.length;
      }
      if (i >= input.length) {
        continue;
      }
      // ... existing logic to build sections ...
    }
  2. Then, use this cursorRelativePos here to correctly calculate cursorDelta.

    if (current && cursorRelativePos >= charsProcessed + 4) {
      cursorDelta++;
    }

Additionally, the new tests for cursor positioning in si-ip6-input.directive.spec.ts only cover appending characters. It would be beneficial to add a test case for inserting a character in the middle of a section to verify the fix and prevent future regressions.

expect(input.value).toBe('2001:DB8::1/64');
expect(input.selectionStart).toBe(14);
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current tests for cursor positioning do not cover cases where a section split is triggered by inserting characters in the middle of a string. This scenario is where the cursorDelta calculation is most critical. Please add a new test case to cover this, which will help validate the fix for the logic in address-utils.ts.

    it('should retain cursor position when section splits from middle insertion', () => {
      // Simulate typing 'a' in '12345678' at position 4 -> '1234a|5678'
      input.value = '1234a5678';
      input.setSelectionRange(5, 5);
      input.dispatchEvent(new InputEvent('input', { data: 'a', inputType: 'insertText' }));
      expect(input.value).toBe('1234:A567:8');
      expect(input.selectionStart).toBe(6);
    });

@github-actions
Copy link

Code Coverage

@github-actions
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants