mirror of
https://github.com/ahmetildirim/obsidian-inscribe.git
synced 2026-07-22 05:44:10 +00:00
refactor: improve completion generation logic with dedicated shouldGenerate method
This commit is contained in:
parent
20415fa5e6
commit
a8149db948
1 changed files with 23 additions and 6 deletions
|
|
@ -35,12 +35,7 @@ export default class CompletionService {
|
|||
if (!activeEditor) return;
|
||||
if (!activeEditor.editor) return;
|
||||
|
||||
// Check if the editor is in Vim insert mode
|
||||
if (isVimEnabled(activeEditor.editor)) {
|
||||
if (!isVimInsertMode(activeEditor.editor)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!this.shouldGenerate(activeEditor.editor)) return;
|
||||
|
||||
const profile = this.profileService.getActiveProfile();
|
||||
const provider = this.providerFactory.getProvider(profile.provider);
|
||||
|
|
@ -96,4 +91,26 @@ export default class CompletionService {
|
|||
yield { text: text };
|
||||
}
|
||||
}
|
||||
|
||||
private shouldGenerate(editor: Editor): boolean {
|
||||
// Check if the editor is in Vim insert mode
|
||||
if (isVimEnabled(editor) && !isVimInsertMode(editor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const cursor = editor.getCursor();
|
||||
const currentLine = editor.getLine(cursor.line);
|
||||
|
||||
// Line must not be empty
|
||||
if (!currentLine || currentLine.length === 0) return false;
|
||||
|
||||
// Cursor must not be at column 0
|
||||
if (cursor.ch === 0) return false;
|
||||
|
||||
// Last character before cursor must be a space
|
||||
const lastChar = currentLine[cursor.ch - 1];
|
||||
if (lastChar !== " ") return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue