Skip to Main Content
  • Questions
  • get current cursor position in TinyMCE Oracle Apex 23.1

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: January 23, 2024 - 6:18 am UTC

Last updated: February 27, 2024 - 5:07 am UTC

Version: 23.1

Viewed 1000+ times

You Asked

I need to have current cursor position in TinyMCE Oracle Apex. I use this js code for another type of page items and it work correctly.

var curPos = document.getElementById("P7_TEXT").selectionStart;
but when "P7_TEXT" is a Rich Text Editor (TinyMCE) , it will return "undefined"

what can I do to get the current position of cursor in rich text page item?

APEX version is 23.1.

and Connor said...

I asked the APEX team and got some feedback

selectionStart is specific to Textareas and such. TinyMCE is its own widget for which we can only use the APIs they provide. You could try messing with the range API. E.g:

const tinymceEditor = apex.items.P1_RTE.getEditor();
// getting the range
const range = tinymceEditor.selection.getRng();
// setting the range
tinymceEditor.selection.setRng( range );

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

get current position in all of TinyMCE NOT in selected line

Amene Khalili, February 26, 2024 - 8:27 am UTC

Thank You for answer to my Question
this solution get position in line we selected.
but I need cursor position in all of TinyMCE
Can we get Cursor position in all of that?
Connor McDonald
February 27, 2024 - 5:07 am UTC

TinyMCE is its own widget for which we can only use the APIs they provide

https://www.tiny.cloud/docs/api/tinymce/