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

Feature/editor full screen mode #103

Closed
Closed
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
15 changes: 14 additions & 1 deletion src/renderer/components/editor/Editor.html
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<div id="editor" :style="{width: width ? px(width) : '100%'}"></div>
<div class="editor" :class="{'editor--fullscreen': fullScreen}">
<div id="editor" ref="editor" :style="editorStyle"></div>
<a
href="#"
class="editor__fullscreen-toggle"
@click="toggleFullscreen"
v-if="!readOnly"
title="Toggle fullscreen mode"
>
<b-icon
:icon="fullScreen ? 'compress': 'expand'"
></b-icon>
</a>
</div>
25 changes: 25 additions & 0 deletions src/renderer/components/editor/Editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.editor {
position: relative;

&--fullscreen {
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100vw;
height: 100vh;
z-index: 10;
}

&__fullscreen-toggle {
position: absolute;
top: 4px;
right: 4px;
z-index: 1;
color: whitesmoke;
}
&__fullscreen-toggle:hover {
color: #bbb;
}
}
27 changes: 24 additions & 3 deletions src/renderer/components/editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,39 @@ export default {
height: true,
width: true,
readOnly: Boolean,
autoGrow: Boolean,
},
data() {
return {
editor: null,
contentBackup: '',
fullScreen: false,
};
},
computed: {
editorHeight() {
if (this.autoGrow && !this.fullScreen) return undefined;
if (this.height && !this.fullScreen) return this.px(this.height);
return '100%'
},
editorStyle() {
return {
width: this.width && !this.fullScreen ? this.px(this.width) : '100%',
height: this.editorHeight,
}
},
},
methods: {
px(n) {
if (/^\d*$/.test(n)) {
return `${n}px`;
}
return n;
},
toggleFullscreen() {
this.fullScreen = !this.fullScreen;
this.editor.resize();
}
},
watch: {
value(val) {
Expand All @@ -49,24 +68,26 @@ export default {

require('brace/ext/emmet');

const editor = (vm.editor = ace.edit(this.$el));
const editor = (vm.editor = ace.edit(this.$refs.editor));

this.$emit('init', editor);

editor.$blockScrolling = Infinity;
editor.setOption('enableEmmet', true);
editor.setOption('maxLines', 15);
editor.setOption('fontSize', '1rem');
editor.getSession().setMode(`ace/mode/${lang}`);
editor.setTheme(`ace/theme/${theme}`);
editor.setShowPrintMargin(false);

if (!this.readOnly) {
editor.setOption('minLines', 15);
editor.setValue(this.value, 1);
} else {
editor.setValue(this.code, 1);
}
editor.setReadOnly(this.readOnly);
if(this.autoGrow) {
editor.setOption('maxLines', Infinity);
}

editor.on('change', () => {
const content = editor.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated
:lang="file.language"
theme="monokai"
width="100%"
height="260"
height="220"
></editor>
</b-field>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/notes-list/note-card/NoteCard.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h4>{{value.name}}
:lang="value.language"
theme="monokai"
width="100%"
height="260"
:auto-grow="true"
:readOnly="true"
></editor>
</div>
Expand Down