arnog / mathlive

A web component for easy math input
https://cortexjs.io/mathlive
MIT License
1.27k stars 261 forks source link

keybinding command switchMode should insert the prefix in the previous mode and the suffix with the new mode #2375

Closed EmaGht closed 1 month ago

EmaGht commented 1 month ago

Use case

Being able to write quoted text while autmatically entering text mode

Actual Behavior

With a configuration as follows:

{ key: 'shift+[Digit2]', ifPlatform: 'windows', command: ['switchMode', 'text', "", "\""], ifMode: "math" },
{ key: 'shift+[Digit2]', ifPlatform: 'windows', command: ['switchMode', 'math', "\"", ""], ifMode: "text" }

I'm trying to switch between math mode and text mode while adding a " for extra visual clarity as it's difficult for a user to notice he is writing actual text otherwise.

The first half is actually possible using

{ key: 'shift+[Digit2]', ifPlatform: 'windows', command: ['switchMode', 'text', "\""], ifMode: "math" },

As the prefix gets added using the new mode, which is "text", but when i type " again it gets added by this keybinding

{ key: 'shift+[Digit2]', ifPlatform: 'windows', command: ['switchMode', 'math', "\"", ""], ifMode: "text" }

in math mode, breaking the visual

Expected Behavior

Be able to write the prefix from "switchMode" in the previous mode, while writing the suffix in the next mode.

I guess what i'm asking is using previousMode instead of mode here

Environment

Is this a regression: did it use to work in a previous version? no

MathLive version latest

Operating System windows

Browser all

arnog commented 1 month ago

The SwitchMode command has two optional arguments. The first one is a "prefix" that is rendered in the current mode, and the second one is a "suffix" that is rendered in the new mode. So, you should use it to do what you want.

However, the implementation is currently broken and needs to be fixed.