Enables friendly pasting in multipletextbox

This commit is contained in:
Søren Kottal
2021-10-05 22:28:11 +02:00
committed by Michael Latouche
parent 6a5e34b24d
commit 7ec1147243
2 changed files with 24 additions and 0 deletions

View File

@@ -26,6 +26,29 @@
}
}
$scope.paste = function (event, index) {
event.preventDefault();
var text = (event.clipboardData || window.clipboardData || event.originalEvent.clipboardData).getData('text');
var lines = text.split(/\r?\n/).map(line => { return { value: line, hasFocus: false } });
if (lines.length > 0) {
// merge with the current text
var currentText = $scope.model.value[index].value;
lines[0].value = currentText.substring(0, event.target.selectionStart) + lines[0].value;
lines[lines.length - 1].value = lines[lines.length - 1].value + currentText.substring(event.target.selectionEnd);
// clear selection
event.target.selectionEnd = event.target.selectionStart;
// remove focus from existing values
$scope.model.value.forEach(value => value.hasFocus = false);
// add all the lines to the value
lines[lines.length - 1].hasFocus = true;
$scope.model.value.splice(index, 1, ...lines);
}
}
$scope.addRemoveOnKeyDown = function (event, index) {
var txtBoxValue = $scope.model.value[index];

View File

@@ -6,6 +6,7 @@
class="umb-property-editor umb-textstring textstring flx-i"
ng-trim="false"
ng-keyup="addRemoveOnKeyDown($event, $index)"
ng-paste="paste($event, $index)"
focus-when="{{item.hasFocus}}" />
<div class="icon-wrapper">