Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(debug): Expose yjs debug function in editor API #6598

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,22 @@ export default {
console.debug(editor.getHTML())
},

/**
* Helper method to debug yjs issues
*/
debugYjs() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have this somewhat accessible when text open in viewer so we can also ask people editing to dump the output when editing outside of collectives?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a bit complicated to expose this, as we don't know how many editor instances are instantiated in the browser. We could create an array OCA.Text.editors and add each editor along with the debugYjs function as a new item. This should probably be done in Editor.vue, as all editors that use a session and Yjs are created from here to my knowledge. I don't see any value in exposing the non-session editors from MarkdownContentEditor.vue and BaseReader.vue. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an array of editors sounds reasonable. We can add the filename maybe to the debug output so that the individual ones can be identified (e.g. a readme is open and a viewer instance).

I think we don't need to make it too complex, as long as we can somehow get the information and identify the relevant instance.

const yjsData = {
clientId: this.$ydoc.clientID,
pendingStructs: this.$ydoc.store.pendingStructs,
clientVectors: [],
documentState: this.$syncService.getDocumentState(),
}
for (const client of this.$ydoc.store.clients.values()) {
yjsData.clientVectors.push(client.at(-1).id)
}
console.debug('Yjs data', JSON.stringify(yjsData))
},

outlineToggled(visible) {
this.emit('outline-toggled', visible)
},
Expand Down
4 changes: 4 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ class TextEditorEmbed {
this.#getEditorComponent().$editor.commands.focus()
}

debugYjs() {
this.#getEditorComponent().debugYjs()
}

#registerDebug() {
if (window?._oc_debug) {
this.vm = this.#vm
Expand Down
Loading