Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert text to cursor position? #282

Closed
mrjunaidali opened this issue Mar 4, 2014 · 23 comments
Closed

How to insert text to cursor position? #282

mrjunaidali opened this issue Mar 4, 2014 · 23 comments

Comments

@mrjunaidali
Copy link

Hi All,

its a nice, easy and very light too.

I want o have an option to insert text to cursor position? any help?

Thanks
Junaid

@hackerwins hackerwins added this to the v0.6.0 milestone Mar 5, 2014
@hackerwins hackerwins self-assigned this Mar 5, 2014
@mrjunaidali
Copy link
Author

Dear HackerWins?

Any help on this?

Thanks.
Junaid Ali

@hackerwins hackerwins removed this from the v0.6.0 milestone Apr 26, 2014
@abishekrsrikaanth
Copy link

Would like to see how this can be done. Have the same requirement.

@ghost
Copy link

ghost commented Apr 28, 2014

I would also like this looked at for issue #354

@mrjunaidali
Copy link
Author

any news on it?

@Diabz
Copy link

Diabz commented Jun 4, 2014

Hi,
this method works for me
http://maxrohde.com/2014/03/28/insert-text-at-caret-position-in-summernote-editor-for-bootstrap/

juste replace "this.substring" with "oldContent.substring"

Dear HackerWins, thanks a lot for your work, if you could add this function to summernote plugin it would be great !!

@ghost
Copy link

ghost commented Jun 5, 2014

👍

@hackerwins hackerwins removed their assignment Jul 25, 2014
@baptistedonaux
Copy link

👍

@atuttle
Copy link

atuttle commented Nov 12, 2014

I'm also interested in this feature.

@hackerwins
Copy link
Member

@mrjunaidali, @abishekrsrikaanth, @Diabz, @studojunkyard, @baptistedonaux, @atuttle

For now, You can insert text with plugin (develop branch only).

below example plugin link.
https://github.com/HackerWins/summernote/blob/develop/plugin/summernote-ext-hello.js

editor.insertText($editable, 'hello ');

If you access editor instance you can use other editor's functions(insertNode, undo, bold, ...)

https://github.com/HackerWins/summernote/blob/develop/src/js/editing/Editor.js

@atuttle
Copy link

atuttle commented Nov 13, 2014

@hackerwins: var editor = $.summernote.eventHandler.getEditor();

At first glance it looks like this could be problematic if there are multiple editors on the same page, though I haven't tested it. If that is true, it would be better if there were a $('.editor').data('summernote-editor') or something like that to get the editor instance tied to that specific editor div.

@atuttle
Copy link

atuttle commented Nov 17, 2014

Is it possible to do text insertion without using the bleeding edge code? How soon do you expect to have it completed and available in master?

@hackerwins
Copy link
Member

@atuttle
Copy link

atuttle commented Nov 30, 2014

I'll probably get a chance to try it later this week, but I still have my initial question: Is $.summernote.eventHandler.getEditor() going to work (correctly) with multiple summernote editors on the same screen at once?

@mohsinali
Copy link

@hackerwins what is '$editable'.

@easylogic
Copy link
Member

@mohsinali

$editable is jquery element with contenteditable attribute.

<div class="note-editable" contenteditable="true" style="height: 300px;"></div>

@easylogic
Copy link
Member

Please use new summernote api.

refer to http://summernote.org/#/deep-dive

@nsamuels0510
Copy link

The new summernote api did not fix #1611, custom drop down does not insert selected list item at cursor position but enters it at the beginning of the editor.

@jimmynguyc
Copy link

jimmynguyc commented Apr 17, 2016

Use the saveRange and restoreRange methods to restore the selected range.

$('#summernote').summernote('editor.saveRange');

// Editor loses selected range (e.g after blur)

$('#summernote').summernote('editor.restoreRange');
$('#summernote').summernote('editor.focus');
$('#summernote').summernote('editor.insertText', 'This text should appear at the cursor');

Alternatively, you can invoke directly from the context variable

context.invoke('editor.saveRange');

// Editor loses selected range (e.g after blur)

context.invoke('editor.restoreRange');
context.invoke('editor.focus');
context.invoke('editor.insertText', 'This text should appear at the cursor');

It's how the pasteByHook works (

context.invoke('editor.restoreRange');
context.invoke('editor.focus');
context.invoke('editor.insertImagesOrCallback', [blob]);
) so I think it's gonna be the idiomatic way.

@Emidomenge
Copy link

@jimmynguyc You saved my life ! 👍

@ghanbari
Copy link

@jimmynguyc You save my life,
thank you very much 💯

@msqar
Copy link

msqar commented Mar 2, 2018

@jimmynguyc hey Jimmy, thanks for the info. But it seems that saveRange and restoreRange aren't working in Safari (Version 11.0.3). Can anyone confirm this?
Is not saving the text range. Firefox and Chrome works fine.

@alegout
Copy link

alegout commented Feb 6, 2019

@msqar indeed, I got the same problem. It's not working on safari apparently

EDIT: I was using insertNode, i now use pasteHTML and it's working with safari.

@victorting
Copy link

@msqar indeed, I got the same problem. It's not working on safari apparently

EDIT: I was using insertNode, i now use pasteHTML and it's working with safari.

Do you found any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests