Skip to content

Commit

Permalink
Merge pull request #4543 from nextcloud/backport/4540/stable26
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Jul 21, 2023
2 parents be918fd + c2467a1 commit 8bbf0a1
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/sync.spec.js
Expand Up @@ -40,7 +40,7 @@ describe('Sync', () => {
}).as('sync')
cy.openTestFile()
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().type('* Saving the doc saves the doc state{enter}')
cy.getContent().type('{moveToEnd}* Saving the doc saves the doc state{enter}')
})

it('saves the actual file and document state', () => {
Expand Down
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions js/editor.js.LICENSE.txt
Expand Up @@ -203,6 +203,27 @@
*
*/

/*
* @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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/>.
*/

/*
* @copyright Copyright (c) 2023 Max <max@nextcloud.com>
*
Expand Down
2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/components/Editor.vue
Expand Up @@ -83,6 +83,7 @@ import { loadState } from '@nextcloud/initial-state'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Collaboration } from '@tiptap/extension-collaboration'
import { CollaborationCursor } from '@tiptap/extension-collaboration-cursor'
import Autofocus from '../extensions/Autofocus.js'
import { Doc } from 'yjs'
import {
Expand Down Expand Up @@ -493,6 +494,9 @@ export default {
})
},
extensions: [
Autofocus.configure({
fileId: this.fileId,
}),
Collaboration.configure({
document: this.$ydoc,
}),
Expand Down Expand Up @@ -587,7 +591,7 @@ export default {
this.contentLoaded = true
if (this.autofocus && !this.readOnly) {
this.$nextTick(() => {
this.$editor.commands.focus()
this.$editor.commands.autofocus()
})
}
this.emit('ready')
Expand Down
61 changes: 61 additions & 0 deletions src/extensions/Autofocus.js
@@ -0,0 +1,61 @@
/*
* @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 { Extension } from '@tiptap/core'

export default Extension.create({
addOptions() {
return {
fileId: null,
}
},
addStorage() {
return {
started: false,
}
},
onCreate() {
if (this.options.fileId === null) {
throw new Error('fileId needs to be provided')
}
this.storage.started = true
},
onSelectionUpdate({ editor }) {
if (!this.storage.started) {
return
}

const pos = editor.state.selection.$anchor.pos
sessionStorage.setItem('text-lastPos-' + this.options.fileId, pos)
},
addCommands() {
return {
autofocus: () => ({ commands, editor }) => {
const pos = sessionStorage.getItem('text-lastPos-' + this.options.fileId)
if (pos) {
return commands.focus(pos)
}

return commands.focus('start')
},
}
},
})

0 comments on commit 8bbf0a1

Please sign in to comment.