Skip to content

Conversation

@tusharonly
Copy link

PR Description

Fixed cursor jumping to end issue in URL text field. When editing a character in the middle of the URL, the cursor would automatically move to the end, making it difficult to edit URLs.

Root Cause: The didUpdateWidget method in EnvironmentTriggerField was recreating the TextEditingController on every text change, always positioning the cursor at the end.

Solution: Modified the controller update logic to:

  • Preserve the current cursor position when text is updated from user input
  • Only reset cursor to end when switching between different requests (keyId changes)
  • Ensure cursor position stays within valid bounds using .clamp(0, newText.length)
  • Avoid unnecessary controller updates when text hasn't actually changed

Related Issues

Checklist

  • I have gone through the contributing guide

  • I have updated my branch and synced it with project main branch before making this PR

  • I am using the latest Flutter stable branch (run flutter upgrade and verify)

  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • No, and this is why: This is a UI interaction fix that addresses cursor positioning behavior. The existing tests continue to pass and validate the text field functionality. Additional widget tests for cursor position preservation could be added in a future enhancement.

OS on which you have developed and tested the feature?

  • Windows

  • macOS

  • Linux

…ing initial value and fix controller handling on key change
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.

Typing or Removing any character in between URL textfield moves the cursor to the end unexpectedly.

1 participant