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

Commit 0e110d9

Browse files
committed
feat(editor): implement full-screen mode for code editor
1 parent c349f7f commit 0e110d9

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
@@ -15,20 +15,39 @@ export default {
1515
height: true,
1616
width: true,
1717
readOnly: Boolean,
18+
autoGrow: Boolean,
1819
},
1920
data() {
2021
return {
2122
editor: null,
2223
contentBackup: '',
24+
fullScreen: false,
2325
};
2426
},
27+
computed: {
28+
editorHeight() {
29+
if (this.autoGrow && !this.fullScreen) return undefined;
30+
if (this.height && !this.fullScreen) return this.px(this.height);
31+
return '100%'
32+
},
33+
editorStyle() {
34+
return {
35+
width: this.width && !this.fullScreen ? this.px(this.width) : '100%',
36+
height: this.editorHeight,
37+
}
38+
},
39+
},
2540
methods: {
2641
px(n) {
2742
if (/^\d*$/.test(n)) {
2843
return `${n}px`;
2944
}
3045
return n;
3146
},
47+
toggleFullscreen() {
48+
this.fullScreen = !this.fullScreen;
49+
this.editor.resize();
50+
}
3251
},
3352
watch: {
3453
value(val) {
@@ -48,7 +67,7 @@ export default {
4867
4968
require('brace/ext/emmet');
5069
51-
const editor = (vm.editor = ace.edit(this.$el));
70+
const editor = (vm.editor = ace.edit(this.$refs.editor));
5271
5372
this.$emit('init', editor);
5473
@@ -60,12 +79,14 @@ export default {
6079
editor.setShowPrintMargin(false);
6180
6281
if (!this.readOnly) {
63-
editor.setOption('minLines', 15);
6482
editor.setValue(this.value, 1);
6583
} else {
6684
editor.setValue(this.code, 1);
6785
}
6886
editor.setReadOnly(this.readOnly);
87+
if(this.autoGrow) {
88+
editor.setOption('maxLines', Infinity);
89+
}
6990
7091
editor.on('change', () => {
7192
const content = editor.getValue();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated
6868
:lang="file.language"
6969
theme="monokai"
7070
width="100%"
71-
height="260"
71+
height="220"
7272
></editor>
7373
</b-field>
7474
</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)