Skip to content

Instantly share code, notes, and snippets.

@reyronald
Created April 15, 2022 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyronald/bcddc9a861b95869dadbde61c6e51b92 to your computer and use it in GitHub Desktop.
Save reyronald/bcddc9a861b95869dadbde61c6e51b92 to your computer and use it in GitHub Desktop.
This one moves the user's cursor within a text input.
export function moveCursorWithinInput(input, position) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(position, position);
} else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', position);
range.moveStart('character', position);
range.select();
}
}
// SOURCE: https://www.joshwcomeau.com/react/file-structure/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment