Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom key maps in CodeMirror?

I want add 'Alt-Space' key map to codemirror and then perform a particular function when the keys are pressed. I am not able to add this keymap using .

cm.addKeyMap

Where should I be writing this function so that the key map can be bound to a particular function?

like image 395
adityazoso Avatar asked Aug 02 '14 08:08

adityazoso


People also ask

How do I set up CodeMirror?

Download CodeMirror files. Download jQuery file. Inside the codemirror project folder create subfolders and name them js, css and plugin. The js folder will hold all the javascript files.

How does CodeMirror work?

CodeMirror uses a concept of operations, which start by calling a specific set-up function that clears the state and end by calling another function that reads this state and does the required updating. Most event handlers, and all the user-visible methods that change state are wrapped like this.

How do I get text from CodeMirror?

To get the value of the CodeMirror text editor we need to write some javascript code in the default. js file. $(document). ready(function(){ //code here...

What is CodeMirror CSS?

CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides only the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented.


1 Answers

What is the exact code you are using?

For your information, you can always add any keyMap to the editor instance by the following lines of code :

var map = {"Alt-Space": function(cm){...}}
editor.addKeyMap(map);

where, editor is the CodeMirror instance.

like image 132
djadmin Avatar answered Oct 07 '22 08:10

djadmin