         # especially possible when readHtml has been called during an undo()
         id = lineDiv.dataset.id
         for t in @_taskList
-            if t.id == id or t.internalId == id
+            if t.internalId == id
                 lineDiv.task = t
                 t.lineDiv = lineDiv
                 return true


        # 6- add the list of task modified since last addHistory()
        h.modifiedTask.push @_tasksModifSinceLastHistory
        @_tasksModifSinceLastHistory = {}
        console.log '  @_tasksModifSinceLastHistory', @_tasksModifSinceLastHistory

        # 7- update the index
        h.index = @HISTORY_SIZE - 1


    _stackTaskChange : (task,action) ->
        # action in : done, undone, modified, removed
        console.log '== editor._stackTaskChange() ' + action, task.internalId

        @_stackTaskForSave(task.internalId, task, action)

        switch action

            when 'modified', 'done', 'undone'
                @_tasksModifSinceLastHistory[task.internalId] =
                    t:task, a:'modified'
                # console.log '  @_tasksModifSinceLastHistory', @_tasksModifSinceLastHistory

            when 'created'
                @_tasksModifSinceLastHistory[task.internalId] =
                    t:task, a:'created'

            # when 'removed'
            #   nothing

        @__printTasksModifStacks()

        return true



    _stackTaskForSave : (id, t, action) ->

        modif = @_tasksModifStack[id]
        if !@_tasksModifStack[id]
            modif = t:t
            @_tasksModifStack[id] = modif

        switch action
            when 'modified', 'done', 'undone'
                modif.modified = true
            when 'created'
                if modif.deleted
                    modif.deleted = false
                    modif.created = false
                    modif.modified = true
                else
                    modif.created = true
            when 'deleted'
                if modif.created
                    modif.deleted = false
                    modif.created = false
                else
                    modif.deleted = true
            # when 'removed'
            #     nothing



    ###*
     * Saves the creations/modification/deletion not yet saved.
     * removed | 1 1 1 1 1 1 1 1 | 0 0 | 0 0 | 0 | 0 0 | 0
     * created | 1 1 1 1 0 0 0 0 | 1 1 | 0 0 | 0 | 1 1 | 0
     * modified| 1 1 0 0 1 1 0 0 | 1 0 | 1 0 | 1 | 1 0 | 0
     * deleted | 1 0 1 0 1 0 1 0 | 1 1 | 1 1 | 0 | 0 0 | 0
     * action  | N N N N N N N N | N N | D D | M | C C | N
     * (N D C = Nothing, Create, Delete)
     * @return {[type]} [description]
    ###
    saveTasks : () ->
        console.log '== saveTasks()'
        for id,modif of @_tasksModifStack
            # console.log 'saveTask
            if modif.removed
                continue

            else if modif.created && modif.deleted
                continue

            else if modif.deleted
                modif.t.destroy(silent: true)

            else if modif.modified && !modif.created
                t = modif.t
                l = t.lineDiv
                t.save({
                        done        : (l.dataset.state == 'done')
                        description :  l.textContent.slice(1)
                    },{
                        ignoreMySocketNotification: true
                        silent: true
                        error : (t) =>
                            window.alert('Cozy Todo is not responding, save ' +\
                                'of tasks is not possible so we cancel '      +\
                                'modifications.')
                            @_updateTaskLine(t, true)
                    }
                )

            else if modif.created && !modif.t.id

                # t = modif.t
                @_saveTaskCreation(modif.t)
                # l = t.lineDiv
                # t.save({
                #         done        : (l.dataset.state == 'done')
                #         description :  l.textContent.slice(1)
                #        },
                #        {
                #         ignoreMySocketNotification: true
                #         silent  : true
                #         success : (t) =>
                #             # console.log "editor t.save.done()",t.id
                #             realtimer.watchOne t
                #             t.lineDiv.dataset.id = t.id
                #             @editorTarget$.trigger jQuery.Event('onChange')

                #             # will be called by modification on server side.
                #             # Modifications initiated on this client will be
                #             # saved with silent=true so that this call back is
                #             # not fired whereas ui is uptodate
                #             t.on 'change', () =>
                #                 # console.log "onchange from save", t.id
                #                 # console.log t.changedAttributes()
                #                 @_updateTaskLine(t)
                #             t.on 'destroy', (t) =>
                #                 # console.log ' editor : destroy from save',t.id
                #                 @_turneTaskIntoLine(t.lineDiv)
                #         error : (t) =>
                #             window.alert('Cozy Todo is not responding, save ' +\
                #                 'of tasks is not possible so we cancel '      +\
                #                 'the task creation.')
                #             @_turneTaskIntoLine(t.lineDiv)
                #         }
                # )

            # case a task re-created by an undo
            else if modif.created && modif.t.id
                lineDiv = @linesDiv.querySelectorAll(
                    "div[data-id='#{modif.t.internalId}']")[0]
                t = @_createTaskForLine(lineDiv,true)
                # preserve its internalId
                @_internalTaskCounter--
                t.internalId = modif.t.internalId

                modif.t = t
                @_replaceInTaskHistory(t)
                @_saveTaskCreation(t)

                # oldTask = modif.t
                # lineDiv = oldTask.lineDiv
                # t = new Task(description:oldTask.get('description'))
                # lineDiv.task = t
                # @_internalTaskCounter += 1
                # t.internalId = 'CNE_task_id_' + @_internalTaskCounter
                # lineDiv.dataset.id = t.internalId # set a temporary id
                # t.lineDiv = lineDiv
                # @_taskList.push(t)

        @_tasksModifStack = {}



    _saveTaskCreation : (t) ->
        l = t.lineDiv
        t.save({
                done        : (l.dataset.state == 'done')
                description :  l.textContent.slice(1)
               },
               {
                ignoreMySocketNotification: true
                silent  : true
                success : (t) =>
                    # console.log "editor t.save.done()",t.id
                    realtimer.watchOne t
                    # t.lineDiv.dataset.id = t.internalId
                    @editorTarget$.trigger jQuery.Event('onChange')

                    # will be called by modification on server side.
                    # Modifications initiated on this client will be
                    # saved with silent=true so that this call back is
                    # not fired whereas ui is uptodate
                    t.on 'change', () =>
                        # console.log "onchange from save", t.id
                        # console.log t.changedAttributes()
                        @_updateTaskLine(t)
                    t.on 'destroy', (t) =>
                        # console.log ' editor : destroy from save',t.id
                        @_turneTaskIntoLine(t.lineDiv)
                error : (t) =>
                    window.alert('Cozy Todo is not responding, save ' +\
                        'of tasks is not possible so we cancel '      +\
                        'the task creation.')
                    @_turneTaskIntoLine(t.lineDiv)
                }
        )

    _isTaskUnchanged : (task) ->
        res = true
