From 5b79775810a23cda4382589f45f915a3d7e67546 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 23 Jun 2016 16:37:51 +0200 Subject: [PATCH] infer modes from MIME types --- www/code/main.js | 27 ++++++++++++++++++++++----- www/code/modes.js | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 89d29e8e6..f0354292c 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -52,6 +52,10 @@ define([ }); var setMode = module.setMode = function (mode) { + if (mode === 'text') { + editor.setOption('mode', 'text'); + return; + } CodeMirror.autoLoadMode(editor, mode); editor.setOption('mode', mode); }; @@ -155,9 +159,22 @@ define([ $bar.find('#cryptpad-saveContent').click(exportText); $bar.find('#cryptpad-loadContent') - .click(Cryptpad.importContent('text/plain', function (content) { + .click(Cryptpad.importContent('text/plain', function (content, file) { + var mime = CodeMirror.findModeByMIME(file.type); + + var mode = mime && mime.mode || null; + + if (Modes.some(function (o) { return o.mode === mode; })) { + setMode(mode); + $bar.find('#language-mode').val(mode); + } else { + console.log("Couldn't find a suitable highlighting mode: %s", mode); + setMode('text'); + $bar.find('#language-mode').val('text'); + } + editor.setValue(content); - config.onLocal(); + onLocal(); })); var dropdown = '