0

In Summernote, one can easily insert a text like so:

$('#summernote').summernote('editor.insertText', 'hello world'));

One could also insert a node like so:

$('#summernote').summernote('insertNode', node);

When inserting the Node, the cursor conveniently stays within the boundaries of the tag, for example when inserting the kbd tag, the cursor stays in between : <kbd> Cursor </kbd>

My question is how could one insert a text (not a tag) like "aa" and maintains the cursor in between the the two a's "a cursor a". So the only thing that I can think of is to control the cursor which I don't know how after many hours of researching. It doesn't have to be through cursor control if one knows a better way.

Greg
  • 63
  • 1
  • 9
  • What if you insert "jshgjha jhasjhaj ajhajha jhasjhj asjhjhajahsjha" ... where would your cursor locator be preferred then? Your example is not sufficient. You want it (a) at the start of what was inserted? (b) one character in? (c) one character from the end (d) in the middle? – Kevin Brown Sep 03 '18 at 22:00
  • After you insert, what does window.getSelection().getRangeAt(0).startOffset yield? Go from there. – Kevin Brown Sep 03 '18 at 22:38
  • Thanks Kevin, sorry for my vague question. I am asking about d) in the middle. so whatever you insert, the mirror is on the other side and I want the cursor to be in the middle. So, if you put "jshgjha" there is another mirrored "jshgjha" at the end and I want the cursor to be in the middle like so: jshgjha cursor jshgjha – Greg Sep 04 '18 at 04:03
  • Looked at your suggestion, window.getSelection().getRangeAt(0).startOffset returns 2, and I want to insert the cursor at position 1. Should I follow something like this: https://stackoverflow.com/questions/6249095/how-to-set-caretcursor-position-in-contenteditable-element-div if so what should be my range.setStart(el.childNodes[2], 5)? – Greg Sep 04 '18 at 04:40
  • @KevinBrown Any idea how I can proceed? – Greg Sep 13 '18 at 22:25
  • You should code up a solution and post the code you are trying that is not working. Stackoverflow is not a platform where people write code for you, it is a platform for us to assist you with existing code. Create a fiddle or something, post that sample with all the code and we can look at helping you. – Kevin Brown Sep 14 '18 at 22:59
  • @KevinBrown Re the first part of your comment: here is a fiddle https://jsfiddle.net/Greg_tavakolian/7goyk3xv/33/ I prefer using method 1, if that is not a possibility I am looking to see how I can modify method 2 to accomplish what I am looking for. Re the second part of your comment: I believe my question and comments show that I am not looking for someone to do the coding for me. – Greg Sep 16 '18 at 19:36

0 Answers0