All Projects → grassator → Insert Text At Cursor

grassator / Insert Text At Cursor

Licence: mit
Fast crossbrowser insertion of text at cursor position in a textarea / input

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Insert Text At Cursor

TextInputLayout
The objective of this code is to guide you to create login screen with TextInputLayout in iOS app.
Stars: ✭ 30 (-38.78%)
Mutual labels:  input, text
Input Range Scss
Styling Cross-Browser Compatible Range Inputs with Sass
Stars: ✭ 272 (+455.1%)
Mutual labels:  form, input
react-native-input-bar
Fully customizable, beautifully designed Input Bar for React Native
Stars: ✭ 32 (-34.69%)
Mutual labels:  input, text
passport
A Kotlin-based Android view validation library with a simple DSL.
Stars: ✭ 31 (-36.73%)
Mutual labels:  input, text
Inputkit
📝InputKit, an Elegant Kit to limits your input text, inspired by BlocksKit, written in both Objective-C & ⚡️Swift.
Stars: ✭ 420 (+757.14%)
Mutual labels:  text, input
dynamic-input-fields-reactjs
Example of the dynamic input fields in ReactJS
Stars: ✭ 31 (-36.73%)
Mutual labels:  input, form
svelte-search
Accessible, customizable Svelte search component
Stars: ✭ 17 (-65.31%)
Mutual labels:  input, form
PHP-FileUpload
Simple and convenient file uploads — secure by default
Stars: ✭ 53 (+8.16%)
Mutual labels:  input, form
Multiitem
一个优雅的实现多类型的RecyclerView类库 支持DataBinding Form表单录入 跨多个RecyclerView拖动
Stars: ✭ 381 (+677.55%)
Mutual labels:  form, input
Web Highlighter
✨ A no-runtime dependency lib for text highlighting & persistence on any website ✨🖍️
Stars: ✭ 373 (+661.22%)
Mutual labels:  text, selection
react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-69.39%)
Mutual labels:  input, form
Formbase
Better default styles for common input elements.
Stars: ✭ 560 (+1042.86%)
Mutual labels:  form, input
text-editor
A text selection range API written in pure JavaScript, for modern browsers.
Stars: ✭ 24 (-51.02%)
Mutual labels:  text, selection
web-marker
a web page highlighter - Please star if you like this project
Stars: ✭ 51 (+4.08%)
Mutual labels:  text, selection
selecton-extension
Selecton provides popup with actions on text selection in all major browsers
Stars: ✭ 36 (-26.53%)
Mutual labels:  text, selection
pygame-text-input
a small module that enables you to input text with your keyboard using pygame
Stars: ✭ 114 (+132.65%)
Mutual labels:  input, text
Sharect
🔗 A lightweight JavaScript library to let users share their text selections to social networks.
Stars: ✭ 192 (+291.84%)
Mutual labels:  text, selection
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (-34.69%)
Mutual labels:  input, form
Vxe Table
🐬 vxe-table vue 表格解决方案
Stars: ✭ 4,242 (+8557.14%)
Mutual labels:  form, input
Nouislider
noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
Stars: ✭ 5,127 (+10363.27%)
Mutual labels:  input, form

Insert Text at Cursor

This 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.

Quick Start

Add it to your project

npm install --save insert-text-at-cursor

Import using ES Modules:

import insertTextAtCursor from 'insert-text-at-cursor';

Or as a CommonJS:

const insertTextAtCursor = require('insert-text-at-cursor');
// Find an element you want on the page
const el = document.getElementById('my-textarea');
insertTextAtCursor(el, 'foobar');

Browser Support

The library has been tested in:

  • Latest Edge, Firefox, Chrome, Opera, Safari (Mac)
  • iOS 11 Safari
  • IE 8-11

Caveats

Due to the nature of the APIs used, the library will always focus the target field and set the cursor after the inserted text.

Motivation

All 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.

While 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.

To 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.

License

The MIT License

Copyright (c) 2018 Dmitriy Kubyshkin

Permission 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].