@trendr/core 0.2.4 → 0.2.5
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/text-area.js +10 -3
package/package.json
CHANGED
package/src/text-area.js
CHANGED
|
@@ -87,7 +87,7 @@ function ensureVisible(cursorRow, scroll, height, totalLines) {
|
|
|
87
87
|
return scroll
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp }) {
|
|
90
|
+
export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false }) {
|
|
91
91
|
const [value, setValue] = createSignal('')
|
|
92
92
|
const [cursor, setCursor] = createSignal(0)
|
|
93
93
|
const _prev = registerHook(() => ({ value: undefined }))
|
|
@@ -115,7 +115,14 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
|
|
|
115
115
|
const v = value()
|
|
116
116
|
const c = cursor()
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
const isSubmitKey = submitOnEnter
|
|
119
|
+
? (key === 'return' && !meta)
|
|
120
|
+
: (meta && key === '\r')
|
|
121
|
+
const isNewlineKey = submitOnEnter
|
|
122
|
+
? (meta && key === '\r')
|
|
123
|
+
: (key === 'return')
|
|
124
|
+
|
|
125
|
+
if (isSubmitKey) {
|
|
119
126
|
if (onSubmit) onSubmit(v)
|
|
120
127
|
if (clearOnSubmit) update('', 0)
|
|
121
128
|
ref.scroll = 0
|
|
@@ -123,7 +130,7 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
|
|
|
123
130
|
return
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
if (
|
|
133
|
+
if (isNewlineKey) {
|
|
127
134
|
update(v.slice(0, c) + '\n' + v.slice(c), c + 1)
|
|
128
135
|
event.stopPropagation()
|
|
129
136
|
return
|