update at 2025-11-11 18:14:34
This commit is contained in:
13
README.md
13
README.md
@@ -6,10 +6,14 @@
|
|||||||
|
|
||||||
[English](./README_en.md) | 中文
|
[English](./README_en.md) | 中文
|
||||||
|
|
||||||
|
[感谢 github 中的 vim-im-switch这个项目](https://github.com/yourusername/vim-im-switch)
|
||||||
|
这个项目不能满足需求,在这个项目基础上改进。
|
||||||
|
|
||||||
|
作者:Gavin Chan
|
||||||
|
|
||||||
> 🚀 **智能输入法管理工具** - 为 Vim 用户打造的无感知输入法切换体验
|
> 🚀 **智能输入法管理工具** - 为 Vim 用户打造的无感知输入法切换体验
|
||||||
|
|
||||||
这是为 **原生 Vim** 和 **Obsidian 编辑器** 的 Vim 模式设计的智能输入法自动切换插件,包含:
|
这是为 **原生 Vim** 和 **Obsidian 编辑器** 的 Vim 模式设计的智能输入法自动切换插件,包含:
|
||||||
|
|
||||||
- 🎯 **Obsidian 插件**:适用于 Obsidian 编辑器的 Vim 模式
|
- 🎯 **Obsidian 插件**:适用于 Obsidian 编辑器的 Vim 模式
|
||||||
- ⚡ **Vim 插件**:适用于原生 Vim/NeoVim 编辑器
|
- ⚡ **Vim 插件**:适用于原生 Vim/NeoVim 编辑器
|
||||||
- 🌍 **跨平台支持**:macOS、Linux、Windows 全平台兼容
|
- 🌍 **跨平台支持**:macOS、Linux、Windows 全平台兼容
|
||||||
@@ -329,12 +333,7 @@ vim-im-switch/
|
|||||||
- 📖 [English Documentation](./README_en.md)
|
- 📖 [English Documentation](./README_en.md)
|
||||||
- 📝 [更新日志](./CHANGELOG.md)
|
- 📝 [更新日志](./CHANGELOG.md)
|
||||||
- 🛠️ [fcitx-remote-for-osx](https://github.com/xcodebuild/fcitx-remote-for-osx)
|
- 🛠️ [fcitx-remote-for-osx](https://github.com/xcodebuild/fcitx-remote-for-osx)
|
||||||
- 🐛 [问题反馈](https://github.com/yourusername/vim-im-switch/issues)
|
- 🐛 [问题反馈](https://github.com/yourusername/vim-im-switch
|
||||||
- 💡 [功能建议](https://github.com/yourusername/vim-im-switch/discussions)
|
|
||||||
|
|
||||||
## 📄 许可证
|
|
||||||
|
|
||||||
本项目采用 [MIT 许可证](./LICENSE.txt)。
|
|
||||||
|
|
||||||
## 🙏 致谢
|
## 🙏 致谢
|
||||||
|
|
||||||
|
|||||||
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 { exec } from "child_process";
|
||||||
import { promisify } from "util";
|
import { promisify } from "util";
|
||||||
import * as CodeMirror from 'codemirror';
|
import * as CodeMirror from 'codemirror';
|
||||||
@@ -50,30 +50,6 @@ export default class VimIMSwitchPlugin extends Plugin {
|
|||||||
|
|
||||||
this.addSettingTab(new IMSwitchSettingTab(this.app, this));
|
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) => {
|
this.app.workspace.on('file-open', async (file: TFile) => {
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
await this.initialize();
|
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() {
|
setupObsidianEditorEvents() {
|
||||||
if (this.keyboardListenerSetup) {
|
if (this.keyboardListenerSetup) {
|
||||||
return;
|
return;
|
||||||
@@ -335,11 +283,6 @@ export default class VimIMSwitchPlugin extends Plugin {
|
|||||||
this.cmEditor.off("vim-mode-change", this.onVimModeChange);
|
this.cmEditor.off("vim-mode-change", this.onVimModeChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理轮询定时器
|
|
||||||
if ((this as any).vimModePollingInterval) {
|
|
||||||
clearInterval((this as any).vimModePollingInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理键盘事件监听器
|
// 清理键盘事件监听器
|
||||||
if ((this as any).obsidianKeyDownListener) {
|
if ((this as any).obsidianKeyDownListener) {
|
||||||
document.removeEventListener('keydown', (this as any).obsidianKeyDownListener, { capture: true });
|
document.removeEventListener('keydown', (this as any).obsidianKeyDownListener, { capture: true });
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user