Skip to content

Commit

Permalink
fix: handle non markdown files in conflicts
Browse files Browse the repository at this point in the history
Do not parse non markdown files when resetting the content.

Fixes #4205.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and juliusknorr committed Jun 22, 2023
1 parent 27ae323 commit 5ecdcf4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
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.setOptions({ editable: !this.readOnly })
},
resolveServerVersion() {
const { outsideChange } = this.syncError.data
this.clicked = true
const markdownItHtml = markdownit.render(this.syncError.data.outsideChange)
this.$editor.setOptions({ editable: !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 @@ -78,7 +78,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 @@ -111,6 +110,7 @@ import markdownit from './../markdownit/index.js'
import { 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 @@ -132,6 +132,7 @@ export default {
},
mixins: [
isMobile,
setContent,
store,
],
provide() {
Expand Down Expand Up @@ -339,23 +340,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 @@ -536,7 +520,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()
},

},
}

0 comments on commit 5ecdcf4

Please sign in to comment.