Skip to content

Commit cc601a7

Browse files
max-nextcloudmejo-
authored andcommitted
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]>
1 parent b8b839a commit cc601a7

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

src/components/CollisionResolveDialog.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@
3232
</template>
3333

3434
<script>
35-
import { useEditorMixin, useSyncServiceMixin } from './Editor.provider.js'
35+
import {
36+
useEditorMixin,
37+
useIsRichEditorMixin,
38+
useSyncServiceMixin
39+
} from './Editor.provider.js'
3640
import { NcButton } from '@nextcloud/vue'
37-
import markdownit from './../markdownit/index.js'
41+
import setContent from './../mixins/setContent.js'
3842
export default {
3943
name: 'CollisionResolveDialog',
4044
components: {
4145
NcButton,
4246
},
4347
mixins: [
4448
useEditorMixin,
49+
useIsRichEditorMixin,
50+
setContent,
4551
useSyncServiceMixin,
4652
],
4753
props: {
@@ -62,10 +68,10 @@ export default {
6268
this.$editor.setOptions({ editable: !this.readOnly })
6369
},
6470
resolveServerVersion() {
71+
const { outsideChange } = this.syncError.data
6572
this.clicked = true
66-
const markdownItHtml = markdownit.render(this.syncError.data.outsideChange)
6773
this.$editor.setOptions({ editable: !this.readOnly })
68-
this.$editor.commands.setContent(markdownItHtml)
74+
this.setContent(outsideChange, { isRich: this.$isRichEditor })
6975
this.$syncService.forceSave().then(() => this.$syncService.syncUp())
7076
},
7177
},

src/components/Editor.vue

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
<script>
7979
import Vue, { set } from 'vue'
8080
import { mapActions, mapState } from 'vuex'
81-
import escapeHtml from 'escape-html'
8281
import { getCurrentUser } from '@nextcloud/auth'
8382
import { loadState } from '@nextcloud/initial-state'
8483
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
@@ -111,6 +110,7 @@ import markdownit from './../markdownit/index.js'
111110
import { Keymap } from './../extensions/index.js'
112111
import DocumentStatus from './Editor/DocumentStatus.vue'
113112
import isMobile from './../mixins/isMobile.js'
113+
import setContent from './../mixins/setContent.js'
114114
import store from './../mixins/store.js'
115115
import MenuBar from './Menu/MenuBar.vue'
116116
import ContentContainer from './Editor/ContentContainer.vue'
@@ -132,6 +132,7 @@ export default {
132132
},
133133
mixins: [
134134
isMobile,
135+
setContent,
135136
store,
136137
],
137138
provide() {
@@ -339,23 +340,6 @@ export default {
339340
'setCurrentSession',
340341
]),
341342
342-
setContent(content, { addToHistory = true } = {}) {
343-
this.$editor.chain()
344-
.setContent(this.parseContent(content), addToHistory)
345-
.command(({ tr }) => {
346-
tr.setMeta('addToHistory', addToHistory)
347-
return true
348-
})
349-
.run()
350-
351-
},
352-
353-
parseContent(documentSource) {
354-
return !this.isRichEditor
355-
? `<pre>${escapeHtml(documentSource)}</pre>`
356-
: markdownit.render(documentSource) + '<p/>'
357-
},
358-
359343
initSession() {
360344
if (!this.hasDocumentParameters) {
361345
this.emit('error', 'No valid file provided')
@@ -536,7 +520,10 @@ export default {
536520
})
537521
this.hasEditor = true
538522
if (!documentState && documentSource) {
539-
this.setContent(documentSource, { addToHistory: false })
523+
this.setContent(documentSource, {
524+
isRich: this.isRichEditor,
525+
addToHistory: false
526+
})
540527
}
541528
this.listenEditorEvents()
542529
} else {

src/extensions/PlainText.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { Extension } from '@tiptap/core'
2424

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

@@ -33,6 +34,7 @@ export default Extension.create({
3334
return [
3435
PlainTextDocument,
3536
Text,
37+
CodeBlock,
3638
]
3739
},
3840

src/mixins/setContent.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @copyright Copyright (c) 2023 Max <[email protected]>
3+
*
4+
* @author Max <[email protected]>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import escapeHtml from 'escape-html'
24+
import markdownit from './../markdownit/index.js'
25+
26+
export default {
27+
methods: {
28+
setContent(content, { isRich, addToHistory = true } = {}) {
29+
const html = isRich
30+
? markdownit.render(content) + '<p/>'
31+
: `<pre>${escapeHtml(content)}</pre>`
32+
this.$editor.chain()
33+
.setContent(html, addToHistory)
34+
.command(({ tr }) => {
35+
tr.setMeta('addToHistory', addToHistory)
36+
return true
37+
})
38+
.run()
39+
},
40+
41+
},
42+
}

0 commit comments

Comments
 (0)