
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
insert-text-textarea
Advanced tools
Insert text in a textarea and input[text] (supports Firefox and Undo, where possible)
Insert text in a textarea and input[text] (supports Firefox and Undo, where possible)
The text will be inserted after the cursor and it will replace any text that's selected, acting like a paste
would.
This is useful when creating "editor" buttons, to add text or wrap the selected text. For example, this module is used by indent-textarea.
An input
event will also be dispatched, with event.inputType === 'insertText'
.
It uses document.execCommand('insertText')
in Chrome (which has Undo support) and it replicates its behavior in Firefox (without Undo support until this bug is solved).
If you need IE support, use insert-text-at-cursor.
You can just download the standalone bundle
Or use npm
:
npm install insert-text-textarea
// This module is only offered as a ES Module
import insertText from 'insert-text-textarea';
const textarea = document.querySelector('textarea');
const button = document.querySelector('.js-add-signature');
button.addEventListener(event => {
// It will add this text at the cursor, replacing any possible selected text
insertText(textarea, 'Made by 🐝 with pollen.');
});
const textarea = document.querySelector('textarea');
const button = document.querySelector('.js-markdown-make-text-bold');
button.addEventListener(event => {
// This will replace the selected text (if any) with **selected text**
// Don't use `getSelection()` if you want Firefox support
const selectedText = value.slice(
textarea.selectionStart,
textarea.selectionEnd
);
insertText(textarea, '**' + selectedText + '**');
});
<textarea>
to fit its content, in a few bytes.FAQs
Insert text in a textarea and input[text] (supports Firefox and Undo, where possible)
The npm package insert-text-textarea receives a total of 378 weekly downloads. As such, insert-text-textarea popularity was classified as not popular.
We found that insert-text-textarea demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.