text-field-edit
Advanced tools
Comparing version 3.1.9001 to 3.2.0
@@ -9,5 +9,5 @@ /** Inserts `text` at the cursor’s position, replacing any selection, with **undo** support and by firing the `input` event. */ | ||
export declare function wrapSelection(field: HTMLTextAreaElement | HTMLInputElement, wrap: string, wrapEnd?: string): void; | ||
declare type ReplacerCallback = (substring: string, ...args: any[]) => string; | ||
type ReplacerCallback = (substring: string, ...args: any[]) => string; | ||
/** Finds and replaces strings and regex in the field’s value, like `field.value = field.value.replace()` but better */ | ||
export declare function replace(field: HTMLTextAreaElement | HTMLInputElement, searchValue: string | RegExp, replacer: string | ReplacerCallback): void; | ||
export declare function replace(field: HTMLTextAreaElement | HTMLInputElement, searchValue: string | RegExp, replacer: string | ReplacerCallback, cursor?: 'select' | 'after-replacement'): void; | ||
export {}; |
@@ -52,3 +52,4 @@ // https://github.com/fregante/text-field-edit/issues/16 | ||
/** Finds and replaces strings and regex in the field’s value, like `field.value = field.value.replace()` but better */ | ||
export function replace(field, searchValue, replacer) { | ||
export function replace(field, searchValue, replacer, cursor) { | ||
if (cursor === void 0) { cursor = 'select'; } | ||
/** Remembers how much each match offset should be adjusted */ | ||
@@ -68,4 +69,6 @@ var drift = 0; | ||
insert(field, replacement); | ||
// Select replacement. Without this, the cursor would be after the replacement | ||
field.selectionStart = matchStart; | ||
if (cursor === 'select') { | ||
// Select replacement. Without this, the cursor would be after the replacement | ||
field.selectionStart = matchStart; | ||
} | ||
drift += replacement.length - matchLength; | ||
@@ -72,0 +75,0 @@ return replacement; |
{ | ||
"name": "text-field-edit", | ||
"version": "3.1.9001", | ||
"version": "3.2.0", | ||
"description": "Insert text in a `<textarea>` and `<input>` (including Undo in most browsers)", | ||
@@ -54,11 +54,11 @@ "keywords": [ | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "^2.0.0", | ||
"@sindresorhus/tsconfig": "^3.0.1", | ||
"browserify": "^17.0.0", | ||
"esmify": "^2.1.1", | ||
"npm-run-all": "^4.1.5", | ||
"tape": "^5.4.0", | ||
"tape-run": "^9.0.0", | ||
"typescript": "^4.5.4", | ||
"xo": "^0.47.0" | ||
"tape": "^5.6.1", | ||
"tape-run": "^10.0.0", | ||
"typescript": "^4.9.3", | ||
"xo": "^0.53.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12653
87