Przeglądaj źródła

Merge pull request #15057 from overleaf/mf-lhs-makefile-editable

[web] Add `lhs` and makefiles (`makefile`, `gnumakefile`, and `*.mk`) as editable files

GitOrigin-RevId: d5f32aeab05947e7b8fec1c9bb6ec1defca42cdf
M Fahru 2 lat temu
rodzic
commit
d378246468

+ 2 - 1
services/web/app/src/Features/Uploads/FileTypeManager.js

@@ -13,6 +13,7 @@ const fileIgnoreMatcher = new Minimatch(Settings.fileIgnorePattern, {
 
 const FileTypeManager = {
   TEXT_EXTENSIONS: new Set(Settings.textExtensions.map(ext => `.${ext}`)),
+  EDITABLE_FILENAMES: Settings.editableFilenames,
 
   MAX_TEXT_FILE_SIZE: 1 * 1024 * 1024, // 1 MB
 
@@ -108,7 +109,7 @@ function _isTextFilename(filename) {
   const extension = Path.extname(filename).toLowerCase()
   return (
     FileTypeManager.TEXT_EXTENSIONS.has(extension) ||
-    filename.match(/^(\.)?latexmkrc$/)
+    FileTypeManager.EDITABLE_FILENAMES.includes(filename.toLowerCase())
   )
 }
 

+ 1 - 0
services/web/app/src/infrastructure/ExpressLocals.js

@@ -397,6 +397,7 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
       recaptchaSiteKeyV3: Settings.recaptcha?.siteKeyV3,
       recaptchaDisabled: Settings.recaptcha?.disabled,
       textExtensions: Settings.textExtensions,
+      editableFilenames: Settings.editableFilenames,
       validRootDocExtensions: Settings.validRootDocExtensions,
       sentryAllowedOriginRegex: Settings.sentry.allowedOriginRegex,
       sentryDsn: Settings.sentry.publicDSN,

+ 5 - 1
services/web/config/settings.defaults.js

@@ -44,7 +44,6 @@ const defaultTextExtensions = [
   'rtex',
   'md',
   'asy',
-  'latexmkrc',
   'lbx',
   'bbx',
   'cbx',
@@ -62,6 +61,8 @@ const defaultTextExtensions = [
   'mf',
   'yml',
   'yaml',
+  'lhs',
+  'mk',
 ]
 
 const parseTextExtensions = function (extensions) {
@@ -676,6 +677,9 @@ module.exports = {
     parseTextExtensions(process.env.ADDITIONAL_TEXT_EXTENSIONS)
   ),
 
+  // case-insensitive file names that is editable (doc) in the editor
+  editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
+
   fileIgnorePattern:
     process.env.FILE_IGNORE_PATTERN ||
     '**/{{__MACOSX,.git,.texpadtmp,.R}{,/**},.!(latexmkrc),*.{dvi,aux,log,toc,out,pdfsync,synctex,synctex(busy),fdb_latexmk,fls,nlo,ind,glo,gls,glg,bbl,blg,doc,docx,gz,swp}}',

+ 11 - 5
services/web/frontend/js/features/file-view/components/file-view.jsx

@@ -15,11 +15,17 @@ export default function FileView({ file }) {
 
   const { t } = useTranslation()
 
-  const { textExtensions } = window.ExposedSettings
+  const { textExtensions, editableFilenames } = window.ExposedSettings
 
   const extension = file.name.split('.').pop().toLowerCase()
-  const isUnpreviewableFile =
-    !imageExtensions.includes(extension) && !textExtensions.includes(extension)
+
+  const isEditableTextFile =
+    textExtensions.includes(extension) ||
+    editableFilenames.includes(file.name.toLowerCase())
+
+  const isImageFile = imageExtensions.includes(extension)
+
+  const isUnpreviewableFile = !isEditableTextFile && !isImageFile
 
   const handleLoad = useCallback(() => {
     setContentLoading(false)
@@ -35,7 +41,7 @@ export default function FileView({ file }) {
   const content = (
     <>
       <FileViewHeader file={file} />
-      {imageExtensions.includes(extension) && (
+      {isImageFile && (
         <FileViewImage
           fileName={file.name}
           fileId={file.id}
@@ -43,7 +49,7 @@ export default function FileView({ file }) {
           onError={handleError}
         />
       )}
-      {textExtensions.includes(extension) && (
+      {isEditableTextFile && (
         <FileViewText file={file} onLoad={handleLoad} onError={handleError} />
       )}
     </>

+ 3 - 1
services/web/frontend/stories/decorators/scope.tsx

@@ -168,7 +168,6 @@ const initialize = () => {
       'rtex',
       'md',
       'asy',
-      'latexmkrc',
       'lbx',
       'bbx',
       'cbx',
@@ -184,7 +183,10 @@ const initialize = () => {
       'lua',
       'gv',
       'mf',
+      'lhs',
+      'mk',
     ],
+    editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
     validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'],
   }
 

+ 3 - 1
services/web/test/frontend/bootstrap.js

@@ -46,7 +46,6 @@ window.ExposedSettings = {
     'rtex',
     'md',
     'asy',
-    'latexmkrc',
     'lbx',
     'bbx',
     'cbx',
@@ -62,7 +61,10 @@ window.ExposedSettings = {
     'lua',
     'gv',
     'mf',
+    'lhs',
+    'mk',
   ],
+  editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
 }
 
 window.i18n = { currentLangCode: 'en' }

+ 6 - 0
services/web/test/unit/src/Uploads/FileSystemImportManagerTests.js

@@ -28,6 +28,12 @@ describe('FileSystemImportManager', function () {
       requires: {
         '@overleaf/settings': {
           textExtensions: ['tex', 'txt'],
+          editableFilenames: [
+            'latexmkrc',
+            '.latexmkrc',
+            'makefile',
+            'gnumakefile',
+          ],
           fileIgnorePattern: Settings.fileIgnorePattern, // use the real pattern from the default settings
         },
         '../Editor/EditorController': this.EditorController,

+ 4 - 0
services/web/test/unit/src/Uploads/FileTypeManagerTests.js

@@ -90,6 +90,10 @@ describe('FileTypeManager', function () {
         '/file.m',
         '/something/file.m',
         '/file.TEX',
+        '/file.lhs',
+        '/makefile',
+        '/Makefile',
+        '/GNUMakefile',
       ]
       TEXT_FILENAMES.forEach(filename => {
         it(`should classify ${filename} as text`, function (done) {

+ 1 - 0
services/web/types/exposed-settings.ts

@@ -38,6 +38,7 @@ export type ExposedSettings = {
   sentryRelease?: string
   siteUrl: string
   textExtensions: string[]
+  editableFilenames: string[]
   validRootDocExtensions: string[]
   templateLinks?: TemplateLink[]
   labsEnabled: boolean