Files
vim-im-switch/CHANGELOG_en.md
2025-11-04 17:50:43 +08:00

7.7 KiB

Changelog

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

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

English | 中文


[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