From 66cacf08daf6a03cb66288a2934803e1b66926e5 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 11 Aug 2017 15:21:26 +0200 Subject: [PATCH] allow users to write with tabs instead of spaces --- www/code/main.js | 21 +++++++++++++++------ www/settings/main.js | 37 +++++++++++++++++++++++++++++++++++++ www/settings/main.less | 3 +++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 36f734d0f..7ac345fb6 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -61,19 +61,28 @@ define([ $iframe.find('.CodeMirror').addClass('fullPage'); editor = CodeMirror.editor; - var setIndentation = APP.setIndentation = function (units) { + var setIndentation = APP.setIndentation = function (units, useTabs) { if (typeof(units) !== 'number') { return; } editor.setOption('indentUnit', units); editor.setOption('tabSize', units); - //editor.setOption('indentWithTabs', true); + editor.setOption('indentWithTabs', useTabs); }; var indentKey = 'cryptpad.indentUnit'; + var useTabsKey = 'cryptpad.indentWithTabs'; + var proxy = Cryptpad.getProxy(); - proxy.on('change', [indentKey], function (o, n) { - APP.setIndentation(n); - }); - setIndentation(proxy[indentKey]); + + var updateIndentSettings = function () { + var indentUnit = proxy[indentKey]; + var useTabs = proxy[useTabsKey]; + setIndentation( + typeof(indentUnit) === 'number'? indentUnit: 2, + typeof(useTabs) === 'boolean'? useTabs: false); + }; + + proxy.on('change', [indentKey], updateIndentSettings); + proxy.on('change', [useTabsKey], updateIndentSettings); var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); diff --git a/www/settings/main.js b/www/settings/main.js index 24978bf50..c36e6cf0c 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -51,6 +51,7 @@ define([ ], 'code': [ 'indentUnit', + 'indentType' ] }; @@ -163,6 +164,41 @@ define([ return $div; }; + var createIndentTypeSelector = function (obj) { + var proxy = obj.proxy; + + var key = 'cryptpad.indentWithTabs'; + + var $div = $('
', { + 'class': 'indentType element' + }); + $('