Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NewMessage, EditabeTextField) - don't parse NcRichContenteditable output before sending #10422

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/ConversationSettings/BasicInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
:loading="isDescriptionLoading"
:edit-button-aria-label="t('spreed', 'Edit conversation description')"
:placeholder="t('spreed', 'Enter a description for this conversation')"
use-markdown
@submit-text="handleUpdateDescription"
@update:editing="handleEditDescription" />
</template>
Expand Down
41 changes: 26 additions & 15 deletions src/components/ConversationSettings/EditableTextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
-->

<template>
<div ref="editable-text-field"
:key="forceReRenderKey"
class="editable-text-field">
<NcRichContenteditable ref="richContenteditable"
<div ref="editable-text-field" class="editable-text-field">
<NcRichText v-if="!editing"
class="editable-text-field__output"
:text="text"
autolink
:use-markdown="useMarkdown" />
<NcRichContenteditable v-else
ref="richContenteditable"
:value.sync="text"
:auto-complete="()=>{}"
:maxlength="maxLength"
:contenteditable="editing && !loading"
:contenteditable="!loading"
:placeholder="placeholder"
@submit="handleSubmitText"
@keydown.esc="handleCancelEditing" />
Expand Down Expand Up @@ -77,11 +81,13 @@ import Pencil from 'vue-material-design-icons/Pencil.vue'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcRichContenteditable from '@nextcloud/vue/dist/Components/NcRichContenteditable.js'
import NcRichText from '@nextcloud/vue/dist/Components/NcRichText.js'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip.js'

export default {
name: 'EditableTextField',
components: {
NcRichText,
Pencil,
Check,
Close,
Expand Down Expand Up @@ -147,14 +153,18 @@ export default {
type: String,
required: true,
},

useMarkdown: {
type: Boolean,
default: false,
},
},

emits: ['update:editing', 'submit-text'],

data() {
return {
text: this.initialText,
forceReRenderKey: 0,
overflows: null,
}
},
Expand Down Expand Up @@ -217,19 +227,14 @@ export default {
return
}
// Remove leading/trailing whitespaces.
// FIXME: remove after issue is resolved: https://github.com/nextcloud/nextcloud-vue/issues/3264
// FIXME upstream: https://github.com/nextcloud-libraries/nextcloud-vue/issues/4492
const temp = document.createElement('textarea')
temp.innerHTML = this.text
this.text = temp.value.replace(/\r\n|\n|\r/gm, '\n').trim()
temp.innerHTML = this.text.replace(/&/gmi, '&amp;')
this.text = temp.value.replace(/\r\n|\n|\r/gm, '\n').replace(/&amp;/gmi, '&')
.replace(/&lt;/gmi, '<').replace(/&gt;/gmi, '>').replace(/&sect;/gmi, '§').trim()

// Submit text
this.$emit('submit-text', this.text)
/**
* Change the NcRichContenteditable key in order to trigger a re-render
* without this all the trimmed new lines and whitespaces would
* still be present in the contenteditable element.
*/
this.forceReRenderKey += 1
},

handleCancelEditing() {
Expand Down Expand Up @@ -257,6 +262,12 @@ export default {
&__edit {
margin-left: var(--default-clickable-area);
}

&__output {
width: 100%;
padding: 10px;
line-height: var(--default-line-height);
}
}

.spinner {
Expand Down
7 changes: 4 additions & 3 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,11 @@ export default {
}

if (this.hasText) {
// FIXME: remove after issue is resolved: https://github.com/nextcloud/nextcloud-vue/issues/3264
// FIXME upstream: https://github.com/nextcloud-libraries/nextcloud-vue/issues/4492
const temp = document.createElement('textarea')
temp.innerHTML = this.text
this.text = temp.value
temp.innerHTML = this.text.replace(/&/gmi, '&amp;')
this.text = temp.value.replace(/&amp;/gmi, '&').replace(/&lt;/gmi, '<')
.replace(/&gt;/gmi, '>').replace(/&sect;/gmi, '§')

const temporaryMessage = await this.$store.dispatch('createTemporaryMessage', {
text: this.text.trim(),
Expand Down
Loading