简体   繁体   中英

ACE editor select word/token after inserting phrase

I'm playing around with ACE editor and I'm trying to create a simple markdown toolbar where the use can insert bold text. italic etc.

I placed an event on the given button and, once clicked, I insert into the editor the right markup for the given request. For example, the bold tag has the following syntax that I insert:

**bold_text**

What I'm trying to do is to also select the bold_text token so the user can start typing right away his bold contents.

I have the ace editor instantiated and everything works but I don't know how to find a word inside the editor and select it.

I saw that ACE has a method called selectWord or selectAWord but non of them takes any parameters. Any ideas?

You can use editor.selection.setRange(...) method but for this usecase snippetManager provides much nicer api

var snippetManager = require("ace/snippets").snippetManager
snippetManager.insertSnippet(editor, "**${0:$SELECTION}**")

the snippets in ace have the same format as snippets in textmate/sublime.

Note that you need to include ext-language_tools.js to be able to use snippetManager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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