autopair 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.html +2 -1
- package/package.json +2 -2
- package/src/autopair.js +21 -2
package/README.md
CHANGED
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autopair",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Automatically closes parentheses and similar characters.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/autopair.js",
|
|
6
6
|
"author": "Dennis Hackethal <engineering@dennishackethal.com>",
|
|
7
7
|
"license": "Adjusted MIT",
|
|
8
8
|
"type": "module",
|
package/src/autopair.js
CHANGED
|
@@ -55,11 +55,30 @@ export default function autopair(textarea, pairs = {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
// Only autopair if next char is whitespace, punctuation, or a closing of the same type
|
|
59
58
|
const nextChar = value[end] || '';
|
|
59
|
+
const prevChar = value[start - 1] || '';
|
|
60
|
+
|
|
60
61
|
const insidePair = closing === nextChar;
|
|
61
62
|
const safeNext = !isWordChar.test(nextChar) || punctuation.test(nextChar);
|
|
62
|
-
|
|
63
|
+
const isSymmetric = evt.key === closing;
|
|
64
|
+
|
|
65
|
+
// Autoclose only when allowed
|
|
66
|
+
if (
|
|
67
|
+
!insidePair &&
|
|
68
|
+
(
|
|
69
|
+
!safeNext ||
|
|
70
|
+
(
|
|
71
|
+
isSymmetric &&
|
|
72
|
+
start === end &&
|
|
73
|
+
(
|
|
74
|
+
isWordChar.test(prevChar) || // end of word
|
|
75
|
+
prevChar === evt.key // repeated quote
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
63
82
|
|
|
64
83
|
evt.preventDefault();
|
|
65
84
|
textarea.selectionStart = textarea.selectionEnd = start;
|