Skip to content

Commit 7a46058

Browse files
committed
MB-33359 - Fix query formatting issue with undefined tab spacing.
Change-Id: I44397c4f504c7722a386b9116e02e74331327380 Reviewed-on: http://review.couchbase.org/106394 Reviewed-by: Eben Haber <[email protected]> Tested-by: Eben Haber <[email protected]>
1 parent 1b8fe6d commit 7a46058

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

priv/public/ui/libs/ace/query-formatter.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,20 @@
7070
// calls, e.g. max(a,b,c)
7171
//
7272

73-
function replace_top_level_commas(text,tab,parenDepth) {
73+
function replace_top_level_commas(text,parenDepth) {
7474
var items = [];
7575
var start = 0;
76-
var indent = tab;
7776

7877
for (var i=0; i < text.length; i++) {
7978
switch (text.charAt(i)) {
80-
case '(': parenDepth.depth++; break;
81-
case ')': parenDepth.depth--; break;
79+
case '(':
80+
case '{':
81+
case '[':
82+
parenDepth.depth++; break;
83+
case ')':
84+
case '}':
85+
case ']':
86+
parenDepth.depth--; break;
8287
case ',':
8388
if (parenDepth.depth <= 0) {
8489
items.push(text.substring(start,i+1));
@@ -91,7 +96,7 @@
9196
}
9297

9398
// get the last one
94-
items.push((items.length ? indent : '') + text.substring(start,text.length));
99+
items.push(text.substring(start,text.length));
95100
return(items);
96101
}
97102

@@ -118,7 +123,7 @@
118123

119124
arr.forEach(function (s) {
120125
var parenDepth = {depth:0};
121-
arr2 = arr2.concat(replace_top_level_commas(s,tab,parenDepth));
126+
arr2 = arr2.concat(replace_top_level_commas(s,parenDepth));
122127
});
123128

124129
return(arr2);
@@ -127,7 +132,7 @@
127132
// function to format queries based on the parameters above
128133

129134
var formatter = function(text, step) {
130-
var tab = this.step,
135+
var tab = ' '.repeat(step),
131136
ar,
132137
deep = 0,
133138
paren_level = 0,

0 commit comments

Comments
 (0)