Commit f183e30a authored by Arthur Verschaeve's avatar Arthur Verschaeve

Merge pull request #1423 from marcolamberto/mithril-input-refresh-fix

Changing redraw strategy while handling input events
parents e97e13c5 80f9fbe4
...@@ -8,7 +8,7 @@ app.controller = function () { ...@@ -8,7 +8,7 @@ app.controller = function () {
this.list = app.storage.get(); this.list = app.storage.get();
// Update with props // Update with props
this.list = this.list.map(function(item) { this.list = this.list.map(function (item) {
return new app.Todo(item); return new app.Todo(item);
}); });
...@@ -53,6 +53,10 @@ app.controller = function () { ...@@ -53,6 +53,10 @@ app.controller = function () {
}; };
this.doneEditing = function (todo, index) { this.doneEditing = function (todo, index) {
if (!todo.editing()) {
return;
}
todo.editing(false); todo.editing(false);
todo.title(todo.title().trim()); todo.title(todo.title().trim());
if (!todo.title()) { if (!todo.title()) {
......
...@@ -5,15 +5,18 @@ var app = app || {}; ...@@ -5,15 +5,18 @@ var app = app || {};
// View utility // View utility
app.watchInput = function (onenter, onescape) { app.watchInput = function (onenter, onescape) {
return function (e) { return function (e) {
m.redraw.strategy('none');
if (e.keyCode === app.ENTER_KEY) { if (e.keyCode === app.ENTER_KEY) {
onenter(); onenter();
m.redraw.strategy('diff');
} else if (e.keyCode === app.ESC_KEY) { } else if (e.keyCode === app.ESC_KEY) {
onescape(); onescape();
m.redraw.strategy('diff');
} }
}; };
}; };
app.view = (function() { app.view = (function () {
var focused = false; var focused = false;
return function (ctrl) { return function (ctrl) {
...@@ -63,13 +66,17 @@ app.view = (function() { ...@@ -63,13 +66,17 @@ app.view = (function() {
}) })
]), m('input.edit', { ]), m('input.edit', {
value: task.title(), value: task.title(),
onkeyup: app.watchInput(ctrl.doneEditing.bind(ctrl, task, index), onkeyup: app.watchInput(
ctrl.cancelEditing.bind(ctrl, task)), ctrl.doneEditing.bind(ctrl, task, index),
oninput: m.withAttr('value', task.title), ctrl.cancelEditing.bind(ctrl, task)
),
oninput: m.withAttr('value', function (value) {
m.redraw.strategy('none');
task.title(value);
}),
config: function (element) { config: function (element) {
if (task.editing()) { if (task.editing()) {
element.focus(); element.focus();
element.selectionStart = element.value.length;
} }
}, },
onblur: ctrl.doneEditing.bind(ctrl, task, index) onblur: ctrl.doneEditing.bind(ctrl, task, index)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment