Files
vim-im-switch/CHANGELOG_en.md
2025-11-09 22:04:12 +08:00

10 KiB

Changelog

All notable changes to the Vim Input Method Switch Plugin will be documented in this file.

Includes update history for both Obsidian plugin and Vim plugin versions.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

English | 中文


[2.0.3] - 2025-11-09

Fixed

Obsidian Plugin

  • Fixed input method switching triggered by ESC in Normal mode:
    • Issue: Pressing ESC in Normal mode would unexpectedly trigger input method switching (from Chinese to English, then English to English on second press)
    • Cause: handleKeyDown function didn't check current Vim mode when handling ESC key
    • Solution: Added mode check to only save IM state and switch to English when ESC is pressed in Insert or Replace mode
    • Result: Behavior now consistent with native Vim plugin - ESC in Normal mode doesn't change input method

Improved

  • Enhanced accuracy of mode detection
  • Optimized ESC key handling logic

[2.0.0] - 2025-11-04

Added

Native Vim Plugin Support

  • New fcitx-osx.vim plugin: Provides automatic input method switching for native Vim/NeoVim editors
  • Smart input method state memory:
    • Remembers input method (Chinese/English) when exiting Insert mode
    • Automatically restores previous IM state when entering Insert mode again
    • Completely seamless switching with no UI flicker
  • Using fcitx-remote -s command:
    • Precise switching by specifying input method ID
    • Replaces old -c/-o toggle commands
    • Supports custom English and Chinese IM IDs
  • Asynchronous execution optimization:
    • Uses Vim 8+ job_start() for async command execution
    • Completely eliminates UI flicker and delay during IM switching
    • Backward compatible with older Vim versions (using background process)

Enhanced Deploy Script

  • deploy.sh update: One-click deployment for both Obsidian and Vim plugins
  • Automatically creates ~/.vim/plugin/ directory
  • Copies both plugins to their respective target locations

Improved

Vim Plugin Performance Optimization

  • Uses fcitx-remote -n to get current input method name
  • Saves complete IM ID instead of simple toggle state
  • Avoids unnecessary IM switches (skips when same IM)
  • All output redirected to /dev/null for silent execution

Fixed

  • Fixed issue where fcitx-remote -c command doesn't work in Vim plugin
  • Fixed title bar flashing "fcitx-remote" issue
  • Fixed string comparison failure ("2\n" == 2) issue

Documentation

  • Updated README.md and README_en.md with Vim plugin installation instructions
  • Updated all document titles from "Obsidian" to include both plugins
  • Added Vim plugin configuration and debugging instructions

[2.0.2] - 2025-11-04

Fixed

  • Terminal compatibility: Fixed brief terminal/tab title flash when invoking fcitx-remote from terminal Vim by launching commands fully detached (nohup/background) and redirecting output
  • Compatibility: Removed unsupported job_start(..., {'detach': v:true}) usage to work with more Vim builds

Documentation

  • Minor docs update: note terminal behavior fix in README and RELEASE

[1.0.8] - 2025-01-04

This is a major update that introduces input method state memory and fixes several critical issues.

Added

Input Method State Memory

  • Smart memory of last input method state: The plugin now remembers which input method (Chinese/English) you were using when exiting Insert mode
  • Automatic restoration: When entering Insert mode again, automatically restores to the last saved input method state
  • Support for mixed Chinese/English input scenarios:
    • Scenario 1: Type Chinese in Insert mode, press ESC → saves "Chinese" state
    • Next time press i to enter Insert mode → auto switches back to Chinese IM
    • Scenario 2: Type English in Insert mode, press ESC → saves "English" state
    • Next time press i to enter Insert mode → keeps English IM

Enhanced State Management

  • Added lastInsertModeIMStatus variable to track last Insert mode IM state
  • Real-time detection and saving of current IM name when exiting Insert mode
  • Decides whether to switch IM based on saved state when entering Insert mode

Fixed

Fixed ESC Key Not Working on First Press

  • Issue: When users first press ESC key, IM doesn't switch to English, requires second press to work
  • Root Cause:
    1. Keyboard event listener registered too late (after onload())
    2. Obsidian's Vim mode processes ESC before our listener receives it
    3. Event listening used bubble phase, couldn't capture keys early enough
  • Solution:
    • Moved keyboard event listener registration to onload() method for early registration
    • Used event capture mode ({ capture: true }) instead of bubble mode
    • In ESC handler, detect current IM state using fcitx-remote -n
    • Only switch when current IM is Chinese
  • Result: First ESC press now immediately switches to English IM

Fixed Character Input Triggering IM Switch in Insert Mode

  • Issue: Normal text input in Insert mode (typing i, a, o, etc.) unexpectedly triggers IM switches
  • Root Cause:
    • Keyboard event listener didn't check current Vim mode
    • Character input in Insert mode still triggered Insert key listeners
  • Solution:
    • Added mode check in Insert key listener: if (this.currentVimMode !== 'normal') return;
    • Only respond to Insert keys in Normal mode
    • Character input in Insert mode doesn't trigger any IM switch logic
  • Result: Normal text input in Insert mode is no longer interrupted

Performance

Use Event Capture Mode for Better Responsiveness

  • Improvements:
    • Use addEventListener('keydown', handler, { capture: true }) instead of default bubble mode
    • Capture keys at earliest stage of event processing chain
    • Reduced time gap between Obsidian Vim processing and plugin processing
  • Benefits:
    • ESC key response is faster with almost no delay
    • IM switching is smoother and more natural
    • Reduced possibility of state inconsistency

Optimized IM Detection Logic

  • Improvements:
    • Check current IM before deciding to switch on ESC key press
    • Avoid unnecessary fcitx-remote calls
    • Reduced processing time by 10-20ms
  • Result:
    • No redundant switching when already in English IM
    • Lower system resource usage

Cleanup

Removed Redundant Code

  • Deleted:
    • Removed testVimModeSimulation() test function (~20 lines)
    • Removed testCurrentVimMode() test function (~15 lines)
    • Removed test command registration code
    • Deleted legacy global keyboard monitoring code
  • Impact:
    • Reduced ~50 lines of unused code
    • Decreased plugin size by ~2KB
    • Improved code maintainability

Simplified Logging

  • Before: Every event had detailed debug logs including:
    Current IM: xxx
    Entering insert mode...
    Vim mode: xxx
    Saved IM status: xxx
    Detected ESC key press
    Insert key pressed: i
    
  • After: Only key state transition logs remain:
    Loading plugin...
    ESC → English (saved Chinese)
    → Chinese
    Error: xxx
    
  • Benefits:
    • 70% less console output
    • Clearer logs, easier to see key information
    • Doesn't affect troubleshooting (error logs still detailed)

Code Structure Optimization

  • Improvements:
    • Simplified onunload() method, removed redundant try-catch
    • Unified error handling format
    • Improved clarity of code comments
    • Optimized function naming consistency
  • Result:
    • More readable and understandable code
    • Lower future maintenance cost

Technical Improvements

Triple Detection Mechanism

The plugin now uses three detection mechanisms for reliability:

  1. Keyboard Event Listening (Primary)

    • Uses capture mode to listen for ESC and Insert keys
    • Captures at earliest stage of event processing chain
    • Highest priority, fastest response
  2. CodeMirror Event Listening (Auxiliary)

    • Monitors vim-mode-change events
    • Supplements keyboard events
    • Handles mode switches triggered by non-keyboard actions (e.g., commands)
  3. Polling (Fallback)

    • Checks Vim mode every 100ms
    • Acts as last-resort safety mechanism
    • Ensures no mode changes are missed

State Synchronization Improvements

  • Optimized Vim mode state synchronization logic
  • Reduced state inconsistency cases
  • Improved IM switching accuracy

Documentation

  • Updated README.md with IM state memory feature description
  • Added workflow diagram (Mermaid format)
  • Enhanced troubleshooting guide
  • Added more detailed technical details

Known Issues

No known critical issues. If you encounter problems, see Troubleshooting or submit an Issue.

Upgrade Recommendation

Strongly recommend all users upgrade to this version, especially:

  • Users experiencing ESC key requiring multiple presses
  • Users whose input is interrupted in Insert mode
  • Users needing mixed Chinese/English input

Upgrade steps:

cd /path/to/your/vault/.obsidian/plugins/vim-im-switch/
git pull origin main
npm install
npm run build
# Restart Obsidian

[1.0.7] - 2024-12-20

Fixed

  • Fixed IM switching issue in Visual mode
  • Improved CodeMirror 6 compatibility

Performance

  • Optimized polling mechanism, reduced CPU usage

[1.0.6] - 2024-11-15

Added

  • Added settings interface to customize Chinese/English IM names
  • Support for configuring fcitx-remote command path

Fixed

  • Fixed IM name detection failure in some cases

[1.0.5] - 2024-10-10

Fixed

  • Fixed Windows compatibility issues
  • Improved error handling logic

[1.0.4] - 2024-09-05

Added

  • Added Linux system support
  • Improved log output format

[1.0.3] - 2024-08-01

Fixed

  • Fixed async issues during initialization
  • Improved error handling for command execution

[1.0.2] - 2024-07-15

Performance

  • Optimized IM switching response time
  • Reduced unnecessary command calls

[1.0.1] - 2024-06-20

Fixed

  • Fixed plugin loading failure
  • Improved compatibility

[1.0.0] - 2024-06-01

Initial Release

  • Basic Vim mode IM auto-switching functionality
  • macOS support
  • Normal/Insert mode switching support

Legend

  • Added - New features
  • Fixed - Bug fixes
  • Performance - Performance improvements
  • Cleanup - Code cleanup
  • Technical - Technical improvements
  • Documentation - Documentation updates
  • Known Issues - Known issues
  • Upgrade - Upgrade recommendations
  • Milestone - Important milestones