editor font size settings

This commit is contained in:
Jan Prochazka
2022-03-05 09:35:32 +01:00
parent caf9870990
commit 2fa46da7b6
3 changed files with 57 additions and 12 deletions

View File

@@ -37,6 +37,19 @@
'tomorrow_night', 'tomorrow_night',
'twilight', 'twilight',
]; ];
export const FONT_SIZES = [
{ label: '8', value: '8' },
{ label: '9', value: '9' },
{ label: '10', value: '10' },
{ label: '11', value: '11' },
{ label: '12 - Normal', value: '12' },
{ label: '13', value: '13' },
{ label: '14', value: '14' },
{ label: '15', value: '15' },
{ label: '16', value: '16' },
{ label: '17', value: '17' },
];
</script> </script>
<script lang="ts"> <script lang="ts">
@@ -101,7 +114,7 @@
import 'ace-builds/src-noconflict/theme-tomorrow_night'; import 'ace-builds/src-noconflict/theme-tomorrow_night';
import 'ace-builds/src-noconflict/theme-twilight'; import 'ace-builds/src-noconflict/theme-twilight';
import { currentDropDownMenu, currentEditorTheme, currentThemeDefinition } from '../stores'; import { currentDropDownMenu, currentEditorFontSize, currentEditorTheme, currentThemeDefinition } from '../stores';
import _ from 'lodash'; import _ from 'lodash';
import { handleCommandKeyDown } from '../commands/CommandListener.svelte'; import { handleCommandKeyDown } from '../commands/CommandListener.svelte';
import resizeObserver from '../utility/resizeObserver'; import resizeObserver from '../utility/resizeObserver';
@@ -149,11 +162,14 @@
let queryParserWorker; let queryParserWorker;
let defaultFontSize;
const stdOptions = { const stdOptions = {
showPrintMargin: false, showPrintMargin: false,
}; };
$: theme = $currentEditorTheme || ($currentThemeDefinition?.themeType == 'dark' ? 'merbivore' : 'github'); $: theme = $currentEditorTheme || ($currentThemeDefinition?.themeType == 'dark' ? 'merbivore' : 'github');
$: watchEditorFontSize($currentEditorFontSize);
export function getEditor(): ace.Editor { export function getEditor(): ace.Editor {
return editor; return editor;
@@ -187,6 +203,12 @@
} }
} }
function watchEditorFontSize(value) {
if (editor) {
editor.setFontSize(value ? parseInt(value) : defaultFontSize);
}
}
$: watchTheme(theme); $: watchTheme(theme);
function watchTheme(newTheme: string) { function watchTheme(newTheme: string) {
if (editor) { if (editor) {
@@ -400,6 +422,10 @@
contentBackup = content; contentBackup = content;
changedQueryParts(); changedQueryParts();
}); });
defaultFontSize = editor.getFontSize();
if ($currentEditorFontSize) {
editor.setFontSize($currentEditorFontSize);
}
editor.on('changeSelection', () => { editor.on('changeSelection', () => {
changedCurrentQueryPart(); changedCurrentQueryPart();

View File

@@ -14,9 +14,9 @@
import ModalBase from '../modals/ModalBase.svelte'; import ModalBase from '../modals/ModalBase.svelte';
import { closeCurrentModal } from '../modals/modalTools'; import { closeCurrentModal } from '../modals/modalTools';
import { EDITOR_THEMES } from '../query/AceEditor.svelte'; import { EDITOR_THEMES, FONT_SIZES } from '../query/AceEditor.svelte';
import SqlEditor from '../query/SqlEditor.svelte'; import SqlEditor from '../query/SqlEditor.svelte';
import { currentEditorTheme, extensions } from '../stores'; import { currentEditorFontSize, currentEditorTheme, extensions } from '../stores';
import getElectron from '../utility/getElectron'; import getElectron from '../utility/getElectron';
import ThemeSkeleton from './ThemeSkeleton.svelte'; import ThemeSkeleton from './ThemeSkeleton.svelte';
@@ -106,7 +106,9 @@ ORDER BY
<div class="heading">Editor theme</div> <div class="heading">Editor theme</div>
<FormFieldTemplateLarge label="Theme" type='combo'> <div class="flex">
<div class="col-6">
<FormFieldTemplateLarge label="Theme" type="combo">
<SelectField <SelectField
isNative isNative
notSelected="(use theme default)" notSelected="(use theme default)"
@@ -115,6 +117,20 @@ ORDER BY
on:change={e => ($currentEditorTheme = e.detail)} on:change={e => ($currentEditorTheme = e.detail)}
/> />
</FormFieldTemplateLarge> </FormFieldTemplateLarge>
</div>
<div class="col-6">
<FormFieldTemplateLarge label="Font size " type="combo">
<SelectField
isNative
notSelected="(default)"
options={FONT_SIZES}
value={$currentEditorFontSize}
on:change={e => ($currentEditorFontSize = e.detail)}
/>
</FormFieldTemplateLarge>
</div>
</div>
<div class="editor"> <div class="editor">
<SqlEditor value={sqlPreview} readOnly /> <SqlEditor value={sqlPreview} readOnly />

View File

@@ -59,6 +59,9 @@ export const currentTheme = getElectron()
export const currentEditorTheme = getElectron() export const currentEditorTheme = getElectron()
? writableSettingsValue(null, 'currentEditorTheme') ? writableSettingsValue(null, 'currentEditorTheme')
: writableWithStorage(null, 'currentEditorTheme'); : writableWithStorage(null, 'currentEditorTheme');
export const currentEditorFontSize = getElectron()
? writableSettingsValue(null, 'currentEditorFontSize')
: writableWithStorage(null, 'currentEditorFontSize');
export const activeTabId = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)?.tabid); export const activeTabId = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)?.tabid);
export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)); export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected));
export const recentDatabases = writableWithStorage([], 'recentDatabases'); export const recentDatabases = writableWithStorage([], 'recentDatabases');