diff --git a/www/code/main.js b/www/code/main.js index 7591f12a2..69c2dbc89 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -61,6 +61,20 @@ define([ $iframe.find('.CodeMirror').addClass('fullPage'); editor = CodeMirror.editor; + var setIndentation = APP.setIndentation = function (units) { + if (typeof(units) !== 'number') { return; } + editor.setOption('indentUnit', units); + editor.setOption('tabSize', units); + //editor.setOption('indentWithTabs', true); + }; + + var indentKey = 'cryptpad.indentUnit'; + var proxy = Cryptpad.getProxy(); + proxy.on('change', [indentKey], function (o, n) { + APP.setIndentation(n); + }); + setIndentation(proxy[indentKey]); + var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); var isHistoryMode = false; diff --git a/www/settings/main.js b/www/settings/main.js index 11ec267eb..24db12a81 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -39,6 +39,7 @@ define([ 'account': [ 'infoBlock', 'displayName', + 'indentUnit', 'languageSelector', 'logoutEverywhere', 'resetTips', @@ -125,6 +126,42 @@ define([ return $div; }; + var createIndentUnitSelector = function (obj) { + var proxy = obj.proxy; + + console.log('create indent unit selector'); + var $div = $('
', { + 'class': 'indentUnit element' + }); + + var $inputBlock = $('
', { + 'class': 'inputBlock', + }).appendTo($div); + + var $input = $('', { + 'min': 1, + 'max': 8, + type: 'number', + }).on('change', function () { + var val = parseInt($input.val()); + console.log(val, typeof(val)); + if (typeof(val) !== 'number') { return; } + proxy['cryptpad.indentUnit'] = val; + }).appendTo($inputBlock); + + proxy.on('change', [ 'cryptpad.indentUnit', ], function (o, n) { $input.val(n); }); + + Cryptpad.getAttribute('indentUnit', function (e, val) { + if (e) { return void console.error(e); } + if (typeof(val) !== 'number') { + $input.val(2); + } else { + $input.val(val); + } + }); + return $div; + }; + var createResetTips = function () { var $div = $('
', {'class': 'resetTips element'}); $('