Moving a ToDo item to the top


#1

Hi,

I am having problems getting this function to work:

    Extensions.addCommand({
     name: 'moveTop',
     description: 'Move the current Todo node to the top of the list.',
     performCommand: function(editor) {

     var cnode = editor.selectedRange().startNode,
            pnode = cnode.previousBranch();

        //
        // Go to the top of the current todo list.
       //
       while (pnode.type() != 'heading') {
          pnode = pnode.previousBranch();
       }

        //
        // Append to top of the list.
        //
        fcnode = pnode.firstChild();
        pnode.insertChildBefore(cnode,fcnode);
     }
 });

I also can not get commands to run in the Debugger. You can not bring up the command pallet in the debugger, so how are you to debug commands?

All of my todo list are in level one headers. I want to move items to the top, bottom, next list and previous list. I have all of these working, except for this one!

Thanks.

Richard


#2

In the debugger console command line, you can give the name string of the command (eg ‘moveTop’) to the window.performAction method.

Try, for example, selecting a line in the SDK editor, and entering:

window.performAction('done')

(window. is the default namespace/context, so it should be optional, in practice)

i.e. just:

performAction('done')

(commands will often have no return value, so the console will tend to respond with undefined after the command is performed)


#3

I knew there must be a way. It needs to be in the documents! Thanks.


#4

Okay. I fixed it. I did not realize firstChild wasn’t a function. Easy to see in the debugger. Thanks for the help.