mathquill latex-如何通过代码移动光标(选择)?

2022-01-24 00:00:00 latex javascript html mathquill

我正在使用 mathquill lib (mathquill git),我正在尝试制作键盘和退格键使用 html 按钮,但我不知道如何移动光标抛出公式.

I am using mathquill lib (mathquill git) and I am trying to make a keypad and a backspace using html buttons but I can't figure out how to move the cursor throw the formula.

谢谢,

推荐答案

您可以在 mathquill 中的 textarea 上触发自定义 keydown 事件以在公式中移动光标.

You can trigger custom keydown event on textarea within mathquill to move cursor through formula.

var customKeyDownEvent = $.Event('keydown');

customKeyDownEvent.bubbles = true;
customKeyDownEvent.cancelable =true;
customKeyDownEvent.charCode = 37;  // 37 for left arrow key
customKeyDownEvent.keyCode = 37;   
customKeyDownEvent.which = 37;

$('.mathquill-editable textarea').trigger(customKeyDownEvent);

使用charCode/keyCode/分别是:

Use charCode / keyCode / which are:

  1. 37 代表左箭头键
  2. 39 代表右箭头键

谢谢.

相关文章