update at 2025-11-10 13:54:46
This commit is contained in:
52
main.ts
52
main.ts
@@ -41,7 +41,7 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
private currentVimMode = 'normal'; // 跟踪当前vim模式
|
||||
|
||||
async onload() {
|
||||
console.log('🚀 [VimIMSwitch] Loading plugin...');
|
||||
console.log('🚀 Loading plugin...');
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
@@ -204,16 +204,14 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
const beforeIM = await this.runCmd(this.fcitxRemotePath, ["-n"]);
|
||||
const currentIMName = beforeIM.trim();
|
||||
|
||||
// 检查当前输入法是中文还是英文
|
||||
if (currentIMName === this.settings.chineseInputMethod) {
|
||||
this.lastInsertModeIMStatus = IMStatus.Activate;
|
||||
console.log('🔤 [VimIMSwitch] ESC → English (saved Chinese)');
|
||||
} else {
|
||||
this.lastInsertModeIMStatus = IMStatus.Deactivate;
|
||||
console.log('🔤 [VimIMSwitch] ESC → English (saved English)');
|
||||
}
|
||||
|
||||
// 切换到英文输入法
|
||||
// 检查当前输入法是中文还是英文
|
||||
if (currentIMName === this.settings.chineseInputMethod) {
|
||||
this.lastInsertModeIMStatus = IMStatus.Activate;
|
||||
console.log('ESC → English (saved Chinese)');
|
||||
} else {
|
||||
this.lastInsertModeIMStatus = IMStatus.Deactivate;
|
||||
console.log('ESC → English (saved English)');
|
||||
} // 切换到英文输入法
|
||||
this.currentVimMode = 'normal';
|
||||
await this.deactivateIM();
|
||||
}
|
||||
@@ -228,10 +226,10 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
this.currentVimMode = 'insert';
|
||||
// 恢复上次的输入法状态
|
||||
if (this.lastInsertModeIMStatus == IMStatus.Activate) {
|
||||
console.log("🈳 [VimIMSwitch] → Chinese");
|
||||
console.log("→ Chinese");
|
||||
await this.activateIM();
|
||||
} else {
|
||||
console.log("🔤 [VimIMSwitch] → English");
|
||||
console.log("→ English");
|
||||
await this.deactivateIM();
|
||||
}
|
||||
}, 10);
|
||||
@@ -266,15 +264,15 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
if (this.imStatus == IMStatus.Activate) {
|
||||
this.lastInsertModeIMStatus = IMStatus.Activate;
|
||||
}
|
||||
console.log("🔤 [VimIMSwitch] → English");
|
||||
console.log("→ English");
|
||||
await this.deactivateIM();
|
||||
} else if (cm.mode == "insert" || cm.mode == "replace") {
|
||||
// 进入insert模式时,恢复上次的输入法状态
|
||||
if (this.lastInsertModeIMStatus == IMStatus.Activate) {
|
||||
console.log("🈳 [VimIMSwitch] → Chinese");
|
||||
console.log("→ Chinese");
|
||||
await this.activateIM();
|
||||
} else {
|
||||
console.log("🔤 [VimIMSwitch] → English");
|
||||
console.log("→ English");
|
||||
await this.deactivateIM();
|
||||
}
|
||||
}
|
||||
@@ -287,7 +285,7 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
|
||||
async getFcitxRemoteStatus() {
|
||||
if (this.fcitxRemotePath == "") {
|
||||
console.log("❌ [VimIMSwitch] Cannot get fcitx-remote path, please set it correctly.");
|
||||
console.log("❌ Cannot get fcitx-remote path, please set it correctly.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -303,31 +301,31 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
this.imStatus = IMStatus.None;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`❌ [VimIMSwitch] Error getting IM status:`, error);
|
||||
console.log(`❌ Error getting IM status:`, error);
|
||||
}
|
||||
}
|
||||
async activateIM() {
|
||||
if (this.fcitxRemotePath == "") {
|
||||
console.log("❌ [VimIMSwitch] Cannot get fcitx-remote path, please set it correctly.");
|
||||
console.log("❌ Cannot get fcitx-remote path, please set it correctly.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.runCmd(this.fcitxRemotePath, ["-s", this.settings.chineseInputMethod]);
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
} catch (error) {
|
||||
console.log("❌ [VimIMSwitch] Error activating IM:", error);
|
||||
console.log("❌ Error activating IM:", error);
|
||||
}
|
||||
}
|
||||
async deactivateIM() {
|
||||
if (this.fcitxRemotePath == "") {
|
||||
console.log("❌ [VimIMSwitch] Cannot get fcitx-remote path, please set it correctly.");
|
||||
console.log("❌ Cannot get fcitx-remote path, please set it correctly.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.runCmd(this.fcitxRemotePath, ["-s", this.settings.englishInputMethod]);
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
} catch (error) {
|
||||
console.log("❌ [VimIMSwitch] Error deactivating IM:", error);
|
||||
console.log("❌ Error deactivating IM:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,22 +375,22 @@ export default class VimIMSwitchPlugin extends Plugin {
|
||||
}
|
||||
|
||||
async updateCurrentPath() {
|
||||
console.log(`🖥️ [VimIMSwitch] Platform detected: ${process.platform}`);
|
||||
console.log(`🖥️ Platform detected: ${process.platform}`);
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
this.fcitxRemotePath = this.settings.fcitxRemotePath_macOS;
|
||||
console.log(`🍎 [VimIMSwitch] Using macOS path: ${this.fcitxRemotePath}`);
|
||||
console.log(`🍎 Using macOS path: ${this.fcitxRemotePath}`);
|
||||
break;
|
||||
case 'linux':
|
||||
this.fcitxRemotePath = this.settings.fcitxRemotePath_linux;
|
||||
console.log(`🐧 [VimIMSwitch] Using Linux path: ${this.fcitxRemotePath}`);
|
||||
console.log(`🐧 Using Linux path: ${this.fcitxRemotePath}`);
|
||||
break;
|
||||
case 'win32':
|
||||
this.fcitxRemotePath = this.settings.fcitxRemotePath_windows;
|
||||
console.log(`🪟 [VimIMSwitch] Using Windows path: ${this.fcitxRemotePath}`);
|
||||
console.log(`🪟 Using Windows path: ${this.fcitxRemotePath}`);
|
||||
break;
|
||||
default:
|
||||
console.log(`❌ [VimIMSwitch] Platform ${process.platform} is not supported currently.`);
|
||||
console.log(`❌ Platform ${process.platform} is not supported currently.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user