@@ -209,6 +209,14 @@ Elm.Native.Graphics.Input.make = function(elm) {
209209 });
210210 }
211211
212+ function setRange(node, start, end, dir) {
213+ if (node.parentNode) {
214+ node.setSelectionRange(start, end, dir);
215+ } else {
216+ setTimeout(function(){node.setSelectionRange(start, end, dir);}, 0);
217+ }
218+ }
219+
212220 function updateIfNeeded(css, attribute, latestAttribute) {
213221 if (css[attribute] !== latestAttribute) {
214222 css[attribute] = latestAttribute;
@@ -259,7 +267,10 @@ Elm.Native.Graphics.Input.make = function(elm) {
259267
260268 field.type = model.type;
261269 field.placeholder = JS.fromString(model.placeHolder);
262− field.value = JS.fromString(model.content);
270+ field.value = JS.fromString(model.content.string);
271+ var selection = model.content.selection;
272+ var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
273+ setRange(field, selection.start, selection.end, direction);
263274
264275 field.elm_signal = model.signal;
265276 field.elm_handler = model.handler;
@@ -271,7 +282,15 @@ Elm.Native.Graphics.Input.make = function(elm) {
271282 String.fromCharCode(event.keyCode) +
272283 curr.slice(field.selectionEnd));
273284 var pos = field.selectionEnd + 1;
274− elm.notify(field.elm_signal.id, field.elm_handler(JS.toString(next)));
285+ elm.notify(field.elm_signal.id, field.elm_handler({
286+ _:{},
287+ string: JS.toString(next),
288+ selection: {
289+ start: pos,
290+ end: pos,
291+ direction: { ctor:'Forward' }
292+ },
293+ }));
275294 event.preventDefault();
276295 }
277296
@@ -281,12 +300,46 @@ Elm.Native.Graphics.Input.make = function(elm) {
281300 if (curr === next) {
282301 return;
283302 }
303+
304+ var direction = field.selectionDirection === 'forward' ? 'Forward' : 'Backward';
305+ var start = field.selectionStart;
306+ var end = field.selectionEnd;
284307 field.value = field.elm_old_value;
285− elm.notify(field.elm_signal.id, field.elm_handler(JS.toString(next)));
308+
309+ elm.notify(field.elm_signal.id, field.elm_handler({
310+ _:{},
311+ string: JS.toString(next),
312+ selection: {
313+ start: start,
314+ end: end,
315+ direction: { ctor: direction }
316+ },
317+ }));
286318 }
287319
320+ function mouseUpdate(event) {
321+ var direction = field.selectionDirection === 'forward' ? 'Forward' : 'Backward';
322+ elm.notify(field.elm_signal.id, field.elm_handler({
323+ _:{},
324+ string: field.value,
325+ selection: {
326+ start: field.selectionStart,
327+ end: field.selectionEnd,
328+ direction: { ctor: direction }
329+ },
330+ }));
331+ }
332+ function mousedown(event) {
333+ mouseUpdate(event);
334+ elm.node.addEventListener('mouseup', mouseup);
335+ }
336+ function mouseup(event) {
337+ mouseUpdate(event);
338+ elm.node.removeEventListener('mouseup', mouseup)
339+ }
288340 field.addEventListener('keypress', keyUpdate);
289341 field.addEventListener('input', inputUpdate);
342+ field.addEventListener('mousedown', mousedown);
290343
291344 return field;
292345 }
@@ -300,9 +353,12 @@ Elm.Native.Graphics.Input.make = function(elm) {
300353
301354 field.type = newModel.type;
302355 field.placeholder = JS.fromString(newModel.placeHolder);
303− var value = JS.fromString(newModel.content);
356+ var value = JS.fromString(newModel.content.string);
304357 field.value = value;
305358 field.elm_old_value = value;
359+ var selection = newModel.content.selection;
360+ var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
361+ setRange(field, selection.start, selection.end, direction);
306362 }
307363
308364 function mkField(type) {