Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 962ecab

Browse files
probilMax Lyashuk
authored and
Max Lyashuk
committed
feat(editor): implement full-screen mode for code editor
1 parent 5cfb0e9 commit 962ecab

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed
+14-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
<div id="editor" :style="{width: width ? px(width) : '100%'}"></div>
1+
<div class="editor" :class="{'editor--fullscreen': fullScreen}">
2+
<div id="editor" ref="editor" :style="editorStyle"></div>
3+
<a
4+
href="#"
5+
class="editor__fullscreen-toggle"
6+
@click="toggleFullscreen"
7+
v-if="!readOnly"
8+
title="Toggle fullscreen mode"
9+
>
10+
<b-icon
11+
:icon="fullScreen ? 'compress': 'expand'"
12+
></b-icon>
13+
</a>
14+
</div>
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.editor {
2+
position: relative;
3+
4+
&--fullscreen {
5+
position: fixed;
6+
top: 0;
7+
right: 0;
8+
left: 0;
9+
bottom: 0;
10+
width: 100vw;
11+
height: 100vh;
12+
z-index: 10;
13+
}
14+
15+
&__fullscreen-toggle {
16+
position: absolute;
17+
top: 4px;
18+
right: 4px;
19+
z-index: 1;
20+
color: whitesmoke;
21+
}
22+
&__fullscreen-toggle:hover {
23+
color: #bbb;
24+
}
25+
}

src/renderer/components/editor/Editor.vue

+23-2
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,39 @@ export default {
1616
height: true,
1717
width: true,
1818
readOnly: Boolean,
19+
autoGrow: Boolean,
1920
},
2021
data() {
2122
return {
2223
editor: null,
2324
contentBackup: '',
25+
fullScreen: false,
2426
};
2527
},
28+
computed: {
29+
editorHeight() {
30+
if (this.autoGrow && !this.fullScreen) return undefined;
31+
if (this.height && !this.fullScreen) return this.px(this.height);
32+
return '100%'
33+
},
34+
editorStyle() {
35+
return {
36+
width: this.width && !this.fullScreen ? this.px(this.width) : '100%',
37+
height: this.editorHeight,
38+
}
39+
},
40+
},
2641
methods: {
2742
px(n) {
2843
if (/^\d*$/.test(n)) {
2944
return `${n}px`;
3045
}
3146
return n;
3247
},
48+
toggleFullscreen() {
49+
this.fullScreen = !this.fullScreen;
50+
this.editor.resize();
51+
}
3352
},
3453
watch: {
3554
value(val) {
@@ -49,7 +68,7 @@ export default {
4968
5069
require('brace/ext/emmet');
5170
52-
const editor = (vm.editor = ace.edit(this.$el));
71+
const editor = (vm.editor = ace.edit(this.$refs.editor));
5372
5473
this.$emit('init', editor);
5574
@@ -61,12 +80,14 @@ export default {
6180
editor.setShowPrintMargin(false);
6281
6382
if (!this.readOnly) {
64-
editor.setOption('minLines', 15);
6583
editor.setValue(this.value, 1);
6684
} else {
6785
editor.setValue(this.code, 1);
6886
}
6987
editor.setReadOnly(this.readOnly);
88+
if(this.autoGrow) {
89+
editor.setOption('maxLines', Infinity);
90+
}
7091
7192
editor.on('change', () => {
7293
const content = editor.getValue();

src/renderer/components/modals/create-note-modal/CreateNoteModal.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated
6969
:lang="file.language"
7070
theme="monokai"
7171
width="100%"
72-
height="260"
72+
height="220"
7373
></editor>
7474
</b-field>
7575
</div>

src/renderer/components/notes-list/note-card/NoteCard.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h4>{{value.name}}
4646
:lang="value.language"
4747
theme="monokai"
4848
width="100%"
49-
height="260"
49+
:auto-grow="true"
5050
:readOnly="true"
5151
></editor>
5252
</div>

0 commit comments

Comments
 (0)