@trendr/core 0.4.18 → 0.4.19
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 -0
- package/package.json +1 -1
- package/src/text-area.js +8 -1
package/README.md
CHANGED
|
@@ -547,6 +547,7 @@ Multi-line text input. Auto-grows up to `maxHeight`, then scrolls.
|
|
|
547
547
|
value={draft()} // controlled value (optional)
|
|
548
548
|
submitOnEnter={false} // default false: Alt+Enter submits, Enter inserts newline.
|
|
549
549
|
// true flips it: Enter submits, Shift/Alt+Enter inserts newline
|
|
550
|
+
newlineOnBackslashEnter={false} // replace a backslash immediately before Enter with a newline
|
|
550
551
|
clearOnSubmit={true} // reset to empty on submit (default true)
|
|
551
552
|
cursor={{ blink: true }} // per-component cursor config (overrides theme)
|
|
552
553
|
onChange={(v, prev) => {}} // every edit, receives new and previous value
|
package/package.json
CHANGED
package/src/text-area.js
CHANGED
|
@@ -124,7 +124,7 @@ function ensureVisible(cursorRow, scroll, height, totalLines) {
|
|
|
124
124
|
return scroll
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false, color, lineCounter = false }) {
|
|
127
|
+
export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false, newlineOnBackslashEnter = false, color, lineCounter = false }) {
|
|
128
128
|
const [value, setValue] = createSignal('')
|
|
129
129
|
const [cursor, setCursor] = createSignal(0)
|
|
130
130
|
if (valueProp !== undefined && valueProp !== value()) {
|
|
@@ -169,6 +169,7 @@ export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder,
|
|
|
169
169
|
return
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
const isBackslashNewlineKey = newlineOnBackslashEnter && key === 'return' && !meta && c > 0 && v[c - 1] === '\\'
|
|
172
173
|
const isSubmitKey = submitOnEnter
|
|
173
174
|
? (key === 'return' && !meta && !shift)
|
|
174
175
|
: (meta && key === 'return')
|
|
@@ -176,6 +177,12 @@ export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder,
|
|
|
176
177
|
? ((shift && key === 'return') || (meta && key === 'return'))
|
|
177
178
|
: (key === 'return')
|
|
178
179
|
|
|
180
|
+
if (isBackslashNewlineKey) {
|
|
181
|
+
update(v.slice(0, c - 1) + '\n' + v.slice(c), c)
|
|
182
|
+
event.stopPropagation()
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
179
186
|
if (isSubmitKey) {
|
|
180
187
|
if (onSubmit) onSubmit(v)
|
|
181
188
|
if (clearOnSubmit) update('', 0)
|