Skip to content

Commit fb0938c

Browse files
committed
Add per user setting for text editor max width
Signed-off-by: Azri Adam <[email protected]>
1 parent 3948a67 commit fb0938c

File tree

6 files changed

+320
-253
lines changed

6 files changed

+320
-253
lines changed

lib/Controller/SettingsController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
class SettingsController extends Controller {
1818
public const ACCEPTED_KEYS = [
19-
'workspace_enabled'
19+
'workspace_enabled',
20+
'is_full_width_editor'
2021
];
2122

2223
public function __construct(
@@ -31,7 +32,7 @@ public function __construct(
3132
/**
3233
* @throws \OCP\PreConditionNotMetException
3334
*
34-
* @psalm-return DataResponse<200|400, array{workspace_enabled?: mixed, message?: 'Invalid config key'}, array<never, never>>
35+
* @psalm-return DataResponse<200|400, array{workspace_enabled?: mixed, is_full_width_editor?: mixed, message?: 'Invalid config key'}, array<never, never>>
3536
*/
3637
#[NoAdminRequired]
3738
public function updateConfig(string $key, int|string $value): DataResponse {

lib/Service/ConfigService.php

+4
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ public function isNotifyPushSyncEnabled(): bool {
4444
return $this->appConfig->getValueBool(Application::APP_NAME, 'notify_push');
4545

4646
}
47+
48+
public function isFullWidthEditor(?string $userId): bool {
49+
return $this->config->getUserValue($userId, Application::APP_NAME, 'is_full_width_editor', '0') === '1';
50+
}
4751
}

lib/Service/InitialStateProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function provideState(): void {
7777
'notify_push',
7878
$this->configService->isNotifyPushSyncEnabled(),
7979
);
80+
81+
$this->initialState->provideInitialState(
82+
'is_full_width_editor',
83+
$this->configService->isFullWidthEditor($this->userId),
84+
);
8085
}
8186

8287
public function provideFileId(int $fileId): void {

src/components/Editor.vue

+83-60
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
:dirty="dirty"
4949
:sessions="filteredSessions"
5050
:sync-error="syncError"
51-
:has-connection-issue="hasConnectionIssue" />
51+
:has-connection-issue="hasConnectionIssue"
52+
@editor-width-change="handleEditorWidthChange" />
5253
<slot name="header" />
5354
</MenuBar>
5455
<div v-else class="menubar-placeholder" />
@@ -321,13 +322,22 @@ export default {
321322
},
322323
}
323324
},
325+
editorMaxWidth() {
326+
return loadState('text', 'is_full_width_editor', false) ? '100%' : '80ch'
327+
},
324328
},
325329
watch: {
326330
displayed() {
327331
this.$nextTick(() => {
328332
this.contentWrapper = this.$refs.contentWrapper
329333
})
330334
},
335+
editorMaxWidth: {
336+
immediate: true,
337+
handler(newWidth) {
338+
this.updateEditorWidth(newWidth)
339+
},
340+
},
331341
},
332342
mounted() {
333343
if (this.active && (this.hasDocumentParameters)) {
@@ -860,6 +870,19 @@ export default {
860870
})
861871
this.translateModal = false
862872
},
873+
874+
handleEditorWidthChange(newWidth) {
875+
this.updateEditorWidth(newWidth)
876+
this.$nextTick(() => {
877+
if (this.$editor) {
878+
this.$editor.view.updateState(this.$editor.view.state)
879+
this.$editor.commands.focus()
880+
}
881+
})
882+
},
883+
updateEditorWidth(newWidth) {
884+
document.documentElement.style.setProperty('--text-editor-max-width', newWidth)
885+
},
863886
},
864887
}
865888
</script>
@@ -931,75 +954,75 @@ export default {
931954
</style>
932955

933956
<style lang="scss">
934-
@import './../css/variables';
935-
@import './../css/style';
936-
@import './../css/print';
957+
@import './../css/variables';
958+
@import './../css/style';
959+
@import './../css/print';
937960

938-
.text-editor__wrapper {
939-
@import './../css/prosemirror';
961+
.text-editor__wrapper {
962+
@import './../css/prosemirror';
940963

941-
// relative position for the alignment of the menububble
942-
.text-editor__main {
943-
&.draggedOver {
944-
background-color: var(--color-primary-element-light);
945-
}
946-
.text-editor__content-wrapper {
947-
position: relative;
948-
}
964+
// relative position for the alignment of the menububble
965+
.text-editor__main {
966+
&.draggedOver {
967+
background-color: var(--color-primary-element-light);
968+
}
969+
.text-editor__content-wrapper {
970+
position: relative;
949971
}
950972
}
973+
}
951974

952-
.text-editor__wrapper.has-conflicts > .editor {
953-
width: 50%;
954-
}
975+
.text-editor__wrapper.has-conflicts > .editor {
976+
width: 50%;
977+
}
955978

956-
.text-editor__wrapper.has-conflicts > .content-wrapper {
957-
width: 50%;
958-
#read-only-editor {
959-
margin: 0px auto;
960-
padding-top: 50px;
961-
overflow: initial;
962-
}
979+
.text-editor__wrapper.has-conflicts > .content-wrapper {
980+
width: 50%;
981+
#read-only-editor {
982+
margin: 0px auto;
983+
padding-top: 50px;
984+
overflow: initial;
963985
}
986+
}
964987

965-
@keyframes spin {
966-
0% { transform: rotate(0deg); }
967-
100% { transform: rotate(360deg); }
968-
}
988+
@keyframes spin {
989+
0% { transform: rotate(0deg); }
990+
100% { transform: rotate(360deg); }
991+
}
969992

970-
/* Give a remote user a caret */
971-
.collaboration-cursor__caret {
972-
position: relative;
973-
margin-left: -1px;
974-
margin-right: -1px;
975-
border-left: 1px solid #0D0D0D;
976-
border-right: 1px solid #0D0D0D;
977-
word-break: normal;
978-
pointer-events: none;
979-
}
993+
/* Give a remote user a caret */
994+
.collaboration-cursor__caret {
995+
position: relative;
996+
margin-left: -1px;
997+
margin-right: -1px;
998+
border-left: 1px solid #0D0D0D;
999+
border-right: 1px solid #0D0D0D;
1000+
word-break: normal;
1001+
pointer-events: none;
1002+
}
9801003

981-
/* Render the username above the caret */
982-
.collaboration-cursor__label {
983-
position: absolute;
984-
top: -1.4em;
985-
left: -1px;
986-
font-size: 12px;
987-
font-style: normal;
988-
font-weight: 600;
989-
line-height: normal;
990-
user-select: none;
991-
color: #0D0D0D;
992-
padding: 0.1rem 0.3rem;
993-
border-radius: 3px 3px 3px 0;
994-
white-space: nowrap;
995-
opacity: 0;
996-
997-
&.collaboration-cursor__label__active {
998-
opacity: 1;
999-
}
1004+
/* Render the username above the caret */
1005+
.collaboration-cursor__label {
1006+
position: absolute;
1007+
top: -1.4em;
1008+
left: -1px;
1009+
font-size: 12px;
1010+
font-style: normal;
1011+
font-weight: 600;
1012+
line-height: normal;
1013+
user-select: none;
1014+
color: #0D0D0D;
1015+
padding: 0.1rem 0.3rem;
1016+
border-radius: 3px 3px 3px 0;
1017+
white-space: nowrap;
1018+
opacity: 0;
10001019

1001-
&:not(.collaboration-cursor__label__active) {
1002-
transition: opacity 0.2s 5s;
1003-
}
1020+
&.collaboration-cursor__label__active {
1021+
opacity: 1;
10041022
}
1023+
1024+
&:not(.collaboration-cursor__label__active) {
1025+
transition: opacity 0.2s 5s;
1026+
}
1027+
}
10051028
</style>

0 commit comments

Comments
 (0)