on master help sign in
Fix bugs in fields
49901dcEvan Czaplicki
libraries/Native/Graphics/Input.js+23−24
@@ -208,26 +208,24 @@ Elm.Native.Graphics.Input.make = function(elm) {
208 field.elm_signal = model.signal;
208 field.elm_signal = model.signal;
209 field.elm_handler = model.handler;
209 field.elm_handler = model.handler;
210
210
211− field.id = 'test';
211+ field.type = model.type;
212− field.type = type;
213 field.placeholder = JS.fromString(model.placeHolder);
212 field.placeholder = JS.fromString(model.placeHolder);
214− field.value = JS.fromString(model.state.string);
213+ field.value = JS.fromString(model.content.string);
215− setRange(field, model.state.selectionStart, model.state.selectionEnd, 'forward');
214+ var selection = model.content.selection;
215+ var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
216+ setRange(field, selection.start, selection.end, direction);
216 field.style.border = 'none';
217 field.style.border = 'none';
217− state = model.state;
218
218
219 function update() {
219 function update() {
220− var start = field.selectionStart;
221− var end = field.selectionEnd;
222− if (field.selectionDirection === 'backward') {
220+ var direction = field.selectionDirection === 'backward' ? 'Backward' : 'Forward';
223− start = end;
224− end = field.selectionStart;
225− }
226− elm.notify(events.id, field.elm_handler({
221+ elm.notify(field.elm_signal.id, field.elm_handler({
227 _:{},
222 _:{},
228 string:JS.toString(field.value),
223 string:JS.toString(field.value),
224+ selection: {
229− selectionStart:start,
225+ start:field.selectionStart,
230− selectionEnd:end
226+ end:field.selectionEnd,
227+ direction: { ctor:direction }
228+ },
231 }));
229 }));
232 }
230 }
233 function mousedown() {
231 function mousedown() {
@@ -246,16 +244,16 @@ Elm.Native.Graphics.Input.make = function(elm) {
246
244
247 function updateField(node, oldModel, newModel) {
245 function updateField(node, oldModel, newModel) {
248 node.elmHandler = newModel.handler;
246 node.elmHandler = newModel.handler;
249− var newStr = JS.fromString(newModel.state.string);
247+ var newStr = JS.fromString(newModel.content.string);
250 if (node.value !== newStr) node.value = newStr;
248 if (node.value !== newStr) node.value = newStr;
251
249
252− var start = newModel.state.selectionStart;
250+ var selection = newModel.content.selection;
253− var end = newModel.state.selectionEnd;
251+ var start = selection.start;
252+ var end = selection.end;
254− var direction = 'forward';
253+ var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
255 if (end < start) {
254 if (end < start) {
256 start = end;
255 start = end;
257− end = newModel.state.selectionStart;
256+ end = selection.start;
258− direction = 'backward';
259 }
257 }
260
258
261 if (node.selectionStart !== start
259 if (node.selectionStart !== start
@@ -266,17 +264,18 @@ Elm.Native.Graphics.Input.make = function(elm) {
266 }
264 }
267
265
268 function mkField(type) {
266 function mkField(type) {
269− function field(signal, handler, placeHolder, state) {
267+ function field(signal, handler, placeHolder, content) {
270 return A3(newElement, 200, 30, {
268 return A3(newElement, 200, 30, {
271 ctor: 'Custom',
269 ctor: 'Custom',
272 type: type + 'Input',
270 type: type + 'Input',
273− render: render,
271+ render: renderField,
274− update: update,
272+ update: updateField,
275 model: {
273 model: {
276 signal:signal,
274 signal:signal,
277 handler:handler,
275 handler:handler,
278 placeHolder:placeHolder,
276 placeHolder:placeHolder,
279− state:state
277+ content:content,
278+ type:type
280 }
279 }
281 });
280 });
282 }
281 }