obsidian-tasks-group / obsidian-tasks

Task management for the Obsidian knowledge base.
https://publish.obsidian.md/tasks/
MIT License
2.4k stars 225 forks source link

Allow TAB to select option from EditorSuggestorPopup content #3103

Open jjjpanda opened 1 day ago

jjjpanda commented 1 day ago

⚠️ Please check that this feature request hasn't been suggested before.

🔖 Feature description

Currently, the only way to select any content from the EditorSuggestorPopup is using the mouse or arrow key + ENTER. Many editors, especially IDEs allow both TAB or ENTER to select and auto-complete a suggested phrase. I believe a setting switch to allow this (and swallow TAB keypresses to not indent) should be implemented.

✔️ Solution

In EditorSuggestorPopup

 app.scope.register([], 'Tab', () => {
            const editor = this.context?.editor;
            if (editor) {
                editor.exec('indentMore');
                // Returning false triggers preventDefault
                // Should prevent double indent if tabs start to get passed through
                return false;
            }
            return true;
        });

This section is included to allow for indents during the EditorSuggest, with a boolean flag from the Settings object passed into the constructor of EditorSuggestorPopup, a line directly calling selectSuggestion() can be added to mimic the behavior of the ENTER key.

❓ Alternatives

No response

📝 Additional Context

No response

claremacrae commented 1 day ago

Hi, this is intentional, based on past feedback from users. With tasks in lists, it is much more likely to want TAB to indent than it is to select from the list. See:

I believe a setting switch to allow this (and swallow TAB keypresses to not indent) should be implemented.

Each extra option that we add to user settings adds complexity both for code-maintainers and for users, so the barrier to entry for new user settings is very high.

jjjpanda commented 23 hours ago

Thank you for the quick response! I understand the concern with adding complexity here. Based on what's been described in #2187, #2183, and from the steps to reproduce in both of those issues:

press enter to create task 2. the dropdown appears (due date, etc.) for the task 2. press tab to try to nest task 2. Nothing happens. Press escapeor click the mouse to get rid of the dropdown. Now I can nest task 2 using tab.

Create a task Press enter Try to indent by pressing tab

It seems like the use case for indenting with TAB was being blocked by the immediate dropdown that appears as soon as enter is pressed. Would a feature like this be possible if the dropdown only appeared after typing a space and not at the start of a task? Or specifically for my case, maybe this feature could be only for dataview task formatting (where an explicit [-dataview inline is required for autosuggest).