{"id":26502832,"url":"https://github.com/grassator/insert-text-at-cursor","last_synced_at":"2025-04-10T01:14:50.696Z","repository":{"id":30060567,"uuid":"123795605","full_name":"grassator/insert-text-at-cursor","owner":"grassator","description":"Fast crossbrowser insertion of text at cursor position in a textarea / input","archived":false,"fork":false,"pushed_at":"2023-03-01T17:07:33.000Z","size":395,"stargazers_count":73,"open_issues_count":7,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T01:14:45.161Z","etag":null,"topics":["form","input","selection","text"],"latest_commit_sha":null,"homepage":null,"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/grassator.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2018-03-04T14:18:19.000Z","updated_at":"2024-11-26T07:00:35.000Z","dependencies_parsed_at":"2024-06-18T14:36:14.022Z","dependency_job_id":null,"html_url":"https://github.com/grassator/insert-text-at-cursor","commit_stats":{"total_commits":19,"total_committers":5,"mean_commits":3.8,"dds":0.5789473684210527,"last_synced_commit":"65ad0c7be13d751c6e59ee16eff671a5a09340c0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grassator%2Finsert-text-at-cursor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grassator%2Finsert-text-at-cursor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grassator%2Finsert-text-at-cursor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grassator%2Finsert-text-at-cursor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grassator","download_url":"https://codeload.github.com/grassator/insert-text-at-cursor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"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":["form","input","selection","text"],"created_at":"2025-03-20T18:35:41.795Z","updated_at":"2025-04-10T01:14:50.678Z","avatar_url":"https://github.com/grassator.png","language":"JavaScript","readme":"# Insert Text at Cursor\n\nThis library provides a consistent  (and fast!) way to insert some text at the cursor position into a textrea or a text input field. If the field contains a selection, the selected text will be replaced with a given one.\n\n### Quick Start\n\nAdd it to your project\n\n```bash\nnpm install --save insert-text-at-cursor\n```\n\nImport using ES Modules:\n\n```js\nimport insertTextAtCursor from 'insert-text-at-cursor';\n```\n\nOr as a CommonJS:\n\n```js\nconst insertTextAtCursor = require('insert-text-at-cursor');\n```\n\n```js\n// Find an element you want on the page\nconst el = document.getElementById('my-textarea');\ninsertTextAtCursor(el, 'foobar');\n```\n\n### Browser Support\n\nThe library has been tested in:\n\n* Latest Edge, Firefox, Chrome, Opera, Safari (Mac)\n* iOS 11 Safari\n* IE 8-11\n\n### Caveats\n\nDue to the nature of the APIs used, the library will always focus the target field and set the cursor after the inserted text.\n\n### Motivation\n\nAll previously existing solution that I could find rely on getting full value of the the textarea, then slicing in necessary text, resetting new value and then restoring selection to the right position.\n\nWhile this works quite well for small size of the text, if you have a few pages of text, the delay is very noticeable, especially on mobile devices and older browsers.\n\nTo mitigate that the library uses several different strategies by doing feature detection of several non-standard features to find a fast path. If none of the fast options are available, it falls back to true and tested method described above.\n\n### License\n\nThe MIT License\n\nCopyright (c) 2018 Dmitriy Kubyshkin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrassator%2Finsert-text-at-cursor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrassator%2Finsert-text-at-cursor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrassator%2Finsert-text-at-cursor/lists"}