5
How can I insert text at the position of a cursor? the field is a contenteditable so it can contain in addition to normal html css text and images.
I took the example in the plugin documentation: Summernote - How to Insert text to cursor position?
But still the example doesn’t work.
Example:
$('#summernote').summernote({
height: 300
});
$(".list-group li span").click(function() {
$('#summernote').summernote('editor.saveRange');
$('#summernote').summernote('editor.restoreRange');
$('#summernote').summernote('editor.focus');
$('#summernote').summernote('editor.insertText', $(this).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.0/summernote.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.0/summernote.css" rel="stylesheet">
<ul class="list-group">
<li class="list-group-item"><span class="label label-primary">[PHONE]</span> Telefone da Empresa.</li>
<li class="list-group-item"><span class="label label-primary">[FAX]</span> Telefax da Empresa.</li>
<li class="list-group-item"><span class="label label-primary">[EMAIL_1]</span> Primeiro Email da Empresa.</li>
<li class="list-group-item"><span class="label label-primary">[EMAIL_2] </span> Segundo Email da Empresa.</li>
</ul>
<div id="summernote"></div>
I understand, but I have to somehow preserve this cursor position, because summernote Toolbar buttons can do this.
– Gabriel Rodrigues
Is it not possible in the output field event to store what the cursor position was? If in the output event it is already set to 0, it may be possible in the edit field event
– José Henrique Luckmann