Skip to content

Commit

Permalink
Soft-wrap as a global preference. Fixes #517
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed May 10, 2024
1 parent e4e7ac2 commit 3a7aa75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/common/state/store-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ interface UIPreferencesStore {
renderMarkdown: boolean;
setRenderMarkdown: (renderMarkdown: boolean) => void;

renderCodeSoftWrap: boolean;
setRenderCodeSoftWrap: (renderCodeSoftWrap: boolean) => void;

// showPersonaExamples: boolean;
// setShowPersonaExamples: (showPersonaExamples: boolean) => void;

Expand Down Expand Up @@ -75,6 +78,9 @@ export const useUIPreferencesStore = create<UIPreferencesStore>()(
renderMarkdown: true,
setRenderMarkdown: (renderMarkdown: boolean) => set({ renderMarkdown }),

renderCodeSoftWrap: false,
setRenderCodeSoftWrap: (renderCodeSoftWrap: boolean) => set({ renderCodeSoftWrap }),

// showPersonaExamples: false,
// setShowPersonaExamples: (showPersonaExamples: boolean) => set({ showPersonaExamples }),

Expand Down
5 changes: 3 additions & 2 deletions src/modules/blocks/code/RenderCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import WrapTextIcon from '@mui/icons-material/WrapText';

import { copyToClipboard } from '~/common/util/clipboardUtils';
import { frontendSideFetch } from '~/common/util/clientFetchers';
import { useUIPreferencesStore } from '~/common/state/store-ui';

import type { CodeBlock } from '../blocks';
import { ButtonCodePen, isCodePenSupported } from './ButtonCodePen';
Expand Down Expand Up @@ -107,7 +108,7 @@ function RenderCodeImpl(props: RenderCodeImplProps) {
const [showMermaid, setShowMermaid] = React.useState(true);
const [showPlantUML, setShowPlantUML] = React.useState(true);
const [showSVG, setShowSVG] = React.useState(true);
const [softWrap, setSoftWrap] = React.useState(false);
const [softWrap, setSoftWrap] = useUIPreferencesStore(state => [state.renderCodeSoftWrap, state.setRenderCodeSoftWrap]);

// derived props
const {
Expand Down Expand Up @@ -274,7 +275,7 @@ function RenderCodeImpl(props: RenderCodeImplProps) {
{/* Soft Wrap toggle */}
{(!renderHTML && !renderMermaid && !renderPlantUML && !renderSVG) && (
<Tooltip title='Toggle Soft Wrap'>
<OverlayButton variant={softWrap ? 'solid' : 'outlined'} onClick={() => setSoftWrap(on => !on)}>
<OverlayButton variant={softWrap ? 'solid' : 'outlined'} onClick={() => setSoftWrap(!softWrap)}>
<WrapTextIcon />
</OverlayButton>
</Tooltip>
Expand Down

0 comments on commit 3a7aa75

Please sign in to comment.