From 7bb71490497d1bd432ef6439b672ca2c44bcb926 Mon Sep 17 00:00:00 2001 From: Luna-Klatzer Date: Sun, 2 Jun 2024 12:58:57 +0200 Subject: [PATCH 1/3] fix (#146): Fixed editor content display bug in Chrome Fix for version `0.7.0-dev`. --- .../frontend/src/scripts/editor/editor.ts | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/solardoc/frontend/src/scripts/editor/editor.ts b/solardoc/frontend/src/scripts/editor/editor.ts index 63142d61..3bc5d788 100644 --- a/solardoc/frontend/src/scripts/editor/editor.ts +++ b/solardoc/frontend/src/scripts/editor/editor.ts @@ -21,6 +21,7 @@ import {createOTUpdates} from '@/scripts/editor/ot/create-ot' import {getMonacoUpdatesFromOT} from '@/scripts/editor/ot/get-monaco-updates' import {sendOTUpdates} from '@/scripts/editor/ot/send-ot' import {EditorModelNotFoundError} from "@/errors/editor-model-not-found-error"; +import {Selection, SelectionDirection} from "monaco-editor"; const currentFileStore = useCurrentFileStore() const currentUserStore = useCurrentUserStore() @@ -107,7 +108,7 @@ export class SolardocEditor { globalMonacoEditor! = monaco.editor.create(elementToBindTo.value, { theme: initialState.darkMode ? 'asciiDocDarkTheme' : 'asciiDocLightTheme', language: 'asciiDoc', - value: initialState.content, + value: undefined, fontFamily: 'JetBrains Mono', minimap: { enabled: false, @@ -116,6 +117,8 @@ export class SolardocEditor { automaticLayout: true, scrollBeyondLastLine: false, }) + // We need to set the content after the editor is created due to a weird bug in Monaco (See #146) + this._applyInitContent(`${initialState.content}` || '') this._locked = false this._readonly = false @@ -164,6 +167,10 @@ export class SolardocEditor { globalMonacoEditor!.setValue(content) } + private static forceRerender() { + globalMonacoEditor!.render() + } + /** * @since 0.7.0 */ @@ -186,10 +193,10 @@ export class SolardocEditor { } else if (oTrans.init) { // The init transformation should not be applied and only the init content should be set //await this.runThreadSafe(async () => model.setValue(currentFileStore.content)) - await this.runThreadSafe(async () => globalMonacoEditor!.setValue(currentFileStore.content)) + await this._runThreadSafe(async () => globalMonacoEditor!.setValue(currentFileStore.content)) return } else { - await this.runThreadSafe(async () => { + await this._runThreadSafe(async () => { const edits: Array = getMonacoUpdatesFromOT(editorModel, oTrans) globalMonacoEditor!.executeEdits(this.name, edits) }) @@ -218,11 +225,11 @@ export class SolardocEditor { }) } - private static lock() { + private static _lock() { this._locked = true } - private static unlock() { + private static _unlock() { this._locked = false } @@ -232,20 +239,20 @@ export class SolardocEditor { * @param promise The promise to run * @private */ - private static async runThreadSafe(promise: () => Promise): Promise { + private static async _runThreadSafe(promise: () => Promise): Promise { if (this.isLocked) { - await this.waitForUnlock() + await this._waitForUnlock() } - this.lock() + this._lock() await promise() - this.unlock() + this._unlock() } /** * Returns a promise which resolves when the editor is unlocked. * @private */ - private static waitForUnlock(): Promise { + private static _waitForUnlock(): Promise { return new Promise(resolve => { const interval = setInterval(() => { if (!this.isLocked) { @@ -255,4 +262,28 @@ export class SolardocEditor { }, 100) }) } + + /** + * Applies the initial content to the editor. This is used to set the initial content of the editor when it is + * created. + * + * This is required due to bug #146 in Monaco, where setting the content in the editor creation options does not work. + * @param content The content to set. + * @private + */ + private static _applyInitContent(content: string) { + const model = globalMonacoEditor!.getModel()!.getFullModelRange() + globalMonacoEditor!.executeEdits( + this.name, + [{ + range: model, + text: content, + }] satisfies Array, + ) + + document.fonts.ready.then(() => { + monaco.editor.remeasureFonts() + this.forceRerender() + }) + } } From ff9418b459a6dbb8e0bacf62cffafec9af62bca6 Mon Sep 17 00:00:00 2001 From: Luna-Klatzer Date: Sun, 2 Jun 2024 13:18:38 +0200 Subject: [PATCH 2/3] fix (#146): Removed unneeded `executeEdits` in `SolardocEditor._applyInitContent` --- solardoc/frontend/src/scripts/editor/editor.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/solardoc/frontend/src/scripts/editor/editor.ts b/solardoc/frontend/src/scripts/editor/editor.ts index 3bc5d788..b889e58b 100644 --- a/solardoc/frontend/src/scripts/editor/editor.ts +++ b/solardoc/frontend/src/scripts/editor/editor.ts @@ -272,15 +272,7 @@ export class SolardocEditor { * @private */ private static _applyInitContent(content: string) { - const model = globalMonacoEditor!.getModel()!.getFullModelRange() - globalMonacoEditor!.executeEdits( - this.name, - [{ - range: model, - text: content, - }] satisfies Array, - ) - + globalMonacoEditor!.setValue(content) document.fonts.ready.then(() => { monaco.editor.remeasureFonts() this.forceRerender() From 9f2d33b2d0dbf9c471bbdf344fc521daecef551e Mon Sep 17 00:00:00 2001 From: Luna-Klatzer Date: Sun, 2 Jun 2024 13:22:37 +0200 Subject: [PATCH 3/3] other: Prettified code and optimised imports --- solardoc/frontend/src/App.vue | 6 +-- .../src/components/Auth-Status-Modal.vue | 2 +- .../src/components/FullScreenPreview.vue | 8 ++-- .../src/components/LoadAnywayButton.vue | 8 ++-- solardoc/frontend/src/components/Navbar.vue | 2 +- .../src/components/ProgressSpinner.vue | 2 +- .../frontend/src/components/SDRouterLink.vue | 2 +- .../frontend/src/components/editor/Editor.vue | 14 +++---- .../editor/channel-view/ChannelView.vue | 14 +++---- .../editor/channel-view/ChannelViewCreate.vue | 24 ++++++----- .../channel-view/ChannelViewCurrent.vue | 14 +++---- .../channel-view/ChannelViewElement.vue | 8 ++-- .../channel-view/ChannelViewJoinConfirm.vue | 22 +++++----- .../dropdown/EditorSandwichDropdown.vue | 22 +++++----- .../editor/share-url/ShareUrlCreate.vue | 14 +++---- .../profile-view/file-view/FileCard.vue | 16 ++++---- .../profile-view/file-view/FilesList.vue | 12 +++--- .../profile-view/file-view/SearchBar.vue | 4 +- .../profile-view/header/ProfileHeader.vue | 2 +- .../header/ProfileViewHeaderButtons.vue | 10 ++--- .../slides-navigator/SlidePreview.vue | 8 ++-- .../slides-navigator/SlidesNavigator.vue | 12 +++--- .../SlideSubSlidePreview.vue | 8 ++-- .../SlideSubSlidesPreview.vue | 4 +- .../SubSlidesNavigator.vue | 12 +++--- .../errors/editor-element-not-found-error.ts | 2 +- .../errors/editor-model-not-found-error.ts | 2 +- .../src/errors/handler/error-handler.ts | 4 +- .../frontend/src/errors/not-logged-in-warn.ts | 2 +- .../frontend/src/errors/unreachable-error.ts | 2 +- solardoc/frontend/src/main.ts | 6 +-- solardoc/frontend/src/router/index.ts | 6 +-- .../frontend/src/scripts/editor/editor.ts | 40 ++++++++++--------- .../heading-space-missing-error.ts | 2 +- .../error-checkers/list-inconsistent-error.ts | 2 +- .../src/scripts/editor/error-checking.ts | 6 +-- .../editor/monaco-config/dark-editor-theme.ts | 2 +- .../src/scripts/editor/ot/create-ot.ts | 6 +-- .../scripts/editor/ot/get-monaco-updates.ts | 4 +- .../frontend/src/scripts/editor/ot/send-ot.ts | 4 +- .../frontend/src/scripts/editor/render.ts | 10 ++--- .../frontend/src/scripts/ensure-logged-in.ts | 6 +-- .../frontend/src/scripts/handle-render.ts | 10 ++--- .../src/scripts/show-dummy-loading.ts | 2 +- solardoc/frontend/src/scripts/show-notif.ts | 4 +- solardoc/frontend/src/scripts/show-welcome.ts | 4 +- .../src/services/phoenix/api-service.ts | 4 +- .../frontend/src/services/phoenix/config.ts | 2 +- .../src/services/phoenix/editor-channel.ts | 5 ++- .../frontend/src/services/phoenix/errors.ts | 4 +- .../frontend/src/services/phoenix/ot-trans.ts | 6 +-- .../src/services/phoenix/ws-client.ts | 8 ++-- .../src/services/render/api-service.ts | 4 +- .../frontend/src/services/render/errors.ts | 2 +- solardoc/frontend/src/stores/channel-view.ts | 6 +-- solardoc/frontend/src/stores/current-file.ts | 6 +-- solardoc/frontend/src/stores/current-user.ts | 4 +- solardoc/frontend/src/stores/dark-mode.ts | 2 +- .../src/stores/editor-update-ws-client.ts | 4 +- solardoc/frontend/src/stores/init-state.ts | 2 +- solardoc/frontend/src/stores/last-modified.ts | 2 +- solardoc/frontend/src/stores/loading.ts | 2 +- solardoc/frontend/src/stores/overlay-state.ts | 2 +- .../frontend/src/stores/preview-loading.ts | 2 +- .../src/stores/preview-menu-slide-state.ts | 2 +- .../src/stores/preview-selected-slide.ts | 2 +- solardoc/frontend/src/stores/render-data.ts | 4 +- solardoc/frontend/src/stores/welcome.ts | 2 +- solardoc/frontend/src/views/EditorView.vue | 34 ++++++++-------- solardoc/frontend/src/views/HomeView.vue | 4 +- solardoc/frontend/src/views/LoginView.vue | 10 ++--- solardoc/frontend/src/views/ProfileView.vue | 4 +- solardoc/frontend/src/views/ShareURLView.vue | 12 +++--- solardoc/frontend/src/views/SignupView.vue | 12 +++--- 74 files changed, 269 insertions(+), 260 deletions(-) diff --git a/solardoc/frontend/src/App.vue b/solardoc/frontend/src/App.vue index 334b2733..bec083b7 100644 --- a/solardoc/frontend/src/App.vue +++ b/solardoc/frontend/src/App.vue @@ -1,7 +1,7 @@ diff --git a/solardoc/frontend/src/components/ProgressSpinner.vue b/solardoc/frontend/src/components/ProgressSpinner.vue index 78211f1b..9faa16cc 100644 --- a/solardoc/frontend/src/components/ProgressSpinner.vue +++ b/solardoc/frontend/src/components/ProgressSpinner.vue @@ -1,5 +1,5 @@ diff --git a/solardoc/frontend/src/components/SDRouterLink.vue b/solardoc/frontend/src/components/SDRouterLink.vue index ad218b2c..14fcb625 100644 --- a/solardoc/frontend/src/components/SDRouterLink.vue +++ b/solardoc/frontend/src/components/SDRouterLink.vue @@ -1,5 +1,5 @@ diff --git a/solardoc/frontend/src/components/profile-view/header/ProfileViewHeaderButtons.vue b/solardoc/frontend/src/components/profile-view/header/ProfileViewHeaderButtons.vue index 2ea85a14..6436e7a1 100644 --- a/solardoc/frontend/src/components/profile-view/header/ProfileViewHeaderButtons.vue +++ b/solardoc/frontend/src/components/profile-view/header/ProfileViewHeaderButtons.vue @@ -1,10 +1,10 @@