在给定的光标位置插入新文本 [英] Inserting a new text at given cursor position

查看:80
本文介绍了在给定的光标位置插入新文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的新语言模式自定义codemirror。作为此新模式实现的一部分,我正在编写一个新的工具栏,用户可以在其中选择一些文本并说出插入。此命令应在用户单击工具栏之前在用户键入的位置插入文本。

I am working on customizing the codemirror for my new language mode. As part of this new mode implementation, I am writing a new tool bar where user can select some text and say insert. This command should insert the text where user was typing just before clicking on tool bar.

我找不到任何API级别的支持。

I could not find any API level support to do so. If there is any other way can someone help me out on this?

基本上可以得到当前光标的位置和当前光标所在的位置。可能是Position对象

Basically get the current cursor positio- line number and position at which cursor is currently present. May be a Position object

用于插入文本的API,例如 insertText( Text,PositionObject)

API for inserting a text, something like insertText("Text", PositionObject)

推荐答案

replaceSelection http://codemirror.net/doc/manual.html#replaceSelection )?


doc.replaceSelection(替换:字符串,?select:字符串)
用给定的字符串替换所选内容。默认情况下,新选择在插入的文本之后结束。可选的select参数可用于更改此参数-传递 around将导致选择新文本,传递 start将选择范围折叠到插入文本的开头。

doc.replaceSelection(replacement: string, ?select: string) Replace the selection(s) with the given string. By default, the new selection ends up after the inserted text. The optional select argument can be used to change this—passing "around" will cause the new text to be selected, passing "start" will collapse the selection to the start of the inserted text.

这篇关于在给定的光标位置插入新文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆