Commit 80f9fbe4 authored by lm's avatar lm

Changing redraw strategy while handling input events in order to avoid focus

issues.

Fix style issues: missing spaces.

Fix avoid double deletion when handling empty input and the following blur event.
parent c3f5dc53
......@@ -8,7 +8,7 @@ app.controller = function () {
this.list = app.storage.get();
// Update with props
this.list = this.list.map(function(item) {
this.list = this.list.map(function (item) {
return new app.Todo(item);
});
......@@ -53,6 +53,10 @@ app.controller = function () {
};
this.doneEditing = function (todo, index) {
if (!todo.editing()) {
return;
}
todo.editing(false);
todo.title(todo.title().trim());
if (!todo.title()) {
......
......@@ -5,15 +5,18 @@ var app = app || {};
// View utility
app.watchInput = function (onenter, onescape) {
return function (e) {
m.redraw.strategy('none');
if (e.keyCode === app.ENTER_KEY) {
onenter();
m.redraw.strategy('diff');
} else if (e.keyCode === app.ESC_KEY) {
onescape();
m.redraw.strategy('diff');
}
};
};
app.view = (function() {
app.view = (function () {
var focused = false;
return function (ctrl) {
......@@ -63,13 +66,17 @@ app.view = (function() {
})
]), m('input.edit', {
value: task.title(),
onkeyup: app.watchInput(ctrl.doneEditing.bind(ctrl, task, index),
ctrl.cancelEditing.bind(ctrl, task)),
oninput: m.withAttr('value', task.title),
onkeyup: app.watchInput(
ctrl.doneEditing.bind(ctrl, task, index),
ctrl.cancelEditing.bind(ctrl, task)
),
oninput: m.withAttr('value', function (value) {
m.redraw.strategy('none');
task.title(value);
}),
config: function (element) {
if (task.editing()) {
element.focus();
element.selectionStart = element.value.length;
}
},
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