Installing basic UI
This commit is contained in:
50
src/lib/stores/editorSettings.ts
Normal file
50
src/lib/stores/editorSettings.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export interface EditorSettings {
|
||||
fontSize: number;
|
||||
fontFamily: string;
|
||||
showLineNumbers: boolean;
|
||||
enableLineWrapping: boolean;
|
||||
tabSize: number;
|
||||
vimMode: boolean;
|
||||
}
|
||||
|
||||
const defaultSettings: EditorSettings = {
|
||||
fontSize: 14,
|
||||
fontFamily: "'Roboto Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
|
||||
showLineNumbers: true,
|
||||
enableLineWrapping: false,
|
||||
tabSize: 2,
|
||||
vimMode: false
|
||||
};
|
||||
|
||||
function createEditorSettings() {
|
||||
const stored = localStorage.getItem('editorSettings');
|
||||
const initial = stored ? { ...defaultSettings, ...JSON.parse(stored) } : defaultSettings;
|
||||
|
||||
const { subscribe, set, update } = writable<EditorSettings>(initial);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set: (value: EditorSettings) => {
|
||||
localStorage.setItem('editorSettings', JSON.stringify(value));
|
||||
set(value);
|
||||
},
|
||||
update: (updater: (value: EditorSettings) => EditorSettings) => {
|
||||
update((current) => {
|
||||
const newValue = updater(current);
|
||||
localStorage.setItem('editorSettings', JSON.stringify(newValue));
|
||||
return newValue;
|
||||
});
|
||||
},
|
||||
updatePartial: (partial: Partial<EditorSettings>) => {
|
||||
update((current) => {
|
||||
const newValue = { ...current, ...partial };
|
||||
localStorage.setItem('editorSettings', JSON.stringify(newValue));
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const editorSettings = createEditorSettings();
|
||||
Reference in New Issue
Block a user