Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: handle non markdown files in conflicts
Do not parse non markdown files when resetting the content.

Fixes #4205.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Aug 17, 2023
commit bab845125409d596daafb32201f55406f4845c19
14 changes: 10 additions & 4 deletions src/components/CollisionResolveDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@
</template>

<script>
import { useEditorMixin, useSyncServiceMixin } from './Editor.provider.js'
import {
useEditorMixin,
useIsRichEditorMixin,
useSyncServiceMixin
} from './Editor.provider.js'
import { NcButton } from '@nextcloud/vue'
import markdownit from './../markdownit/index.js'
import setContent from './../mixins/setContent.js'
export default {
name: 'CollisionResolveDialog',
components: {
NcButton,
},
mixins: [
useEditorMixin,
useIsRichEditorMixin,
setContent,
useSyncServiceMixin,
],
props: {
Expand All @@ -62,10 +68,10 @@ export default {
this.$editor.setEditable(!this.readOnly)
},
resolveServerVersion() {
const { outsideChange } = this.syncError.data
this.clicked = true
const markdownItHtml = markdownit.render(this.syncError.data.outsideChange)
this.$editor.setEditable(!this.readOnly)
this.$editor.commands.setContent(markdownItHtml)
this.setContent(outsideChange, { isRich: this.$isRichEditor })
this.$syncService.forceSave().then(() => this.$syncService.syncUp())
},
},
Expand Down
25 changes: 6 additions & 19 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
<script>
import Vue, { set } from 'vue'
import { mapActions, mapState } from 'vuex'
import escapeHtml from 'escape-html'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
Expand Down Expand Up @@ -113,6 +112,7 @@ import markdownit from './../markdownit/index.js'
import { CollaborationCursor, Keymap } from '../extensions/index.js'
import DocumentStatus from './Editor/DocumentStatus.vue'
import isMobile from './../mixins/isMobile.js'
import setContent from './../mixins/setContent.js'
import store from './../mixins/store.js'
import MenuBar from './Menu/MenuBar.vue'
import ContentContainer from './Editor/ContentContainer.vue'
Expand All @@ -138,6 +138,7 @@ export default {
},
mixins: [
isMobile,
setContent,
store,
],
provide() {
Expand Down Expand Up @@ -349,23 +350,6 @@ export default {
'setCurrentSession',
]),

setContent(content, { addToHistory = true } = {}) {
this.$editor.chain()
.setContent(this.parseContent(content), addToHistory)
.command(({ tr }) => {
tr.setMeta('addToHistory', addToHistory)
return true
})
.run()

},

parseContent(documentSource) {
return !this.isRichEditor
? `<pre>${escapeHtml(documentSource)}</pre>`
: markdownit.render(documentSource) + '<p/>'
},

initSession() {
if (!this.hasDocumentParameters) {
this.emit('error', 'No valid file provided')
Expand Down Expand Up @@ -546,7 +530,10 @@ export default {
})
this.hasEditor = true
if (!documentState && documentSource) {
this.setContent(documentSource, { addToHistory: false })
this.setContent(documentSource, {
isRich: this.isRichEditor,
addToHistory: false
})
}
this.listenEditorEvents()
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/PlainText.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { Extension } from '@tiptap/core'

/* eslint-disable import/no-named-as-default */
import CodeBlock from '@tiptap/extension-code-block'
import Text from '@tiptap/extension-text'
import PlainTextDocument from './../nodes/PlainTextDocument.js'

Expand All @@ -33,6 +34,7 @@ export default Extension.create({
return [
PlainTextDocument,
Text,
CodeBlock,
]
},

Expand Down
42 changes: 42 additions & 0 deletions src/mixins/setContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* @copyright Copyright (c) 2023 Max <[email protected]>
*
* @author Max <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import escapeHtml from 'escape-html'
import markdownit from './../markdownit/index.js'

export default {
methods: {
setContent(content, { isRich, addToHistory = true } = {}) {
const html = isRich
? markdownit.render(content) + '<p/>'
: `<pre>${escapeHtml(content)}</pre>`
this.$editor.chain()
.setContent(html, addToHistory)
.command(({ tr }) => {
tr.setMeta('addToHistory', addToHistory)
return true
})
.run()
},

},
}