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