Skip to content

Commit c36e12a

Browse files
Merge pull request #7514 from nextcloud/fix/move-wide-page-toggle
fix/move wide page toggle
2 parents 90d6bd8 + 2050ce8 commit c36e12a

File tree

15 files changed

+336
-138
lines changed

15 files changed

+336
-138
lines changed

cypress/e2e/MenuBar.spec.js

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { initUserAndFiles, randUser } from '../utils/index.js'
6+
import { randUser } from '../utils/index.js'
77

88
const user = randUser()
9-
const fileName = 'empty.md'
109

1110
describe('Test the rich text editor menu bar', function () {
12-
before(() => initUserAndFiles(user, fileName))
11+
before(function () {
12+
cy.createUser(user)
13+
})
1314

1415
beforeEach(function () {
1516
cy.login(user)
16-
cy.visit('/apps/files', {
17-
onBeforeLoad(win) {
18-
cy.stub(win, 'open').as('winOpen')
19-
},
20-
})
21-
22-
cy.openFile(fileName)
17+
cy.uploadTestFile()
2318
})
2419

2520
describe('word count', function () {
@@ -32,30 +27,78 @@ describe('Test the rich text editor menu bar', function () {
3227
.get('[data-text-action-entry="character-count"]')
3328
}
3429

35-
beforeEach(cy.clearContent)
30+
beforeEach(function () {
31+
cy.visit('/apps/files')
32+
cy.openTestFile()
33+
})
34+
3635
it('empty file', () => {
37-
cy.getFile(fileName).then(($el) => {
38-
cy.getActionEntry('remain').click()
39-
getWordCount().should('include.text', '0 words, 0 chars')
40-
})
36+
cy.getContent()
37+
cy.getActionEntry('remain').click()
38+
getWordCount().should('include.text', '0 words, 0 chars')
4139
})
4240

4341
it('single word', () => {
44-
cy.getFile(fileName).then(($el) => {
45-
cy.clearContent()
46-
cy.getContent().type(' Hello ')
47-
cy.getActionEntry('remain').click()
48-
getWordCount().should('include.text', '1 word, 9 chars')
49-
})
42+
cy.getContent().type(' Hello ')
43+
cy.getActionEntry('remain').click()
44+
getWordCount().should('include.text', '1 word, 9 chars')
5045
})
5146

5247
it('multiple words', () => {
53-
cy.getFile(fileName).then(($el) => {
54-
cy.clearContent()
55-
cy.getContent().type('Hello \nworld')
56-
cy.getActionEntry('remain').click()
57-
getWordCount().should('include.text', '2 words, 11 chars')
58-
})
48+
cy.getContent().type('Hello \nworld')
49+
cy.getActionEntry('remain').click()
50+
getWordCount().should('include.text', '2 words, 11 chars')
51+
})
52+
})
53+
54+
describe('text width toggle', function () {
55+
beforeEach(() => {
56+
cy.configureText('is_full_width_editor', 0)
57+
cy.visit('/apps/files')
58+
cy.window()
59+
.its('document.documentElement.style')
60+
.invoke('getPropertyValue', '--text-editor-max-width')
61+
.as('maxWidth')
62+
})
63+
64+
it('applys default', function () {
65+
cy.openTestFile()
66+
cy.get('@maxWidth').should('equal', '80ch')
67+
})
68+
69+
it('toggles value', function () {
70+
cy.openTestFile()
71+
cy.getActionEntry('remain').click()
72+
cy.contains('Full width editor').click()
73+
cy.get('@maxWidth').should('equal', '100%')
74+
})
75+
76+
it('preserves on reopen', function () {
77+
cy.openTestFile()
78+
cy.getActionEntry('remain').click()
79+
cy.contains('Full width editor').click()
80+
cy.closeFile()
81+
cy.openTestFile()
82+
cy.get('@maxWidth').should('equal', '100%')
83+
})
84+
85+
it('preserves on reload', function () {
86+
cy.openTestFile()
87+
cy.getActionEntry('remain').click()
88+
cy.contains('Full width editor').click()
89+
cy.visit('/apps/files')
90+
cy.openTestFile()
91+
cy.get('@maxWidth').should('equal', '100%')
92+
})
93+
94+
it('does not interfere if width is already set', function () {
95+
cy.window()
96+
.its('document.body.style')
97+
.invoke('setProperty', '--text-editor-max-width', '987px')
98+
cy.openTestFile()
99+
cy.getActionEntry('remain').click()
100+
cy.contains('Full width editor').should('not.exist')
101+
cy.get('@maxWidth').should('equal', '')
59102
})
60103
})
61104
})

src/components/Editor.vue

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
:dirty="dirty"
5151
:sessions="filteredSessions"
5252
:sync-error="syncError"
53-
:has-connection-issue="requireReconnect"
54-
@editor-width-change="handleEditorWidthChange" />
53+
:has-connection-issue="requireReconnect" />
5554
<slot name="header" />
5655
</MenuBar>
5756
<div v-else class="menubar-placeholder" />
@@ -84,7 +83,6 @@
8483
import { getCurrentUser } from '@nextcloud/auth'
8584
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
8685
import { File } from '@nextcloud/files'
87-
import { loadState } from '@nextcloud/initial-state'
8886
import { Collaboration } from '@tiptap/extension-collaboration'
8987
import { useElementSize } from '@vueuse/core'
9088
import Vue, { defineComponent, ref, set, shallowRef, watch } from 'vue'
@@ -101,6 +99,7 @@ import { generateRemoteUrl } from '@nextcloud/router'
10199
import { Awareness } from 'y-protocols/awareness.js'
102100
import { provideConnection } from '../composables/useConnection.ts'
103101
import { useEditorMethods } from '../composables/useEditorMethods.ts'
102+
import { provideEditorWidth } from '../composables/useEditorWidth.ts'
104103
import { provideSaveService } from '../composables/useSaveService.ts'
105104
import { provideSyncService } from '../composables/useSyncService.ts'
106105
import { useSyntaxHighlighting } from '../composables/useSyntaxHighlighting.ts'
@@ -257,6 +256,9 @@ export default defineComponent({
257256
: createPlainEditor({ language, extensions })
258257
provideEditor(editor)
259258
259+
const { applyEditorWidth } = provideEditorWidth()
260+
applyEditorWidth()
261+
260262
const { setEditable } = useEditorMethods(editor)
261263
262264
const serialize = isRichEditor
@@ -371,22 +373,13 @@ export default defineComponent({
371373
},
372374
}
373375
},
374-
editorMaxWidth() {
375-
return loadState('text', 'is_full_width_editor', false) ? '100%' : '80ch'
376-
},
377376
},
378377
watch: {
379378
displayed() {
380379
this.$nextTick(() => {
381380
this.contentWrapper = this.$refs.contentWrapper
382381
})
383382
},
384-
editorMaxWidth: {
385-
immediate: true,
386-
handler(newWidth) {
387-
this.updateEditorWidth(newWidth)
388-
},
389-
},
390383
dirty(val) {
391384
if (val) {
392385
window.addEventListener('beforeunload', this.saveBeforeUnload)
@@ -875,20 +868,6 @@ export default defineComponent({
875868
this.translateModal = false
876869
},
877870
878-
handleEditorWidthChange(newWidth) {
879-
this.updateEditorWidth(newWidth)
880-
this.$nextTick(() => {
881-
this.editor.view.updateState(this.editor.view.state)
882-
this.editor.commands.focus()
883-
})
884-
},
885-
updateEditorWidth(newWidth) {
886-
document.documentElement.style.setProperty(
887-
'--text-editor-max-width',
888-
newWidth,
889-
)
890-
},
891-
892871
saveBeforeUnload() {
893872
this.saveService.saveViaSendBeacon()
894873
},
@@ -976,7 +955,6 @@ export default defineComponent({
976955
</style>
977956
978957
<style lang="scss">
979-
@import './../css/variables';
980958
@import './../css/style';
981959
@import './../css/print';
982960

src/components/Editor/SessionList.vue

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
-->
55

66
<template>
7-
<NcPopover class="session-list" placement="bottom">
7+
<NcPopover
8+
:no-focus-trap="!$slots.default"
9+
class="session-list"
10+
placement="bottom">
811
<template #trigger="{ attrs }">
912
<div>
1013
<NcButton
@@ -47,26 +50,15 @@
4750
>({{ t('text', 'guest') }})</span
4851
>
4952
</li>
50-
<li>
51-
<NcCheckboxRadioSwitch
52-
:checked="isFullWidth"
53-
@update:checked="onWidthToggle">
54-
{{ t('text', 'Full width editor') }}
55-
</NcCheckboxRadioSwitch>
56-
</li>
5753
</ul>
5854
</div>
5955
</template>
6056
</NcPopover>
6157
</template>
6258

6359
<script>
64-
import axios from '@nextcloud/axios'
65-
import { loadState } from '@nextcloud/initial-state'
6660
import { t } from '@nextcloud/l10n'
67-
import { generateUrl } from '@nextcloud/router'
6861
import NcButton from '@nextcloud/vue/components/NcButton'
69-
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
7062
import NcPopover from '@nextcloud/vue/components/NcPopover'
7163
import AccountMultipleOutlineIcon from 'vue-material-design-icons/AccountMultipleOutline.vue'
7264
import {
@@ -82,7 +74,6 @@ export default {
8274
AvatarWrapper,
8375
NcButton,
8476
NcPopover,
85-
NcCheckboxRadioSwitch,
8677
},
8778
props: {
8879
sessions: {
@@ -93,10 +84,8 @@ export default {
9384
},
9485
},
9586
data() {
96-
const isFullWidth = loadState('text', 'is_full_width_editor', false)
9787
return {
9888
myName: '',
99-
isFullWidth,
10089
}
10190
},
10291
computed: {
@@ -141,15 +130,6 @@ export default {
141130
},
142131
},
143132
methods: {
144-
onWidthToggle(checked) {
145-
this.isFullWidth = checked
146-
this.$emit('editor-width-change', checked ? '100%' : '80ch')
147-
148-
axios.post(generateUrl('/apps/text/settings'), {
149-
key: 'is_full_width_editor',
150-
value: checked ? '1' : '0',
151-
})
152-
},
153133
t,
154134
},
155135
}

src/components/Editor/Status.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</template>
2121
</NcButton>
2222
</div>
23-
<SessionList :sessions="sessions" @editor-width-change="onEditorWidthChange">
23+
<SessionList :sessions="sessions">
2424
<p slot="lastSaved" class="last-saved">
2525
{{ t('text', 'Last saved') }}: {{ lastSavedString }}
2626
</p>
@@ -145,9 +145,6 @@ export default {
145145
this.saveService.forceSave()
146146
}
147147
},
148-
onEditorWidthChange(newWidth) {
149-
this.$emit('editor-width-change', newWidth)
150-
},
151148
t,
152149
},
153150
}

src/components/Menu/MenuBar.vue

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,8 @@
5151
:force-enabled="true"
5252
@click="activeMenuEntry = 'remain'">
5353
<template #lastAction="{ visible }">
54-
<NcActionButton
55-
v-if="canTranslate"
56-
close-after-click
57-
@click="showTranslate">
58-
<template #icon>
59-
<TranslateVariant />
60-
</template>
61-
{{ t('text', 'Translate') }}
62-
</NcActionButton>
54+
<TranslateButton />
55+
<WidthToggle />
6356
<ActionFormattingHelp @click="showHelp" />
6457
<NcActionSeparator />
6558
<CharacterCount v-bind="{ visible }" />
@@ -73,9 +66,6 @@
7366
</template>
7467

7568
<script>
76-
import { emit } from '@nextcloud/event-bus'
77-
import { loadState } from '@nextcloud/initial-state'
78-
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
7969
import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
8070
import { useElementSize } from '@vueuse/core'
8171
import { ref } from 'vue'
@@ -85,14 +75,16 @@ import { useEditor } from '../../composables/useEditor.ts'
8575
import { useEditorFlags } from '../../composables/useEditorFlags.ts'
8676
import { useIsMobileMixin } from '../Editor.provider.ts'
8777
import HelpModal from '../HelpModal.vue'
88-
import { DotsHorizontal, TranslateVariant } from '../icons.js'
78+
import { DotsHorizontal } from '../icons.js'
8979
import ActionFormattingHelp from './ActionFormattingHelp.vue'
9080
import ActionList from './ActionList.vue'
9181
import ActionSingle from './ActionSingle.vue'
9282
import CharacterCount from './CharacterCount.vue'
9383
import { MenuEntries, ReadOnlyDoneEntries } from './entries.js'
9484
import { MENU_ID } from './MenuBar.provider.js'
9585
import ToolBarLogic from './ToolBarLogic.js'
86+
import TranslateButton from './TranslateButton.vue'
87+
import WidthToggle from './WidthToggle.vue'
9688
9789
export default {
9890
name: 'MenuBar',
@@ -102,9 +94,9 @@ export default {
10294
ActionSingle,
10395
HelpModal,
10496
NcActionSeparator,
105-
NcActionButton,
10697
CharacterCount,
107-
TranslateVariant,
98+
TranslateButton,
99+
WidthToggle,
108100
},
109101
extends: ToolBarLogic,
110102
mixins: [useIsMobileMixin],
@@ -146,8 +138,6 @@ export default {
146138
randomID: `menu-bar-${Math.ceil(Math.random() * 10000 + 500).toString(16)}`,
147139
displayHelp: false,
148140
isReady: false,
149-
canTranslate:
150-
loadState('text', 'translation_languages', []).from?.length > 0,
151141
resize: null,
152142
}
153143
},
@@ -230,22 +220,6 @@ export default {
230220
hideHelp() {
231221
this.displayHelp = false
232222
},
233-
showTranslate() {
234-
const {
235-
commands,
236-
view: { state },
237-
} = this.editor
238-
const { from, to } = state.selection
239-
let selectedText = state.doc.textBetween(from, to, ' ')
240-
241-
if (!selectedText.trim().length) {
242-
commands.selectAll()
243-
selectedText = state.doc.textContent
244-
}
245-
246-
console.debug('translation click', state.selection, selectedText)
247-
emit('text:translate-modal:show', { content: selectedText })
248-
},
249223
t,
250224
},
251225
}

0 commit comments

Comments
 (0)