@@ -14,9 +14,15 @@ import { download } from '../../redux/modules/files.js';
1414import { fetchContentIfNeeded } from '../../redux/modules/filesContent.js' ;
1515import { getFilesContent } from '../../redux/selectors/files.js' ;
1616import ResourceRenderer from '../../components/helpers/ResourceRenderer' ;
17- import SourceCodeViewer from '../../components/helpers/SourceCodeViewer' ;
17+ import SourceCodeViewer , {
18+ SourceCodeHighlightingSelector ,
19+ localStorageHighlightOverridesKey ,
20+ } from '../../components/helpers/SourceCodeViewer' ;
21+
1822import DownloadSolutionArchiveContainer from '../DownloadSolutionArchiveContainer' ;
1923import UsersNameContainer from '../UsersNameContainer' ;
24+ import { getFileExtensionLC } from '../../helpers/common.js' ;
25+ import { storageGetItem , storageSetItem } from '../../helpers/localStorage.js' ;
2026
2127import * as styles from './sourceCode.less' ;
2228
@@ -41,12 +47,15 @@ const preprocessFiles = lruMemoize(files =>
4147) ;
4248
4349class SourceCodeViewerContainer extends Component {
44- state = { clipboardCopied : false } ;
50+ state = { clipboardCopied : false , highlightOverrides : { } } ;
4551
4652 componentDidMount ( ) {
4753 const { fileId, loadAsync } = this . props ;
4854 if ( fileId !== null ) {
4955 loadAsync ( ) ;
56+ this . setState ( {
57+ highlightOverrides : storageGetItem ( localStorageHighlightOverridesKey , { } ) ,
58+ } ) ;
5059 }
5160 }
5261
@@ -56,9 +65,21 @@ class SourceCodeViewerContainer extends Component {
5665 ( this . props . fileId !== prevProps . fileId || this . props . zipEntry !== prevProps . zipEntry )
5766 ) {
5867 this . props . loadAsync ( ) ;
68+ this . setState ( {
69+ highlightOverrides : storageGetItem ( localStorageHighlightOverridesKey , { } ) ,
70+ } ) ;
5971 }
6072 }
6173
74+ setHighlightOverride = ( extension , mode ) => {
75+ const { [ extension ] : _ , ...newOverrides } = this . state . highlightOverrides ;
76+ if ( mode || mode === '' ) {
77+ newOverrides [ extension ] = mode ;
78+ }
79+ this . setState ( { highlightOverrides : newOverrides } ) ;
80+ storageSetItem ( localStorageHighlightOverridesKey , newOverrides ) ;
81+ } ;
82+
6283 render ( ) {
6384 const {
6485 show,
@@ -75,6 +96,8 @@ class SourceCodeViewerContainer extends Component {
7596 submittedBy = null ,
7697 } = this . props ;
7798
99+ const fileExtension = getFileExtensionLC ( fileName ) ;
100+
78101 return (
79102 < ResourceRenderer
80103 loading = {
@@ -95,7 +118,13 @@ class SourceCodeViewerContainer extends Component {
95118 }
96119 resource = { content } >
97120 { content => (
98- < Modal show = { show } onHide = { onHide } onEscapeKeyDown = { onHide } dialogClassName = { styles . modal } size = "xl" >
121+ < Modal
122+ show = { show }
123+ onHide = { onHide }
124+ onEscapeKeyDown = { onHide }
125+ dialogClassName = { styles . modal }
126+ size = "xl"
127+ enforceFocus = { false } >
99128 < Modal . Header closeButton >
100129 < ResourceRenderer resource = { files } >
101130 { files => (
@@ -116,6 +145,17 @@ class SourceCodeViewerContainer extends Component {
116145 ) ) }
117146 </ DropdownButton >
118147
148+ < SourceCodeHighlightingSelector
149+ id = "highlighting"
150+ fullButton
151+ size = "sm"
152+ className = "me-2"
153+ variant = "outline-secondary"
154+ extension = { fileExtension }
155+ initialMode = { this . state . highlightOverrides [ fileExtension ] }
156+ onChange = { this . setHighlightOverride }
157+ />
158+
119159 < Button size = "sm" className = "me-2" onClick = { ( ) => download ( fileId , zipEntry ) } >
120160 < DownloadIcon gapRight = { 2 } />
121161 < FormattedMessage id = "app.sourceCodeViewer.downloadButton" defaultMessage = "Download file" />
@@ -180,7 +220,13 @@ class SourceCodeViewerContainer extends Component {
180220 { content . malformedCharacters ? (
181221 < pre className = "border-top" > { content . content } </ pre >
182222 ) : (
183- < SourceCodeViewer id = { fileId } content = { content . content } name = { fileName } solutionId = { solutionId } />
223+ < SourceCodeViewer
224+ id = { fileId }
225+ content = { content . content }
226+ name = { fileName }
227+ solutionId = { solutionId }
228+ highlightOverrides = { this . state . highlightOverrides }
229+ />
184230 ) }
185231 < div className = "border-top pt-1 bg-light rounded-bottom" > </ div >
186232 </ Modal . Body >
0 commit comments