-
-
Notifications
You must be signed in to change notification settings - Fork 213
feat: add font size and word wrap settings to editor preferences #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
d78f35e
87c91cf
bfcc2e7
ef8926e
67cf583
c0a43e6
be9a668
4b8effb
c4e2423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -121,11 +121,13 @@ export default function ConcertoEditor({ | |||||
| }: ConcertoEditorProps) { | ||||||
| const { handleSelection, MenuComponent } = useCodeSelection("concerto"); | ||||||
| const monacoInstance = useMonaco(); | ||||||
| const { error, backgroundColor, aiConfig, showLineNumbers } = useAppStore((state) => ({ | ||||||
| const { error, backgroundColor, aiConfig, showLineNumbers, editorFontSize, editorWordWrap } = useAppStore((state) => ({ | ||||||
| error: state.error, | ||||||
| backgroundColor: state.backgroundColor, | ||||||
| aiConfig: state.aiConfig, | ||||||
| showLineNumbers: state.showLineNumbers, | ||||||
| editorFontSize: state.editorFontSize, | ||||||
| editorWordWrap: state.editorWordWrap, | ||||||
| })); | ||||||
| const ctoErr = error?.startsWith("c:") ? error : undefined; | ||||||
|
|
||||||
|
|
@@ -136,9 +138,10 @@ export default function ConcertoEditor({ | |||||
|
|
||||||
| const options: monaco.editor.IStandaloneEditorConstructionOptions = useMemo(() => ({ | ||||||
| minimap: { enabled: false }, | ||||||
| wordWrap: "on", | ||||||
| wordWrap: editorWordWrap ? "on" : "off", | ||||||
|
||||||
| wordWrap: editorWordWrap ? "on" : "off", | |
| wordWrap: editorWordWrap ? ("on" as const) : ("off" as const), |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,10 +19,12 @@ export default function JSONEditor({ | |||||
| }) { | ||||||
| const { handleSelection, MenuComponent } = useCodeSelection("json"); | ||||||
|
|
||||||
| const { backgroundColor, aiConfig, showLineNumbers } = useAppStore((state) => ({ | ||||||
| const { backgroundColor, aiConfig, showLineNumbers, editorFontSize, editorWordWrap } = useAppStore((state) => ({ | ||||||
| backgroundColor: state.backgroundColor, | ||||||
| aiConfig: state.aiConfig, | ||||||
| showLineNumbers: state.showLineNumbers, | ||||||
| editorFontSize: state.editorFontSize, | ||||||
| editorWordWrap: state.editorWordWrap, | ||||||
| })); | ||||||
|
|
||||||
| const themeName = useMemo( | ||||||
|
|
@@ -32,9 +34,10 @@ export default function JSONEditor({ | |||||
|
|
||||||
| const options: monaco.editor.IStandaloneEditorConstructionOptions = useMemo(() => ({ | ||||||
| minimap: { enabled: false }, | ||||||
| wordWrap: "on", | ||||||
| wordWrap: editorWordWrap ? "on" : "off", | ||||||
|
||||||
| wordWrap: editorWordWrap ? "on" : "off", | |
| wordWrap: editorWordWrap ? ("on" as const) : ("off" as const), |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,6 +63,10 @@ interface AppState { | |||||||||||||||||||||||||||||||||||||
| toggleDataCollapse: () => void; | ||||||||||||||||||||||||||||||||||||||
| showLineNumbers: boolean; | ||||||||||||||||||||||||||||||||||||||
| setShowLineNumbers: (value: boolean) => void; | ||||||||||||||||||||||||||||||||||||||
| editorFontSize: number; | ||||||||||||||||||||||||||||||||||||||
| setEditorFontSize: (value: number) => void; | ||||||||||||||||||||||||||||||||||||||
| editorWordWrap: boolean; | ||||||||||||||||||||||||||||||||||||||
| setEditorWordWrap: (value: boolean) => void; | ||||||||||||||||||||||||||||||||||||||
| isSettingsOpen: boolean; | ||||||||||||||||||||||||||||||||||||||
| setSettingsOpen: (value: boolean) => void; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,6 +164,27 @@ const getInitialLineNumbers = () => { | |||||||||||||||||||||||||||||||||||||
| return true; // Default to showing line numbers | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const getInitialFontSize = () => { | ||||||||||||||||||||||||||||||||||||||
| if (typeof window !== 'undefined') { | ||||||||||||||||||||||||||||||||||||||
| const saved = localStorage.getItem('editorFontSize'); | ||||||||||||||||||||||||||||||||||||||
| if (saved !== null) { | ||||||||||||||||||||||||||||||||||||||
| const parsed = parseInt(saved, 10); | ||||||||||||||||||||||||||||||||||||||
| if (!isNaN(parsed)) return parsed; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return 14; // Default font size | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+170
to
+179
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const getInitialWordWrap = () => { | ||||||||||||||||||||||||||||||||||||||
| if (typeof window !== 'undefined') { | ||||||||||||||||||||||||||||||||||||||
| const saved = localStorage.getItem('editorWordWrap'); | ||||||||||||||||||||||||||||||||||||||
| if (saved !== null) { | ||||||||||||||||||||||||||||||||||||||
| return saved === 'true'; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return true; // Default to word wrap on | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const useAppStore = create<AppState>()( | ||||||||||||||||||||||||||||||||||||||
| immer( | ||||||||||||||||||||||||||||||||||||||
| devtools((set, get) => { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -195,6 +220,8 @@ const useAppStore = create<AppState>()( | |||||||||||||||||||||||||||||||||||||
| isTemplateCollapsed: false, | ||||||||||||||||||||||||||||||||||||||
| isDataCollapsed: false, | ||||||||||||||||||||||||||||||||||||||
| showLineNumbers: getInitialLineNumbers(), | ||||||||||||||||||||||||||||||||||||||
| editorFontSize: getInitialFontSize(), | ||||||||||||||||||||||||||||||||||||||
| editorWordWrap: getInitialWordWrap(), | ||||||||||||||||||||||||||||||||||||||
| isSettingsOpen: false, | ||||||||||||||||||||||||||||||||||||||
| toggleModelCollapse: () => set((state) => ({ isModelCollapsed: !state.isModelCollapsed })), | ||||||||||||||||||||||||||||||||||||||
| toggleTemplateCollapse: () => set((state) => ({ isTemplateCollapsed: !state.isTemplateCollapsed })), | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -205,6 +232,18 @@ const useAppStore = create<AppState>()( | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| set({ showLineNumbers: value }); | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| setEditorFontSize: (value: number) => { | ||||||||||||||||||||||||||||||||||||||
| if (typeof window !== 'undefined') { | ||||||||||||||||||||||||||||||||||||||
| localStorage.setItem('editorFontSize', String(value)); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| set({ editorFontSize: value }); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| if (typeof window !== 'undefined') { | |
| localStorage.setItem('editorFontSize', String(value)); | |
| } | |
| set({ editorFontSize: value }); | |
| // Validate and normalize the incoming font size to prevent invalid values | |
| const safeValue = Math.round(value); | |
| const MIN_FONT_SIZE = 8; | |
| const MAX_FONT_SIZE = 72; | |
| if (!Number.isFinite(safeValue) || safeValue < MIN_FONT_SIZE || safeValue > MAX_FONT_SIZE) { | |
| // Ignore invalid values rather than persisting them | |
| return; | |
| } | |
| if (typeof window !== 'undefined') { | |
| localStorage.setItem('editorFontSize', String(safeValue)); | |
| } | |
| set({ editorFontSize: safeValue }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ vi.mock('../../store/store', () => { | |||||||||||||||||||
| setSettingsOpen: vi.fn(), | ||||||||||||||||||||
| showLineNumbers: true, | ||||||||||||||||||||
| setShowLineNumbers: vi.fn(), | ||||||||||||||||||||
| editorFontSize: 14, | ||||||||||||||||||||
| setEditorFontSize: vi.fn(), | ||||||||||||||||||||
| editorWordWrap: true, | ||||||||||||||||||||
| setEditorWordWrap: vi.fn(), | ||||||||||||||||||||
| textColor: '#121212', | ||||||||||||||||||||
| backgroundColor: '#ffffff', | ||||||||||||||||||||
| toggleDarkMode: vi.fn(), | ||||||||||||||||||||
|
|
@@ -76,10 +80,39 @@ describe('SettingsModal', () => { | |||||||||||||||||||
| expect(toggle).toBeChecked(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('renders the Font Size setting', () => { | ||||||||||||||||||||
| render(<SettingsModal />); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| expect(screen.getByText('Font Size')).toBeInTheDocument(); | ||||||||||||||||||||
| expect(screen.getByText('Adjust font size in code editors')).toBeInTheDocument(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
||||||||||||||||||||
| it('renders the Font Size select with the correct initial value', () => { | |
| render(<SettingsModal />); | |
| const fontSizeSelect = screen.getByRole('combobox', { name: /font size/i }); | |
| expect(fontSizeSelect).toBeInTheDocument(); | |
| expect(fontSizeSelect).toHaveValue('14'); | |
| }); |
Shubh-Raj marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import useAppStore from '../../store/store'; | ||
|
|
||
| describe('useAppStore - editorFontSize', () => { | ||
| beforeEach(() => { | ||
| localStorage.clear(); | ||
| useAppStore.setState({ | ||
| editorFontSize: 14, | ||
| }); | ||
| }); | ||
|
|
||
| it('should have editorFontSize default to 14', () => { | ||
| const state = useAppStore.getState(); | ||
| expect(state.editorFontSize).toBe(14); | ||
| }); | ||
|
Comment on lines
+5
to
+15
|
||
|
|
||
| it('should update editorFontSize when setEditorFontSize is called', () => { | ||
| const store = useAppStore.getState(); | ||
|
|
||
| store.setEditorFontSize(18); | ||
|
|
||
| expect(useAppStore.getState().editorFontSize).toBe(18); | ||
| }); | ||
|
|
||
| it('should persist editorFontSize to localStorage', () => { | ||
| const store = useAppStore.getState(); | ||
|
|
||
| store.setEditorFontSize(16); | ||
|
|
||
| expect(localStorage.getItem('editorFontSize')).toBe('16'); | ||
| }); | ||
|
|
||
| it('should set various font sizes correctly', () => { | ||
| const store = useAppStore.getState(); | ||
|
|
||
| store.setEditorFontSize(12); | ||
| expect(useAppStore.getState().editorFontSize).toBe(12); | ||
|
|
||
| store.setEditorFontSize(20); | ||
| expect(useAppStore.getState().editorFontSize).toBe(20); | ||
|
|
||
| store.setEditorFontSize(14); | ||
| expect(useAppStore.getState().editorFontSize).toBe(14); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FONT_SIZE_OPTIONS constant is defined in SettingsModal.tsx but not accessible from the store file. For better maintainability and potential validation, consider either: 1) defining FONT_SIZE_OPTIONS in a shared constants file, or 2) exporting it from SettingsModal.tsx so it can be imported in store.ts if validation is added later. This would create a single source of truth for the valid font size values.