@trendr/core 0.2.5 → 0.2.6
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/package.json +1 -1
- package/src/input.js +16 -0
- package/src/text-area.js +7 -0
package/package.json
CHANGED
package/src/input.js
CHANGED
|
@@ -153,7 +153,23 @@ export function createInputHandler(stream) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
function isPaste(data) {
|
|
157
|
+
const s = typeof data === 'string' ? data : data.toString()
|
|
158
|
+
return s.length > 1 && !s.startsWith('\x1b') && (s.includes('\n') || s.includes('\r'))
|
|
159
|
+
}
|
|
160
|
+
|
|
156
161
|
function onData(data) {
|
|
162
|
+
if (isPaste(data)) {
|
|
163
|
+
const text = (typeof data === 'string' ? data : data.toString()).replace(/\r\n?/g, '\n')
|
|
164
|
+
const event = { key: 'paste', text, ctrl: false, meta: false, shift: false, raw: text }
|
|
165
|
+
event.stopPropagation = () => { event._stopped = true }
|
|
166
|
+
const snapshot = [...keyListeners].reverse()
|
|
167
|
+
for (const fn of snapshot) {
|
|
168
|
+
fn(event)
|
|
169
|
+
if (event._stopped) break
|
|
170
|
+
}
|
|
171
|
+
return
|
|
172
|
+
}
|
|
157
173
|
for (const key of splitKeys(data)) {
|
|
158
174
|
dispatch(key)
|
|
159
175
|
}
|
package/src/text-area.js
CHANGED
|
@@ -115,6 +115,13 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
|
|
|
115
115
|
const v = value()
|
|
116
116
|
const c = cursor()
|
|
117
117
|
|
|
118
|
+
if (key === 'paste') {
|
|
119
|
+
const pasted = event.text || ''
|
|
120
|
+
update(v.slice(0, c) + pasted + v.slice(c), c + pasted.length)
|
|
121
|
+
event.stopPropagation()
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
const isSubmitKey = submitOnEnter
|
|
119
126
|
? (key === 'return' && !meta)
|
|
120
127
|
: (meta && key === '\r')
|