Skip to content
This repository
Browse code

save indentation preferences. add new default prefs when missing

  • Loading branch information...
commit 03b949b74e4d1beca1260b15e1f08cbd55c8dd08 1 parent 6f38c6a
Jason San Jose jasonsanjose authored
35 src/editor/EditorManager.js
@@ -588,30 +588,24 @@ define(function (require, exports, module) {
588 588 $fileInfo.text(StringUtils.format(Strings.STATUSBAR_LINE_COUNT, editor.lineCount()));
589 589 }
590 590
591   - function _updateIndentInfo(editor) {
592   - var indentWithTabs = editor._codeMirror.getOption("indentWithTabs");
  591 + function _updateIndentType() {
  592 + var indentWithTabs = Editor.getUseTabChar();
593 593 $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES);
594 594 $indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS);
595   -
596   - $indentWidth.text(editor._codeMirror.getOption("tabSize"));
  595 + }
  596 +
  597 + function _updateIndentSize(inc) {
  598 + $indentWidth.text(Editor.getTabSize());
597 599 }
598 600
599 601 function _toggleIndentType() {
600   - var editor = getFocusedEditor(),
601   - indentWithTabs = editor._codeMirror.getOption("indentWithTabs");
602   -
603   - editor._codeMirror.setOption("indentWithTabs", !indentWithTabs);
604   -
605   - _updateIndentInfo(editor);
  602 + Editor.setUseTabChar(!Editor.getUseTabChar());
  603 + _updateIndentType();
606 604 }
607 605
608   - function _updateIndentSize(inc) {
609   - var editor = getFocusedEditor(),
610   - size = editor._codeMirror.getOption("tabSize");
611   -
612   - editor._codeMirror.setOption("tabSize", size + inc);
613   -
614   - _updateIndentInfo(editor);
  606 + function _changeIndentSize(inc) {
  607 + Editor.setTabSize(Editor.getTabSize() + inc);
  608 + _updateIndentSize();
615 609 }
616 610
617 611 function _updateCursorInfo(event, editor) {
@@ -643,7 +637,8 @@ define(function (require, exports, module) {
643 637 _updateCursorInfo(null, current);
644 638 _updateModeInfo(current);
645 639 _updateFileInfo(current);
646   - _updateIndentInfo(current);
  640 + _updateIndentType();
  641 + _updateIndentSize();
647 642 }
648 643 }
649 644
@@ -672,8 +667,8 @@ define(function (require, exports, module) {
672 667
673 668 // indentation event handlers
674 669 $indentType.on("click", _toggleIndentType);
675   - $indentDecrement.on("click", function () { _updateIndentSize(-1); });
676   - $indentIncrement.on("click", function () { _updateIndentSize(1); });
  670 + $indentDecrement.on("click", function () { _changeIndentSize(-1); });
  671 + $indentIncrement.on("click", function () { _changeIndentSize(1); });
677 672
678 673 StatusBar.hide();
679 674 _onFocusedEditorChange(null, getFocusedEditor(), null);
7 src/preferences/PreferencesManager.js
@@ -60,6 +60,13 @@ define(function (require, exports, module) {
60 60 // create a new empty preferences object
61 61 prefs = (defaults && JSON.stringify(defaults)) ? defaults : {};
62 62 prefStorage[clientID] = prefs;
  63 + } else if (defaults) {
  64 + // add new defaults
  65 + Object.keys(defaults).forEach(function (key) {
  66 + if (prefs[key] === undefined) {
  67 + prefs[key] = defaults[key];
  68 + }
  69 + });
63 70 }
64 71
65 72 return new PreferenceStorage(clientID, prefs);

0 comments on commit 03b949b

Please sign in to comment.
Something went wrong with that request. Please try again.