From bed1d31bc8b7b32cfe37859842ec16dcaf66a434 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 16 Nov 2020 11:37:04 +0000 Subject: [PATCH] Restore cursor position in TypedInput cred-mode --- .../src/js/ui/common/typedInput.js | 17 ++++++++++++++--- .../src/sass/ui/common/typedInput.scss | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js index 037e8e454..fa1e68cca 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js @@ -173,6 +173,7 @@ valueLabel: function(container,value) { var that = this; container.css("pointer-events","none"); + container.css("flex-grow",0); this.elementDiv.hide(); var buttons = $('
').css({ position: "absolute", @@ -184,22 +185,25 @@ width:"20px" }).appendTo(buttons).on("click", function(evt) { evt.preventDefault(); + var cursorPosition = that.input[0].selectionStart; var currentType = that.input.attr("type"); if (currentType === "text") { that.input.attr("type","password"); eyeCon.removeClass("fa-eye-slash").addClass("fa-eye"); setTimeout(function() { that.input.focus(); + that.input[0].setSelectionRange(cursorPosition, cursorPosition); },50); } else { that.input.attr("type","text"); eyeCon.removeClass("fa-eye").addClass("fa-eye-slash"); setTimeout(function() { that.input.focus(); + that.input[0].setSelectionRange(cursorPosition, cursorPosition); },50); } }).hide(); - var eyeCon = $('').css("margin-left","-1px").appendTo(eyeButton); + var eyeCon = $('').css("margin-left","-2px").appendTo(eyeButton); if (value === "__PWRD__") { var innerContainer = $('
').css({ @@ -284,7 +288,7 @@ this.input.css('width','100%'); this.uiSelect.width(m[1]); this.uiWidth = null; - } else { + } else if (this.uiWidth !== 0){ this.uiSelect.width(this.uiWidth); } ["Right","Left"].forEach(function(d) { @@ -304,7 +308,11 @@ this.element.attr('type','hidden'); - this.options.types = this.options.types||Object.keys(allOptions); + if (!this.options.types && this.options.type) { + this.options.types = [this.options.type] + } else { + this.options.types = this.options.types||Object.keys(allOptions); + } this.selectTrigger = $('').prependTo(this.uiSelect); $('').toggle(this.options.types.length > 1).appendTo(this.selectTrigger); @@ -872,6 +880,9 @@ this.elementDiv.hide(); this.valueLabelContainer.hide(); } else if (opt.valueLabel) { + // Reset any CSS the custom label may have set + this.valueLabelContainer.css("pointer-events",""); + this.valueLabelContainer.css("flex-grow",1); this.valueLabelContainer.show(); this.valueLabelContainer.empty(); this.elementDiv.hide(); diff --git a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss index ec865b116..fb3e331ee 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss @@ -18,6 +18,7 @@ border: 1px solid $form-input-border-color; border-radius: 4px; height: 34px; + line-height: 14px; display: inline-flex; padding: 0; margin: 0;