From 70fe27f31bc270906c8e2914da96037b82a813e4 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 25 Jul 2022 11:21:31 +0200 Subject: [PATCH] Allow multiline in checklist items [SCI-7008] --- app/assets/stylesheets/shared/inline_edit.scss | 1 + .../protocol/step_elements/checklistItem.vue | 2 ++ app/javascript/vue/shared/inline_edit.vue | 17 +++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/shared/inline_edit.scss b/app/assets/stylesheets/shared/inline_edit.scss index cf7a408e9..145f5993c 100644 --- a/app/assets/stylesheets/shared/inline_edit.scss +++ b/app/assets/stylesheets/shared/inline_edit.scss @@ -28,6 +28,7 @@ .sci-inline-edit__view { cursor: pointer; + white-space: pre-wrap; width: 100%; &.blank { diff --git a/app/javascript/vue/protocol/step_elements/checklistItem.vue b/app/javascript/vue/protocol/step_elements/checklistItem.vue index 8e4b7cfd4..e6e74b090 100644 --- a/app/javascript/vue/protocol/step_elements/checklistItem.vue +++ b/app/javascript/vue/protocol/step_elements/checklistItem.vue @@ -26,6 +26,8 @@ :multilinePaste="true" :editOnload="checklistItem.attributes.isNew" :smartAnnotation="true" + :saveOnEnter="false" + :allowNewLine="true" @editingEnabled="enableTextEdit" @editingDisabled="disableTextEdit" @update="updateText" diff --git a/app/javascript/vue/shared/inline_edit.vue b/app/javascript/vue/shared/inline_edit.vue index 057e1c2d4..d280bf604 100644 --- a/app/javascript/vue/shared/inline_edit.vue +++ b/app/javascript/vue/shared/inline_edit.vue @@ -40,6 +40,8 @@ characterLimit: { type: Number }, placeholder: { type: String }, autofocus: { type: Boolean, default: false }, + saveOnEnter: { type: Boolean, default: true }, + allowNewLine: { type: Boolean, default: false }, multilinePaste: { type: Boolean, default: false }, smartAnnotation: { type: Boolean, default: false }, editOnload: { type: Boolean, default: false } @@ -134,17 +136,16 @@ } }, handleInput() { - this.newValue = this.newValue.replace(/^[\n\r]+|[\n\r]+$/g, ''); + if (!this.allowNewLine) { + this.newValue = this.newValue.replace(/^[\n\r]+|[\n\r]+$/g, ''); + } this.$nextTick(this.resize); }, handleKeypress(e) { - switch(e.key) { - case 'Escape': - this.cancelEdit(); - break; - case 'Enter': - this.update(); - break; + if (e.key == 'Escape') { + this.cancelEdit(); + } else if (e.key == 'Enter' && this.saveOnEnter) { + this.update(); } }, resize() {