update at 2025-11-11 18:14:34
This commit is contained in:
59
main.ts
59
main.ts
@@ -1,4 +1,4 @@
|
||||
import { App, Modal, Notice, Plugin, PluginSettingTab, Setting, Workspace, MarkdownView, TFile, WorkspaceLeaf } from 'obsidian';
|
||||
import { App, Plugin, PluginSettingTab, Setting, MarkdownView, TFile, WorkspaceLeaf } from 'obsidian';
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import * as CodeMirror from 'codemirror';
|
||||
@@ -50,30 +50,6 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
|
||||
this.addSettingTab(new IMSwitchSettingTab(this.app, this));
|
||||
|
||||
this.addCommand({
|
||||
id: 'test-im-switch-to-english',
|
||||
name: 'Test: Switch to English',
|
||||
callback: () => {
|
||||
this.deactivateIM();
|
||||
}
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: 'test-im-switch-to-chinese',
|
||||
name: 'Test: Switch to Chinese',
|
||||
callback: () => {
|
||||
this.activateIM();
|
||||
}
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: 'test-check-im-status',
|
||||
name: 'Test: Check IM Status',
|
||||
callback: () => {
|
||||
this.getFcitxRemoteStatus();
|
||||
}
|
||||
});
|
||||
|
||||
this.app.workspace.on('file-open', async (file: TFile) => {
|
||||
if (!this.initialized) {
|
||||
await this.initialize();
|
||||
@@ -154,34 +130,6 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
setupVimModePolling() {
|
||||
// 防止重复设置轮询
|
||||
if ((this as any).vimModePollingInterval) {
|
||||
clearInterval((this as any).vimModePollingInterval);
|
||||
}
|
||||
|
||||
let lastMode = "";
|
||||
const pollInterval = setInterval(() => {
|
||||
if (!this.cmEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const realCM = (this.cmEditor as any).cm;
|
||||
const currentMode = realCM?.state?.vim?.mode || "";
|
||||
|
||||
if (currentMode && currentMode !== lastMode) {
|
||||
this.onVimModeChange({ mode: currentMode });
|
||||
lastMode = currentMode;
|
||||
}
|
||||
} catch (error) {
|
||||
// 忽略轮询错误
|
||||
}
|
||||
}, 100);
|
||||
|
||||
(this as any).vimModePollingInterval = pollInterval;
|
||||
}
|
||||
|
||||
setupObsidianEditorEvents() {
|
||||
if (this.keyboardListenerSetup) {
|
||||
return;
|
||||
@@ -335,11 +283,6 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
this.cmEditor.off("vim-mode-change", this.onVimModeChange);
|
||||
}
|
||||
|
||||
// 清理轮询定时器
|
||||
if ((this as any).vimModePollingInterval) {
|
||||
clearInterval((this as any).vimModePollingInterval);
|
||||
}
|
||||
|
||||
// 清理键盘事件监听器
|
||||
if ((this as any).obsidianKeyDownListener) {
|
||||
document.removeEventListener('keydown', (this as any).obsidianKeyDownListener, { capture: true });
|
||||
|
||||
Reference in New Issue
Block a user