简体   繁体   English

摩纳哥编辑器中的虚拟键盘

[英]Virtual keyboard in Monaco editor

I am new to Monaco editor and I am trying to use a virtual keyboard and type through the virtual keyboard. 我是Monaco编辑器的新手,我正在尝试使用虚拟键盘并通过虚拟键盘键入内容。 Do you have any idea how can I do that? 你知道我该怎么做吗? This is what I am doing currently 这是我目前正在做的

        var position = editor.getPosition(); // Get current mouse position
        var text = editor.getValue(position);
        var splitedText=text.split("\n");
        var lineContent = splitedText[position.lineNumber-1]; // Get selected line content
        var textToInsert = character; // text to be inserted
        splitedText[position.lineNumber-1] = [lineContent.slice(0, position.column-1), textToInsert, lineContent.slice(position.column-1)].join(''); // Append the text exactly at the selected position (position.column -1)

        editor.setValue(splitedText.join("\n")); // Save the value back to the Editor
        editor.setPosition(position+1);

first character will be inserted properly but when i trigger next character it goes infront of the previous character. 第一个字符将被正确插入,但是当我触发下一个字符时,它将进入前一个字符的前面。 Is there any idea to fix that? 有什么办法解决吗?

Thank you 谢谢

I figure out the answer 我找出答案

       var line = editor.getPosition();
        var range = new monaco.Range(line.lineNumber, line.column, line.lineNumber, line.column);
        var id = { major: 1, minor: 1 };
        var text = character ;
        var op = {identifier: id, range: range, text: text, forceMoveMarkers: true};
        editor.executeEdits("my-source", [op]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM