CodeMirror custom showHint() call - Javascript CodeMirror

Javascript examples for CodeMirror:Configuration

Description

CodeMirror custom showHint() call

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" type="text/css" href="https://codemirror.net/lib/codemirror.css"> 
      <link rel="stylesheet" type="text/css" href="https://codemirror.net/addon/hint/show-hint.css"> 
      <script type="text/javascript" src="https://codemirror.net/lib/codemirror.js"></script> 
      <script type="text/javascript" src="https://codemirror.net/addon/hint/show-hint.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w.  j a va  2s .  c  o m
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
   // options here
});
editor.on('cursorActivity', function(){
   var options = {
    hint: function() {
       return {
         from: editor.getDoc().getCursor(),
          to: editor.getDoc().getCursor(),
        list: ['foo', 'bar']
      }
    }
  };
   editor.showHint(options);
});
    }

      </script> 
   </head> 
   <body> 
      <textarea id="code">// Move the cursor around here to activate showHint
</textarea>  
   </body>
</html>

Related Tutorials