mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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
This commit is contained in:
parent
04a4450341
commit
d378246468
9 changed files with 36 additions and 9 deletions
|
@ -13,6 +13,7 @@ const fileIgnoreMatcher = new Minimatch(Settings.fileIgnorePattern, {
|
||||||
|
|
||||||
const FileTypeManager = {
|
const FileTypeManager = {
|
||||||
TEXT_EXTENSIONS: new Set(Settings.textExtensions.map(ext => `.${ext}`)),
|
TEXT_EXTENSIONS: new Set(Settings.textExtensions.map(ext => `.${ext}`)),
|
||||||
|
EDITABLE_FILENAMES: Settings.editableFilenames,
|
||||||
|
|
||||||
MAX_TEXT_FILE_SIZE: 1 * 1024 * 1024, // 1 MB
|
MAX_TEXT_FILE_SIZE: 1 * 1024 * 1024, // 1 MB
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ function _isTextFilename(filename) {
|
||||||
const extension = Path.extname(filename).toLowerCase()
|
const extension = Path.extname(filename).toLowerCase()
|
||||||
return (
|
return (
|
||||||
FileTypeManager.TEXT_EXTENSIONS.has(extension) ||
|
FileTypeManager.TEXT_EXTENSIONS.has(extension) ||
|
||||||
filename.match(/^(\.)?latexmkrc$/)
|
FileTypeManager.EDITABLE_FILENAMES.includes(filename.toLowerCase())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -397,6 +397,7 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
|
||||||
recaptchaSiteKeyV3: Settings.recaptcha?.siteKeyV3,
|
recaptchaSiteKeyV3: Settings.recaptcha?.siteKeyV3,
|
||||||
recaptchaDisabled: Settings.recaptcha?.disabled,
|
recaptchaDisabled: Settings.recaptcha?.disabled,
|
||||||
textExtensions: Settings.textExtensions,
|
textExtensions: Settings.textExtensions,
|
||||||
|
editableFilenames: Settings.editableFilenames,
|
||||||
validRootDocExtensions: Settings.validRootDocExtensions,
|
validRootDocExtensions: Settings.validRootDocExtensions,
|
||||||
sentryAllowedOriginRegex: Settings.sentry.allowedOriginRegex,
|
sentryAllowedOriginRegex: Settings.sentry.allowedOriginRegex,
|
||||||
sentryDsn: Settings.sentry.publicDSN,
|
sentryDsn: Settings.sentry.publicDSN,
|
||||||
|
|
|
@ -44,7 +44,6 @@ const defaultTextExtensions = [
|
||||||
'rtex',
|
'rtex',
|
||||||
'md',
|
'md',
|
||||||
'asy',
|
'asy',
|
||||||
'latexmkrc',
|
|
||||||
'lbx',
|
'lbx',
|
||||||
'bbx',
|
'bbx',
|
||||||
'cbx',
|
'cbx',
|
||||||
|
@ -62,6 +61,8 @@ const defaultTextExtensions = [
|
||||||
'mf',
|
'mf',
|
||||||
'yml',
|
'yml',
|
||||||
'yaml',
|
'yaml',
|
||||||
|
'lhs',
|
||||||
|
'mk',
|
||||||
]
|
]
|
||||||
|
|
||||||
const parseTextExtensions = function (extensions) {
|
const parseTextExtensions = function (extensions) {
|
||||||
|
@ -676,6 +677,9 @@ module.exports = {
|
||||||
parseTextExtensions(process.env.ADDITIONAL_TEXT_EXTENSIONS)
|
parseTextExtensions(process.env.ADDITIONAL_TEXT_EXTENSIONS)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// case-insensitive file names that is editable (doc) in the editor
|
||||||
|
editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
|
||||||
|
|
||||||
fileIgnorePattern:
|
fileIgnorePattern:
|
||||||
process.env.FILE_IGNORE_PATTERN ||
|
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}}',
|
'**/{{__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}}',
|
||||||
|
|
|
@ -15,11 +15,17 @@ export default function FileView({ file }) {
|
||||||
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const { textExtensions } = window.ExposedSettings
|
const { textExtensions, editableFilenames } = window.ExposedSettings
|
||||||
|
|
||||||
const extension = file.name.split('.').pop().toLowerCase()
|
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(() => {
|
const handleLoad = useCallback(() => {
|
||||||
setContentLoading(false)
|
setContentLoading(false)
|
||||||
|
@ -35,7 +41,7 @@ export default function FileView({ file }) {
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
<FileViewHeader file={file} />
|
<FileViewHeader file={file} />
|
||||||
{imageExtensions.includes(extension) && (
|
{isImageFile && (
|
||||||
<FileViewImage
|
<FileViewImage
|
||||||
fileName={file.name}
|
fileName={file.name}
|
||||||
fileId={file.id}
|
fileId={file.id}
|
||||||
|
@ -43,7 +49,7 @@ export default function FileView({ file }) {
|
||||||
onError={handleError}
|
onError={handleError}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{textExtensions.includes(extension) && (
|
{isEditableTextFile && (
|
||||||
<FileViewText file={file} onLoad={handleLoad} onError={handleError} />
|
<FileViewText file={file} onLoad={handleLoad} onError={handleError} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -168,7 +168,6 @@ const initialize = () => {
|
||||||
'rtex',
|
'rtex',
|
||||||
'md',
|
'md',
|
||||||
'asy',
|
'asy',
|
||||||
'latexmkrc',
|
|
||||||
'lbx',
|
'lbx',
|
||||||
'bbx',
|
'bbx',
|
||||||
'cbx',
|
'cbx',
|
||||||
|
@ -184,7 +183,10 @@ const initialize = () => {
|
||||||
'lua',
|
'lua',
|
||||||
'gv',
|
'gv',
|
||||||
'mf',
|
'mf',
|
||||||
|
'lhs',
|
||||||
|
'mk',
|
||||||
],
|
],
|
||||||
|
editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
|
||||||
validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'],
|
validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
services/web/test/frontend/bootstrap.js
vendored
4
services/web/test/frontend/bootstrap.js
vendored
|
@ -46,7 +46,6 @@ window.ExposedSettings = {
|
||||||
'rtex',
|
'rtex',
|
||||||
'md',
|
'md',
|
||||||
'asy',
|
'asy',
|
||||||
'latexmkrc',
|
|
||||||
'lbx',
|
'lbx',
|
||||||
'bbx',
|
'bbx',
|
||||||
'cbx',
|
'cbx',
|
||||||
|
@ -62,7 +61,10 @@ window.ExposedSettings = {
|
||||||
'lua',
|
'lua',
|
||||||
'gv',
|
'gv',
|
||||||
'mf',
|
'mf',
|
||||||
|
'lhs',
|
||||||
|
'mk',
|
||||||
],
|
],
|
||||||
|
editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
|
||||||
}
|
}
|
||||||
|
|
||||||
window.i18n = { currentLangCode: 'en' }
|
window.i18n = { currentLangCode: 'en' }
|
||||||
|
|
|
@ -28,6 +28,12 @@ describe('FileSystemImportManager', function () {
|
||||||
requires: {
|
requires: {
|
||||||
'@overleaf/settings': {
|
'@overleaf/settings': {
|
||||||
textExtensions: ['tex', 'txt'],
|
textExtensions: ['tex', 'txt'],
|
||||||
|
editableFilenames: [
|
||||||
|
'latexmkrc',
|
||||||
|
'.latexmkrc',
|
||||||
|
'makefile',
|
||||||
|
'gnumakefile',
|
||||||
|
],
|
||||||
fileIgnorePattern: Settings.fileIgnorePattern, // use the real pattern from the default settings
|
fileIgnorePattern: Settings.fileIgnorePattern, // use the real pattern from the default settings
|
||||||
},
|
},
|
||||||
'../Editor/EditorController': this.EditorController,
|
'../Editor/EditorController': this.EditorController,
|
||||||
|
|
|
@ -90,6 +90,10 @@ describe('FileTypeManager', function () {
|
||||||
'/file.m',
|
'/file.m',
|
||||||
'/something/file.m',
|
'/something/file.m',
|
||||||
'/file.TEX',
|
'/file.TEX',
|
||||||
|
'/file.lhs',
|
||||||
|
'/makefile',
|
||||||
|
'/Makefile',
|
||||||
|
'/GNUMakefile',
|
||||||
]
|
]
|
||||||
TEXT_FILENAMES.forEach(filename => {
|
TEXT_FILENAMES.forEach(filename => {
|
||||||
it(`should classify ${filename} as text`, function (done) {
|
it(`should classify ${filename} as text`, function (done) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ export type ExposedSettings = {
|
||||||
sentryRelease?: string
|
sentryRelease?: string
|
||||||
siteUrl: string
|
siteUrl: string
|
||||||
textExtensions: string[]
|
textExtensions: string[]
|
||||||
|
editableFilenames: string[]
|
||||||
validRootDocExtensions: string[]
|
validRootDocExtensions: string[]
|
||||||
templateLinks?: TemplateLink[]
|
templateLinks?: TemplateLink[]
|
||||||
labsEnabled: boolean
|
labsEnabled: boolean
|
||||||
|
|
Loading…
Reference in a new issue