CodeMirror getCursor() not working? JQuery Javascript -


using codemirror. cannot getcursor() function work. have jsfiddle codemirror sources attached.

----> see here jsfiddle <----

i'm trying insert text editor, force cursor move specified number of spaces. i'm trying cursor location getcursor() can't seem work. thoughts?

$(document).ready(function() {  //changing textarea codemirror rich text editor  var editor = codemirror.fromtextarea(document.getelementbyid('thezone'), {     mode: 'text/html',     linewrapping : true,     linenumbers : true,     extrakeys : {     "tab": "indentmore",      "shift-tab": "indentless",     "'>'": function(cm) { cm.closetag(cm, '>'); },     "'/'": function(cm) { cm.closetag(cm, '/'); } } , oncursoractivity: function(cm) {     cm.setlineclass(hlline, null, null);     hlline = cm.setlineclass(cm.getcursor().line, null, "activeline"); } });   //when select changes - insert value cm editor, set focus, cursor   position, move cursor [x] amount of spaces. $('#sel').change(function() {     var selected = $(this).find('option:selected');     var mynum = selected.data('val');     editor.replaceselection($(this).val(), focus);     editor.focus();     var start_cursor = editor.getcursor();  //i need cursor position     alert(start_cursor);  //cursor position comes [object object]      //write code move cursor [x] amount of spaces. [x] data-val value.   });       }); 

the code seems work fine. alert() not display objects. use console.log() instead. added rest of code.

    $('#sel').change(function() {     var selected = $(this).find('option:selected');     var mynum = selected.data('val');     editor.replaceselection($(this).val(), focus);     editor.focus();     var start_cursor = editor.getcursor();  //i need cursor position     console.log(start_cursor);  //cursor position      var cursorline = start_cursor.line;     var cursorch = start_cursor.ch;      //code move cursor [x] amount of spaces. [x] data-val value.     editor.setcursor({line: cursorline , ch : cursorch -mynum });  }); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -