add Vim mode detection

This commit is contained in:
Ahmet Ildirim 2025-05-04 18:31:44 +02:00
parent 970ab0304f
commit b8f4cf1023
5 changed files with 25 additions and 4 deletions

View file

@ -1,7 +1,7 @@
{
"id": "inscribe",
"name": "Inscribe",
"version": "1.0.11",
"version": "1.0.12",
"minAppVersion": "0.15.0",
"description": "Inline autocompletion powered by AI.",
"author": "Ahmet Ildirim",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-inscribe",
"version": "1.0.11",
"version": "1.0.12",
"description": "A plugin for Obsidian that uses AI to provide inline completions.",
"main": "main.js",
"scripts": {

View file

@ -5,6 +5,7 @@ import { Suggestion } from "src/extension";
import { CompletionOptions, Settings } from "src/settings/settings";
import { Provider } from "src/providers/provider";
import preparePrompt from "src/completions/prompt";
import { isVimEnabled, isVimInsertMode } from "src/completions/vim";
export default class CompletionService {
private app: App;
@ -33,6 +34,13 @@ 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;
}
}
const profile = this.profileService.getActiveProfile();
const provider = this.providerFactory.getProvider(profile.provider);
const options = profile.completionOptions;
@ -76,4 +84,4 @@ export default class CompletionService {
}
this.notifyCompletionStatus(false);
}
}
}

12
src/completions/vim.ts Normal file
View file

@ -0,0 +1,12 @@
import { Editor } from "obsidian";
// Utility function to detect if Vim insert mode is active
export function isVimInsertMode(view: Editor): boolean {
const vim = (view as any).state.field((window as any).CodeMirror.Vim?.vimStateField, false);
return vim ? vim.mode === 'insert' : false;
}
// Check if the editor is in Vim mode
export function isVimEnabled(editor: Editor): boolean {
return (editor as any)?.cm?.cm?.state?.keyMap === "vim";
}

View file

@ -9,5 +9,6 @@
"1.0.8": "0.15.0",
"1.0.9": "0.15.0",
"1.0.10": "0.15.0",
"1.0.11": "0.15.0"
"1.0.11": "0.15.0",
"1.0.12": "0.15.0"
}