The keyboard-magic plugin for IntelliJ provides a reversible solution for text typed in the wrong keyboard layout. Instead of attempting to detect user intent through complex algorithms, the tool treats the conversion as an involution, where applying the same operation twice returns the original text.

The plugin uses a deterministic layout detector that counts Cyrillic and Latin characters, ignoring punctuation and digits to avoid noise. This approach ensures that the tool is predictable, as it never fails to perform an action or leaves the user guessing about its state.

The mapping is built on physical keys rather than character meanings to maintain a perfect round-trip property. The plugin uses a hardcoded table of 94 symbols per layout, ensuring that every conversion is strictly reversible without exceptions or edge cases.

To handle multiple carets within the same word, the plugin tracks processed ranges to prevent accidental double-conversion. All edits are applied from the end of the document to the beginning, ensuring that offsets remain valid throughout the process.

The implementation uses a single write command action, allowing users to undo the entire conversion in one step. Additionally, the plugin enforces API version compatibility during compilation to prevent runtime errors in different versions of the IntelliJ platform.