allow users to write with tabs instead of spaces

pull/1/head
ansuz 7 years ago
parent 64849507b3
commit 66cacf08da

@ -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');

@ -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 = $('<div>', {
'class': 'indentType element'
});
$('<label>').text(Messages.settings_codeUseTabs).appendTo($div);
var $inputBlock = $('<div>', {
'class': 'inputBlock',
}).appendTo($div);
var $input = $('<input>', {
type: 'checkbox',
}).on('change', function () {
var val = $input.is(':checked');
if (typeof(val) !== 'boolean') { return; }
proxy[key] = val;
}).appendTo($inputBlock);
proxy.on('change', [key], 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 = $('<div>', {'class': 'resetTips element'});
$('<label>', {'for' : 'resetTips'}).text(Messages.settings_resetTips).appendTo($div);
@ -423,6 +459,7 @@ define([
$rightside.append(createDisplayNameInput(obj));
$rightside.append(createLanguageSelector());
$rightside.append(createIndentUnitSelector(obj));
$rightside.append(createIndentTypeSelector(obj));
if (Cryptpad.isLoggedIn()) {
$rightside.append(createLogoutEverywhere(obj));

@ -31,6 +31,9 @@
&[type="number"] {
border-right: 1px solid #adadad;
}
&[type="checkbox"] {
margin-right: 100%;
}
}
}
.infoBlock {

Loading…
Cancel
Save