Skip to content

Commit 2216747

Browse files
committed
test: integ tests for auto tab space detection
1 parent 90fd553 commit 2216747

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

src/editor/Editor.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,9 @@ define(function (require, exports, module) {
25972597
computedValues.useTabChar = value;
25982598
// persist explicitly user set values to storage
25992599
tabSpacesStateManager.set(fullPath, computedValues);
2600+
Editor.forEveryEditor(editor=>{
2601+
editor._updateOption(USE_TAB_CHAR);
2602+
}, fullPath);
26002603
return true;
26012604
}
26022605
var options = fullPath && {context: fullPath};
@@ -2630,6 +2633,9 @@ define(function (require, exports, module) {
26302633
computedValues.tabSize = value;
26312634
// persist explicitly user set values to storage
26322635
tabSpacesStateManager.set(fullPath, computedValues);
2636+
Editor.forEveryEditor(editor=>{
2637+
editor._updateOption(TAB_SIZE);
2638+
}, fullPath);
26332639
}
26342640
return true;
26352641
}
@@ -2722,6 +2728,9 @@ define(function (require, exports, module) {
27222728
computedValues.spaceUnits = value;
27232729
// persist explicitly user set values to storage
27242730
tabSpacesStateManager.set(fullPath, computedValues);
2731+
Editor.forEveryEditor(editor=>{
2732+
editor._updateOption(SPACE_UNITS);
2733+
}, fullPath);
27252734
}
27262735
return true;
27272736
}
@@ -2847,11 +2856,19 @@ define(function (require, exports, module) {
28472856
};
28482857

28492858
/**
2850-
* Runs callback for every Editor instance that currently exists
2859+
* Runs callback for every Editor instance that currently exists or only the editors matching the given fullPath.
28512860
* @param {!function(!Editor)} callback
2861+
* @param {string} [fullPath] an optional second argument, if given will only callback for all editors
2862+
* that is editing the file for the given fullPath
28522863
*/
2853-
Editor.forEveryEditor = function (callback) {
2854-
_instances.forEach(callback);
2864+
Editor.forEveryEditor = function (callback, fullPath) {
2865+
_instances.forEach(function (editor) {
2866+
if(!fullPath) {
2867+
callback(editor);
2868+
} else if(editor.document.file.fullPath === fullPath) {
2869+
callback(editor);
2870+
}
2871+
});
28552872
};
28562873

28572874
/**

src/extensions/default/DebugCommands/MacroRunner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ define(function (require, exports, module) {
374374
Editor.Editor.setAutoTabSpaces(isAutoMode, fullPath);
375375
isAutoMode && Editor.Editor._autoDetectTabSpaces(activeEditor, true, true);
376376
}
377-
Editor.Editor.setUseTabChar(useTabs);
377+
Editor.Editor.setUseTabChar(useTabs, fullPath);
378378
if(useTabs) {
379-
Editor.Editor.setTabSize(spaceOrTabCount);
379+
Editor.Editor.setTabSize(spaceOrTabCount, fullPath);
380380
} else {
381-
Editor.Editor.setSpaceUnits(spaceOrTabCount);
381+
Editor.Editor.setSpaceUnits(spaceOrTabCount, fullPath);
382382
}
383383
}
384384
};

test/spec/spacing-auto-detect-integ-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,38 @@ define(function (require, exports, module) {
108108
validateSpacing("Tab Size:", "6", "Auto");
109109
await __PR.closeFile();
110110
});
111+
112+
it(`should switching to fixed mode default to 4 spaces for all files`, async function () {
113+
await __PR.openFile("tab-2.js");
114+
validateSpacing("Tab Size:", "2", "Auto");
115+
$("#indent-auto").click();
116+
validateSpacing("Spaces:", "4", "Fixed");
117+
await __PR.openFile("space-1.js");
118+
validateSpacing("Spaces:", "4", "Fixed");
119+
await __PR.closeFile();
120+
});
121+
122+
it(`should be able to change spacing/tabs settings of fixed mode`, async function () {
123+
await __PR.openFile("tab-2.js");
124+
// now change the fixed width
125+
__PR.EDITING.setEditorSpacing(true, 6, false);
126+
validateSpacing("Tab Size:", "6", "Fixed");
127+
await __PR.openFile("space-12.js");
128+
validateSpacing("Tab Size:", "6", "Fixed");
129+
// revert back to defaults
130+
__PR.EDITING.setEditorSpacing(false, 4, false);
131+
await __PR.closeFile();
132+
});
133+
134+
it(`should toggling auto mode recompute the spacing`, async function () {
135+
await __PR.openFile("tab-2.js");
136+
__PR.EDITING.setEditorSpacing(false, 3, true);
137+
validateSpacing("Spaces:", "3", "Auto");
138+
// now toggle the auto to fixed and then to auto once to force recompute spacing
139+
$("#indent-auto").click();
140+
$("#indent-auto").click();
141+
validateSpacing("Tab Size:", "2", "Auto");
142+
await __PR.closeFile();
143+
});
111144
});
112145
});

0 commit comments

Comments
 (0)