Skip to content

Commit 366a8a1

Browse files
authored
Merge pull request #3384 from obsidian-tasks-group/issue-1509-no-suggest-on-NON_TASK
fix: Prevent Auto-Suggest for 'NON_TASK' statuses Fixes #1509.
2 parents a6dd7ff + 1f45deb commit 366a8a1

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/Editing/Auto-Suggest.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ Here is a more detailed walk through of the creation of a new task, which can be
3939

4040
**Note**: the auto-suggest menu pops up only if the cursor is in a line that is recognized as a task, that is, the line contains:
4141

42-
- a bullet with a checkbox, that is, one of:
42+
- a bullet with a checkbox, that is, starting with one of these three characters:
4343
- `- [ ]`
4444
- `* [ ]`
4545
- `+ [ ]`
46-
- and the global filter (if any)
46+
- and the global filter (if any),
47+
- and the status symbol (the character between `[` and `]`) does not have [[Status Types|status type]] `NON_TASK`.
4748

4849
Tasks also tries to display the auto-suggest menu based on context. For example, suggestions will only appear
4950
within square brackets `[]` or parentheses `()` when using the [[Dataview Format#Bracketed inline fields|Dataview Task Format]].
@@ -135,8 +136,6 @@ There are some Auto-Suggest behaviours that might be improved in future releases
135136
- This phrase still needs to be typed manually.
136137
- We are tracking this in [issue #2066](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2066).
137138
- It currently pops up when editing completed tasks. This may be changed in future.
138-
- It currently pops up when editing NON_TASK tasks. This may be changed in future.
139-
- We are tracking this in [issue #1509](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1509).
140139
- The [[Create or edit Task#Date abbreviations|date abbreviations offered by "Create or edit task"]] only work after a space is typed.
141140
- When Auto-Suggest is used in [[Kanban plugin]] cards (or any other plugins that use the [[Tasks Api#Auto-Suggest Integration|auto-suggest integration]]), the [[Task Dependencies|dependencies]] suggestions are not available, because there is not yet a mechanism for plugins to access all the tasks in the vault.
142141
- We are tracking this in [issue #3274](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3274).

src/Suggestor/Suggestor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { GlobalFilter } from '../Config/GlobalFilter';
1616
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
1717
import { searchForCandidateTasksForDependency } from '../ui/DependencyHelpers';
1818
import { escapeRegExp } from '../lib/RegExpTools';
19+
import { StatusType } from '../Statuses/StatusConfiguration';
1920
import type { SuggestInfo, SuggestionBuilder } from '.';
2021

2122
/**
@@ -771,6 +772,7 @@ function editorIsRequestingSuggest(
771772
/**
772773
* Return true if:
773774
* - line is a task line, that is, it is a list item with a checkbox.
775+
* - the checkbox status character is not a NON_TASK type.
774776
* - the cursor is in a task line's description.
775777
*
776778
* Here, description includes any task signifiers, as well as the vanilla description.
@@ -788,6 +790,11 @@ function cursorIsInTaskLineDescription(line: string, cursorPosition: number) {
788790
return false;
789791
}
790792

793+
if (components.status.type === StatusType.NON_TASK) {
794+
// The user's settings say this status is not a task:
795+
return false;
796+
}
797+
791798
// Reconstruct the contents of the line, up to the space after the closing ']' in the checkbox:
792799
const beforeDescription = components.indentation + components.listMarker + ' [' + components.status.symbol + '] ';
793800

tests/Suggestor/Suggestor.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { verifyMarkdown } from '../TestingTools/VerifyMarkdown';
2020
import { GlobalFilter } from '../../src/Config/GlobalFilter';
2121
import { MarkdownTable } from '../../src/lib/MarkdownTable';
2222
import { TaskBuilder } from '../TestingTools/TaskBuilder';
23+
import { StatusRegistry } from '../../src/Statuses/StatusRegistry';
24+
import { StatusConfiguration, StatusType } from '../../src/Statuses/StatusConfiguration';
2325

2426
window.moment = moment;
2527

@@ -574,6 +576,7 @@ describe('onlySuggestIfBracketOpen', () => {
574576
describe('canSuggestForLine', () => {
575577
afterEach(() => {
576578
GlobalFilter.getInstance().reset();
579+
resetSettings();
577580
});
578581

579582
function canSuggestForLineWithCursor(line: string, editor: any = {}) {
@@ -610,6 +613,15 @@ describe('canSuggestForLine', () => {
610613
expect(canSuggestForLineWithCursor('- [ ]| ')).toEqual(false);
611614
});
612615

616+
it('should not suggest if cursor is on a task with NON_TASK status', () => {
617+
// With the default statuses, ? is TODO, so we should suggest:
618+
expect(canSuggestForLineWithCursor('- [?] question|')).toEqual(true);
619+
620+
StatusRegistry.getInstance().add(new StatusConfiguration('?', 'Question', '_', true, StatusType.NON_TASK));
621+
// Now ? is NON_TASK, so we should NOT suggest (issue #1509):
622+
expect(canSuggestForLineWithCursor('- [?] question|')).toEqual(false);
623+
});
624+
613625
it('should suggest when the cursor is at least one character past the checkbox', () => {
614626
expect(canSuggestForLineWithCursor('- [ ] |')).toEqual(true);
615627
});

0 commit comments

Comments
 (0)