autopair 1.1.0 → 1.2.0
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/LICENSE.md +2 -2
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/autopair.js +21 -2
package/LICENSE.md
CHANGED
|
@@ -2,7 +2,7 @@ Adjusted MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025 Dennis Hackethal
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person
|
|
5
|
+
Permission is hereby granted, free of charge, to any person[^1] obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
7
7
|
in the Software without restriction, including without limitation the rights
|
|
8
8
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
@@ -20,7 +20,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
[^1]: Exception: no one in the public sector may use this software. That means
|
|
24
24
|
no politicians, public-school teachers, police, intelligence services, etc.
|
|
25
25
|
Private recipients of public moneys may not use this software either unless
|
|
26
26
|
they oppose the welfare state and consider such moneys restitution. No one
|
package/README.md
CHANGED
package/package.json
CHANGED
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;
|