jsdialog: send selection for text view

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I3d87a676a1c47ea8fc99ba523ccf960a6cbde90f
This commit is contained in:
Szymon Kłos 2023-03-09 11:26:50 +01:00 committed by Szymon Kłos
parent 1665d6e7bc
commit 58e686deb9

View file

@ -21,6 +21,14 @@
/* global JSDialog */
function _sendSimpleSelection(edit, builder) {
var startPos = edit.selectionStart;
var endPos = edit.selectionEnd;
var selection = startPos + ';' + endPos;
builder.callback('edit', 'textselection', edit, selection, builder);
}
function _multiLineEditControl(parentContainer, data, builder, callback) {
var controlType = 'textarea';
if (data.cursor && (data.cursor === 'false' || data.cursor === false))
@ -49,6 +57,29 @@ function _multiLineEditControl(parentContainer, data, builder, callback) {
builder.callback('edit', 'change', edit, this.value, builder);
});
edit.addEventListener('mouseup', function (event) {
if (edit.disabled) {
event.preventDefault();
return;
}
_sendSimpleSelection(event.target, builder);
});
edit.addEventListener('keydown', function (event) {
if (edit.disabled) {
event.preventDefault();
return;
}
if (event.key === 'Left' || event.key === 'ArrowLeft'
|| event.key === 'Right' || event.key === 'ArrowRight'
|| event.key === 'Up' || event.key === 'ArrowUp'
|| event.key === 'Down' || event.key === 'ArrowDown') {
setTimeout(function () { _sendSimpleSelection(edit, builder); }, 0);
}
});
if (data.hidden)
L.DomUtil.addClass(edit, 'hidden');