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 = {
|
||||
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())
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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}}',
|
||||
|
|
|
@ -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} />
|
||||
)}
|
||||
</>
|
||||
|
|
|
@ -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'],
|
||||
}
|
||||
|
||||
|
|
4
services/web/test/frontend/bootstrap.js
vendored
4
services/web/test/frontend/bootstrap.js
vendored
|
@ -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' }
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -38,6 +38,7 @@ export type ExposedSettings = {
|
|||
sentryRelease?: string
|
||||
siteUrl: string
|
||||
textExtensions: string[]
|
||||
editableFilenames: string[]
|
||||
validRootDocExtensions: string[]
|
||||
templateLinks?: TemplateLink[]
|
||||
labsEnabled: boolean
|
||||
|
|
Loading…
Reference in a new issue