@trendr/core 0.2.3 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/text-area.js +16 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trendr/core",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "direct-mode TUI renderer with JSX, signals, and per-cell diffing",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/text-area.js CHANGED
@@ -87,9 +87,15 @@ 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 }) {
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
+ const _prev = registerHook(() => ({ value: undefined }))
94
+ if (valueProp !== undefined && valueProp !== _prev.value) {
95
+ _prev.value = valueProp
96
+ setValue(valueProp)
97
+ setCursor(valueProp.length)
98
+ }
93
99
  const ref = registerHook(() => ({ scroll: 0, goalCol: null }))
94
100
  const layout = useLayout()
95
101
  const { cursorStyle, reset: resetBlink } = useCursor(cursorProp, focused)
@@ -109,7 +115,14 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
109
115
  const v = value()
110
116
  const c = cursor()
111
117
 
112
- if (meta && key === '\r') {
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) {
113
126
  if (onSubmit) onSubmit(v)
114
127
  if (clearOnSubmit) update('', 0)
115
128
  ref.scroll = 0
@@ -117,7 +130,7 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
117
130
  return
118
131
  }
119
132
 
120
- if (key === 'return') {
133
+ if (isNewlineKey) {
121
134
  update(v.slice(0, c) + '\n' + v.slice(c), c + 1)
122
135
  event.stopPropagation()
123
136
  return