I have two text areas that serve as the headers of two pages, so they need to always have the same content. In order for the undo/redo functionality to work I made it so only one of them has a toolbar and if the clone is selected it quickly swaps places with the original and the original is focused.
$(document.body).on('focus', '#TextEditor .headerofpage.clone', function(e){
e.preventDefault();
var editor = $('#TextEditor').find('.headerofpage[id]'),
eParent = editor.parent(),
index = editor.prevAll().length,
thisElem = $(this);
editor.insertBefore(thisElem);
thisElem.insertBefore(eParent.children().eq(index));
editor.trigger('focus');
});
The problem is that the focus places the text cursor at the beginning of the text area. I tried with the following event, but it doesn't work. It works for clicking on elements and triggering their click events, but it doesn't even put focus on text areas.
$(document.body).on('mouseup', '#TextEditor .headerofpage[id]', function(e){
var x = e.clientX;
var y = e.clientY;
document.elementFromPoint(x, y).click();
});
There is a way to place the text cursor at a specific character in a text area, but I need the mouse's location, is it possible?