Skip to content

store the caret position whenever the text input changes - #2333

Merged
joshaber merged 5 commits into
masterfrom
cursor-jumping-around-the-place
Jul 26, 2017
Merged

joshaber merged 5 commits into
masterfrom
cursor-jumping-around-the-place

Conversation

@shiftkey

@shiftkey shiftkey commented Jul 25, 2017 •

Copy link
Copy Markdown
Member

Fixes #2222

This is a workaround for the input element forgetting it's caret position after a prop update and moving the caret to the end.

Spelunking a bunch of old React issues suggests this shouldn't happen, but I see this recent comment suggest that it's still something that needs to be worked around: react/react#955 (comment)

  • document the workarounds

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 25, 2017
@joshaber joshaber self-assigned this Jul 26, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍭

label={__DARWIN__ ? 'Local Path' : 'Local path'}
placeholder="repository path"
onChange={this.onPathChanged}
onValueChanged={this.onPathChanged}

This comment was marked as spam.

Comment thread app/src/ui/lib/text-box.tsx Outdated

/*
* Store the selection end and previous string between updates so that the
* caret posiiton can be reapplied to the input element.

This comment was marked as spam.

Comment thread app/src/ui/lib/text-box.tsx Outdated
}
}

private onRef = (instance: HTMLInputElement) => {

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/ui/lib/text-box.tsx Outdated

/*
* Update the caret position of the input element if it can be reapplied.
* Reference: https://gist.github.com/shiftkey/a713712182288b0870952fd5a1bfcebe

This comment was marked as spam.

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

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants