Skip to content

Commit d26fd2e

Browse files
committed
refactor: . Extract method canSaveEdits()
1 parent 500046d commit d26fd2e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Suggestor/EditorSuggestorPopup.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class EditorSuggestor extends EditorSuggest<SuggestInfoWithContext> {
7272

7373
// If we can't save the file, we should not allow users to choose dependencies.
7474
// See https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2872
75-
const canSaveEdits = markdownFileInfo instanceof MarkdownView;
75+
const canSaveEdits = this.canSaveEdits(markdownFileInfo);
7676

7777
const suggestions: SuggestInfo[] =
7878
getUserSelectedTaskFormat().buildSuggestions?.(
@@ -93,6 +93,10 @@ export class EditorSuggestor extends EditorSuggest<SuggestInfoWithContext> {
9393
return context.editor.cm.state.field(editorInfoField);
9494
}
9595

96+
private canSaveEdits(markdownFileInfo: any) {
97+
return markdownFileInfo instanceof MarkdownView;
98+
}
99+
96100
renderSuggestion(value: SuggestInfoWithContext, el: HTMLElement) {
97101
el.setText(value.displayText);
98102
}
@@ -183,7 +187,7 @@ file: '${newTask.path}'
183187
// multiple ID fields can be added to individual task lines.
184188

185189
const markdownFileInfo = this.getMarkdownFileInfo(value.context);
186-
if (markdownFileInfo instanceof MarkdownView) {
190+
if (this.canSaveEdits(markdownFileInfo)) {
187191
await markdownFileInfo.save();
188192
}
189193
}

0 commit comments

Comments
 (0)