{"id":15672366,"url":"https://github.com/nikku/selection-ranges","last_synced_at":"2025-04-10T02:23:21.490Z","repository":{"id":57742149,"uuid":"121894222","full_name":"nikku/selection-ranges","owner":"nikku","description":"Manipulate selection ranges on contenteditable elements.","archived":false,"fork":false,"pushed_at":"2025-01-18T16:42:52.000Z","size":461,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T01:09:36.952Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikku.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["nikku"]}},"created_at":"2018-02-17T21:30:18.000Z","updated_at":"2025-01-25T22:16:34.000Z","dependencies_parsed_at":"2024-06-18T18:42:55.172Z","dependency_job_id":"eb60d642-62a6-449c-8d57-acdfbf8299e5","html_url":"https://github.com/nikku/selection-ranges","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fselection-ranges","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fselection-ranges/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fselection-ranges/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fselection-ranges/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikku","download_url":"https://codeload.github.com/nikku/selection-ranges/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143335,"owners_count":21054760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T15:24:53.304Z","updated_at":"2025-04-10T02:23:21.452Z","avatar_url":"https://github.com/nikku.png","language":"JavaScript","funding_links":["https://github.com/sponsors/nikku"],"categories":[],"sub_categories":[],"readme":"# selection-ranges\n\n[![CI](https://github.com/nikku/selection-ranges/actions/workflows/CI.yml/badge.svg)](https://github.com/nikku/selection-ranges/actions/workflows/CI.yml)\n\nManipulate selection ranges on `contenteditable` elements.\n\n\n## API\n\n```javascript\n/**\n * Return the selection on the given element as {start, end}.\n *\n * @param {Element} el\n *\n * @return {Object} selection range or null if element is not selected\n */\ngetRange(el);\n```\n\n```javascript\n/**\n * Selects the given range on the specified element.\n *\n * @param {Element} el\n * @param {Object} range {start, end}\n */\nsetRange(el, range);\n```\n\n```javascript\n/**\n * Return true if element is part of window selection.\n *\n * @param  {Element}  el\n * @return {Boolean}\n */\nisSelected(el);\n```\n\n\n## Usage\n\n```javascript\nimport {\n  getRange,\n  setRange\n} from 'selection-ranges';\n\n\nvar node = \u003cdiv contenteditable /\u003e;\n\nlet range = getRange(node);\n// a range such as { start: 5, end: 10 }\n// or null if node is currently not selected\n\nsetRange(node, { start: 0, end: 30 });\n// sets selection range to child nodes; does not focus node\n```\n\n\n## Features\n\n* Works around [browser issues](https://stackoverflow.com/questions/13949059/persisting-the-changes-of-range-objects-after-selection-in-html/13950376) and correctly handles `\u003cbr/\u003e` and paragraph elements\n* Correctly handles out-of-bounds selections\n\n\n## Related\n\n* [selection-update](https://github.com/nikku/selection-update) - compute input selection updates on external content changes\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikku%2Fselection-ranges","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikku%2Fselection-ranges","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikku%2Fselection-ranges/lists"}