Skip to content

Commit

Permalink
Set file editor mode based on filename (#276)
Browse files Browse the repository at this point in the history
Replaces `CodeMirror.findModeByExtension` with `findModeByFileName` to
detect nginx config files properly. If `CodeMirror.findModeByFileName`
doesn't match anything it automatically tries to find a match via
`findModeByExtension`. If that fails to return info as well, we try to
determine a mode by calling `CodeMirror.findModeByMIME`.

This is the discussion + pr in the CodeMirror repo:
* codemirror/codemirror5#2940
* codemirror/codemirror5#3027

Fixes #187
  • Loading branch information
Marc-Andre Stoppert committed Oct 12, 2020
1 parent d0c5974 commit 37e18d4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions resources/js/store/modules/FileEditor.js
Expand Up @@ -101,12 +101,10 @@ export default {
commit('setTheme', theme);
},
async setMode({ commit }, value) {
const filename = (/.+\.(?<ext>[^.]+)$/u).exec(value);
let mode = '';

const info = filename
? CodeMirror.findModeByExtension(filename.groups.ext)
: CodeMirror.findModeByMIME(value);
const info = CodeMirror.findModeByFileName(value)
?? CodeMirror.findModeByMIME(value);

if (info) {
({ mode } = info);
Expand Down

0 comments on commit 37e18d4

Please sign in to comment.