mgsloan / todoist-shortcuts

Browser extension which adds comprehensive keyboard shortcuts to Todoist, beyond what is offered by Todoist itself
MIT License
313 stars 22 forks source link

Move task to specific project #237

Closed mdbraber closed 1 year ago

mdbraber commented 1 year ago

I'm trying to write a bit of code to move a project to a specific project. So far it works, but would you have any recommendations to improve this? Would be great to be able to add this code to the core eventually so shortcuts can be assigned to directly move tasks to specific projects

  // Clicks 'Move to project' for the selection. If WHAT_CURSOR_APPLIES_TO is
  // 'all' or 'most', then instead applies to the cursor if there is no
  // selection.
    function moveToProjectNamed(projectName) {
        return () => {
            const mutateCursor = getCursorToMutate();
            if (mutateCursor) {
                clickTaskMenu(mutateCursor, 'task-overflow-menu-move-to-project', false);
                withUniqueClass(document, 'popper', hasChild('[aria-label="'+projectName+'"]'), (menu) => {
                    withUniqueTag(menu, 'li', matchingAttr('aria-label', projectName), click);
                });
                if (inBulkMoveMode) {
                    bulkMoveCursorChanged();
                }
            } else {
                withUnique(
                    document,
                    'button[data-action-hint="multi-select-toolbar-project-picker"]',
                    (menu) => {
                        click(menu);
                        withUniqueClass(document, 'popper', hasChild('[aria-label="'+projectName+'"]'), (menu) => {
                            withUniqueTag(menu, 'li', matchingAttr('aria-label', projectName), click);
                        });
                    },
                );
            }
        }
    }
mgsloan commented 1 year ago

Code looks good to me! Certainly could add the code if you want. However, there won't be a way to bind it to a key natively (no current plans to implement #99), so usage will need to be done via code modification of the keybinds.

mdbraber commented 1 year ago

Would be more than fine with me (I'm using todoist-shortcuts integrated in my own macOS / Swift app). It would be good to have the code part of the main repository so others can use it or improve upon it

mgsloan commented 1 year ago

Cool, thanks! I've added this code to version 173