Make autoCloseBrackets configurable per user

pull/1/head
yflory 5 years ago
parent 60afb3e811
commit e6eb3554d6

@ -379,13 +379,14 @@ define([
};
exp.mkIndentSettings = function (metadataMgr) {
var setIndentation = function (units, useTabs, fontSize, spellcheck) {
var setIndentation = function (units, useTabs, fontSize, spellcheck, brackets) {
if (typeof(units) !== 'number') { return; }
var doc = editor.getDoc();
editor.setOption('indentUnit', units);
editor.setOption('tabSize', units);
editor.setOption('indentWithTabs', useTabs);
editor.setOption('spellcheck', spellcheck);
editor.setOption('autoCloseBrackets', brackets);
editor.setOption("extraKeys", {
Tab: function() {
if (doc.somethingSelected()) {
@ -415,11 +416,13 @@ define([
var useTabs = data[useTabsKey];
var fontSize = data[fontKey];
var spellcheck = data[spellcheckKey];
var brackets = data.brackets;
setIndentation(
typeof(indentUnit) === 'number'? indentUnit : 2,
typeof(useTabs) === 'boolean'? useTabs : false,
typeof(fontSize) === 'number' ? fontSize : 12,
typeof(spellcheck) === 'boolean' ? spellcheck : false);
typeof(spellcheck) === 'boolean' ? spellcheck : false,
typeof(brackets) === 'boolean' ? brackets : true);
};
metadataMgr.onChangeLazy(updateIndentSettings);
updateIndentSettings();

@ -85,6 +85,7 @@ define([
'code': [
'cp-settings-code-indent-unit',
'cp-settings-code-indent-type',
'cp-settings-code-brackets',
'cp-settings-code-font-size',
'cp-settings-code-spellcheck',
],
@ -1445,6 +1446,35 @@ define([
return $div;
};
create['code-brackets'] = function () {
var key = 'brackets';
var $div = $('<div>', {
'class': 'cp-settings-code-brackets cp-sidebarlayout-element'
});
$('<label>').text(Messages.settings_codeBrackets).appendTo($div);
var $inputBlock = $('<div>', {
'class': 'cp-sidebarlayout-input-block',
}).css('flex-flow', 'column')
.appendTo($div);
var $cbox = $(UI.createCheckbox('cp-settings-codebrackets'));
var $checkbox = $cbox.find('input').on('change', function () {
var val = $checkbox.is(':checked');
if (typeof(val) !== 'boolean') { return; }
common.setAttribute(['codemirror', key], val);
});
$cbox.appendTo($inputBlock);
common.getAttribute(['codemirror', key], function (e, val) {
if (e) { return void console.error(e); }
$checkbox[0].checked = typeof(val) !== "boolean" || val;
});
return $div;
};
create['code-font-size'] = function () {
var key = 'fontSize';

Loading…
Cancel
Save