Skip to content

Commit 77a0696

Browse files
committed
chore: getting monaco editor options from one common place
1 parent c15437b commit 77a0696

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

helpers/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,18 @@ export function putToClipboard(
5858
theme: 'success',
5959
})
6060
}
61+
62+
export function getMonacoEditorDefaultOptions(theme: string) {
63+
return {
64+
language: 'javascript',
65+
theme,
66+
fontSize: parseFloat(getComputedStyle(document.documentElement).fontSize),
67+
scrollBeyondLastLine: false,
68+
scrollBeyondLastColumn: false,
69+
minimap: {
70+
enabled: false,
71+
},
72+
wordWrap: 'on',
73+
contextmenu: false,
74+
}
75+
}

pages/v2/diff.vue

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<script lang="ts">
1919
import pako from 'pako'
2020
import Vue from 'vue'
21-
import { undoUrlSafeBase64 } from '../../helpers/utils'
21+
import { getMonacoEditorDefaultOptions, undoUrlSafeBase64 } from '../../helpers/utils'
2222
import DiffActionBar from '~/components/v2/diffActionBar.vue'
2323
import Navbar from '~/components/v2/navbar.vue'
2424
import { DiffData } from '~/helpers/types'
@@ -67,24 +67,13 @@ export default Vue.extend({
6767
mounted() {
6868
const monacoDiffViewerEl = document.getElementById('monaco-diff-viewer')
6969
const theme = this.$cookies.isDarkMode ? 'vs-dark' : 'light'
70-
const monacoEditorOptions = {
71-
language: 'javascript',
72-
theme,
73-
fontSize: parseFloat(getComputedStyle(document.documentElement).fontSize),
74-
readOnly: true,
75-
scrollBeyondLastLine: false,
76-
scrollBeyondLastColumn: false,
77-
minimap: {
78-
enabled: false,
79-
},
80-
wordWrap: 'on',
81-
contextmenu: false,
82-
}
70+
const monacoEditorOptions = getMonacoEditorDefaultOptions(theme);
8371
if (monacoDiffViewerEl) {
8472
this.monacoDiffEditor = monaco.editor.createDiffEditor(
8573
monacoDiffViewerEl,
8674
{
8775
...monacoEditorOptions,
76+
readOnly: true
8877
}
8978
) as any
9079
if (this.monacoDiffEditor) {

pages/v2/index.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
<script lang="ts">
6969
import Vue from 'vue'
7070
import pako from 'pako'
71-
import { doUrlSafeBase64 } from '../../helpers/utils'
71+
import {
72+
doUrlSafeBase64,
73+
getMonacoEditorDefaultOptions,
74+
} from '../../helpers/utils'
7275
import showTutorials from '../../helpers/driverjsTutorials'
7376
import Navbar from '~/components/v2/navbar.vue'
7477
declare namespace monaco {
@@ -106,17 +109,7 @@ export default Vue.extend({
106109
const lhs = document.getElementById('lhs')
107110
const rhs = document.getElementById('rhs')
108111
const theme = this.$cookies.isDarkMode ? 'vs-dark' : 'light'
109-
const monacoEditorOptions = {
110-
language: 'javascript',
111-
theme,
112-
fontSize: parseFloat(getComputedStyle(document.documentElement).fontSize),
113-
scrollBeyondLastLine: false,
114-
scrollBeyondLastColumn: false,
115-
minimap: {
116-
enabled: false,
117-
},
118-
wordWrap: 'on',
119-
}
112+
const monacoEditorOptions = getMonacoEditorDefaultOptions(theme)
120113
if (lhs) {
121114
this.lhsEditor = monaco.editor.create(lhs, {
122115
...monacoEditorOptions,

0 commit comments

Comments
 (0)