Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

text-field-edit

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

text-field-edit - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

4

index.js
function insertTextFirefox(field, text) {
// Found on https://www.everythingfrontend.com/posts/insert-text-into-textarea-at-cursor-position.html 🎈
field.setRangeText(text, field.selectionStart || 0, field.selectionEnd || 0, 'end' // Without this, the cursor is either at the beginning or `text` remains selected
);
field.setRangeText(text, field.selectionStart || 0, field.selectionEnd || 0, 'end');
field.dispatchEvent(new InputEvent('input', {
data: text,
inputType: 'insertText',
isComposing: false // TODO: fix @types/jsdom, this shouldn't be required
}));

@@ -10,0 +8,0 @@ }

{
"name": "text-field-edit",
"version": "3.1.0",
"description": "Insert text in a <textarea> and <input> (supports Firefox and Undo, where possible)",
"version": "3.1.1",
"description": "Insert text in a `<textarea>` and `<input>` (including Undo in most browsers)",
"keywords": [

@@ -13,2 +13,4 @@ "at cursor",

"field",
"firefox",
"safari",
"form",

@@ -49,11 +51,11 @@ "inject",

"devDependencies": {
"@sindresorhus/tsconfig": "^0.7.0",
"browserify": "^16.5.1",
"@sindresorhus/tsconfig": "^2.0.0",
"browserify": "^17.0.0",
"esmify": "^2.1.1",
"npm-run-all": "^4.1.5",
"tape": "^5.0.0",
"tape-run": "^7.0.0",
"typescript": "^3.8.3",
"xo": "^0.30.0"
"tape": "^5.3.1",
"tape-run": "^9.0.0",
"typescript": "^4.4.2",
"xo": "^0.44.0"
}
}

@@ -8,7 +8,7 @@ # text-field-edit [![][badge-gzip]](#link-npm)

> Insert text in a `<textarea>` and `<input>` (supports Firefox and Undo, where possible)
> Insert text in a `<textarea>` and `<input>` (including Undo in most browsers)
You should use this instead of setting the `field.value` directly because:
- it doesn't break the undo history (in supported browsers)
- it doesn't break the undo history (in Chrome, Firefox, and Safari)
- it fires an `input` event (with `event.inputType === 'insertText'`)

@@ -18,9 +18,7 @@ - it's the most efficient way of adding/replacing selected text in a field

It uses `document.execCommand('insertText')` in Chrome (which has **Undo** support) and it replicates its behavior in Firefox (without Undo support until [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1220696) is solved).
It uses `document.execCommand('insertText')` under the hood. [Firefox added support for Undo](https://bugzilla.mozilla.org/show_bug.cgi?id=1220696) in Firefox 89 (June 2021). If you need IE support, use [insert-text-at-cursor](https://github.com/grassator/insert-text-at-cursor).
If you need IE support, use [insert-text-at-cursor](https://github.com/grassator/insert-text-at-cursor).
## Install
You can just download the [standalone bundle](https://packd.fregante.now.sh/text-field-edit)
You can download the [standalone bundle](https://bundle.fregante.com/?pkg=text-field-edit)

@@ -134,3 +132,3 @@ Or use `npm`:

Adds the `wrappingText` before and after field’s selection (or cursor). If `endWrappingText` is provided, it will be used instead of `wrappingText` at on the right.
Adds the `wrappingText` before and after field’s selection (or cursor). If `endWrappingText` is provided, it will be used instead of `wrappingText` on the right.

@@ -137,0 +135,0 @@ ```js

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc