forked from adobe/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLUtils.js
More file actions
585 lines (519 loc) · 26.5 KB
/
HTMLUtils.js
File metadata and controls
585 lines (519 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/*
* Copyright (c) 2012 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
define(function (require, exports, module) {
"use strict";
var CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"),
TokenUtils = require("utils/TokenUtils");
// Constants
var TAG_NAME = "tagName",
CLOSING_TAG = "closingTag",
ATTR_NAME = "attr.name",
ATTR_VALUE = "attr.value";
// Regular expression for token types with "tag" prefixed
var tagPrefixedRegExp = /^tag/;
/**
* @private
* Sometimes as attr values are getting typed, if the quotes aren't balanced yet
* some extra 'non attribute value' text gets included in the token. This attempts
* to assure the attribute value we grab is always good
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
* @return { val:{string}, offset:{number}}
*/
function _extractAttrVal(ctx) {
var attrValue = ctx.token.string,
startChar = attrValue.charAt(0),
endChar = attrValue.charAt(attrValue.length - 1),
offset = TokenUtils.offsetInToken(ctx),
foundEqualSign = false;
//If this is a fully quoted value, return the whole
//thing regardless of position
if (attrValue.length > 1 &&
(startChar === "'" || startChar === '"') &&
endChar === startChar) {
// Find an equal sign before the end quote. If found,
// then the user may be entering an attribute value right before
// another attribute and we're getting a false balanced string.
// An example of this case is <link rel" href="foo"> where the
// cursor is right after the first double quote.
foundEqualSign = (attrValue.match(/\=\s*['"]$/) !== null);
if (!foundEqualSign) {
//strip the quotes and return;
attrValue = attrValue.substring(1, attrValue.length - 1);
offset = offset - 1 > attrValue.length ? attrValue.length : offset - 1;
return {val: attrValue, offset: offset, quoteChar: startChar, hasEndQuote: true};
}
}
if (foundEqualSign) {
var spaceIndex = attrValue.indexOf(" "),
bracketIndex = attrValue.indexOf(">"),
upToIndex = (spaceIndex !== -1 && spaceIndex < bracketIndex) ? spaceIndex : bracketIndex;
attrValue = attrValue.substring(0, (upToIndex > offset) ? upToIndex : offset);
} else if (offset > 0 && (startChar === "'" || startChar === '"')) {
//The att value is getting edit in progress. There is possible extra
//stuff in this token state since the quote isn't closed, so we assume
//the stuff from the quote to the current pos is definitely in the attribute
//value.
attrValue = attrValue.substring(0, offset);
}
//If the attrValue start with a quote, trim that now
startChar = attrValue.charAt(0);
if (startChar === "'" || startChar === '"') {
attrValue = attrValue.substring(1);
offset--;
} else {
startChar = "";
// Make attr value empty and set offset to zero if it has the ">"
// which is the closing of the tag.
if (endChar === ">") {
attrValue = "";
offset = 0;
}
}
return {val: attrValue, offset: offset, quoteChar: startChar, hasEndQuote: false};
}
/**
* @private
* Gets the tagname from where ever you are in the currect state
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
* @return {string}
*/
function _extractTagName(ctx) {
var mode = ctx.editor.getMode(),
innerModeData = CodeMirror.innerMode(mode, ctx.token.state);
if (ctx.token.type === "tag bracket") {
return innerModeData.state.tagName;
}
// If the ctx is inside the tag name of an end tag, innerModeData.state.tagName is
// undefined. So return token string as the tag name.
return innerModeData.state.tagName || ctx.token.string;
}
/**
* Compiles a list of used attributes for a given tag
* @param {CodeMirror} editor An instance of a CodeMirror editor
* @param {ch:{string}, line:{number}} pos A CodeMirror position
* @return {Array.<string>} A list of the used attributes inside the current tag
*/
function getTagAttributes(editor, pos) {
var attrs = [],
backwardCtx = TokenUtils.getInitialContext(editor._codeMirror, pos),
forwardCtx = $.extend({}, backwardCtx);
if (editor.getModeForSelection() === "html") {
if (backwardCtx.token && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
while (TokenUtils.movePrevToken(backwardCtx) && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
if (backwardCtx.token.type === "error" && backwardCtx.token.string.indexOf("<") === 0) {
break;
}
if (backwardCtx.token.type === "attribute") {
attrs.push(backwardCtx.token.string);
}
}
while (TokenUtils.moveNextToken(forwardCtx) && !tagPrefixedRegExp.test(forwardCtx.token.type)) {
if (forwardCtx.token.type === "attribute") {
// If the current tag is not closed, codemirror may return the next opening
// tag as an attribute. Stop the search loop in that case.
if (forwardCtx.token.string.indexOf("<") === 0) {
break;
}
attrs.push(forwardCtx.token.string);
} else if (forwardCtx.token.type === "error") {
if (forwardCtx.token.string.indexOf("<") === 0 || forwardCtx.token.string.indexOf(">") === 0) {
break;
}
// If we type the first letter of the next attribute, it comes as an error
// token. We need to double check for possible invalidated attributes.
if (/\S/.test(forwardCtx.token.string) &&
forwardCtx.token.string.indexOf("\"") === -1 &&
forwardCtx.token.string.indexOf("'") === -1 &&
forwardCtx.token.string.indexOf("=") === -1) {
attrs.push(forwardCtx.token.string);
}
}
}
}
}
return attrs;
}
/**
* Creates a tagInfo object and assures all the values are entered or are empty strings
* @param {string=} tokenType what is getting edited and should be hinted
* @param {number=} offset where the cursor is for the part getting hinted
* @param {string=} tagName The name of the tag
* @param {string=} attrName The name of the attribute
* @param {string=} attrValue The value of the attribute
* @return {{tagName:string,
* attr:{name:string, value:string, valueAssigned:boolean, quoteChar:string, hasEndQuote:boolean},
* position:{tokenType:string, offset:number}
* }}
* A tagInfo object with some context about the current tag hint.
*/
function createTagInfo(tokenType, offset, tagName, attrName, attrValue, valueAssigned, quoteChar, hasEndQuote) {
return { tagName: tagName || "",
attr:
{ name: attrName || "",
value: attrValue || "",
valueAssigned: valueAssigned || false,
quoteChar: quoteChar || "",
hasEndQuote: hasEndQuote || false },
position:
{ tokenType: tokenType || "",
offset: offset || 0 } };
}
/**
* @private
* Gets the taginfo starting from the attribute value and moving backwards
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
* @return {string}
*/
function _getTagInfoStartingFromAttrValue(ctx) {
// Assume we in the attr value
// and validate that by going backwards
var attrInfo = _extractAttrVal(ctx),
attrVal = attrInfo.val,
offset = attrInfo.offset,
quoteChar = attrInfo.quoteChar,
hasEndQuote = attrInfo.hasEndQuote,
strLength = ctx.token.string.length;
if ((ctx.token.type === "string" || ctx.token.type === "error") &&
ctx.pos.ch === ctx.token.end && strLength > 1) {
var firstChar = ctx.token.string[0],
lastChar = ctx.token.string[strLength - 1];
// We get here only when the cursor is immediately on the right of the end quote
// of an attribute value. So we want to return an empty tag info so that the caller
// can dismiss the code hint popup if it is still open.
if (firstChar === lastChar && (firstChar === "'" || firstChar === "\"")) {
return createTagInfo();
}
}
//Skip all the 'string' tokens backwards. Required to reach to the first line
//of multiline HTML attribute value.
while (TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctx)) {
if (ctx.token.type !== "string") {
break;
}
}
//As we have skipped all the string tokens, make a forward navigation to move to the
//first 'string token so that in next backward navigation we can find '='.
TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx);
//Move to the prev token, and check if it's "="
if (!TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctx) || ctx.token.string !== "=") {
return createTagInfo();
}
//Move to the prev token, and check if it's an attribute
if (!TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctx) || ctx.token.type !== "attribute") {
return createTagInfo();
}
var attrName = ctx.token.string;
var tagName = _extractTagName(ctx);
//We're good.
return createTagInfo(ATTR_VALUE, offset, tagName, attrName, attrVal, true, quoteChar, hasEndQuote);
}
/**
* @private
* Gets the taginfo starting from the attribute name and moving forwards
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
* @param {boolean} isPriorAttr indicates whether we're getting info for a prior attribute
* @return {string}
*/
function _getTagInfoStartingFromAttrName(ctx, isPriorAttr) {
//Verify We're in the attribute name, move forward and try to extract the rest of
//the info. If the user it typing the attr the rest might not be here
if (isPriorAttr === false && ctx.token.type !== "attribute") {
return createTagInfo();
}
var tagName = _extractTagName(ctx);
var attrName = ctx.token.string;
var offset = TokenUtils.offsetInToken(ctx);
if (!TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx) || ctx.token.string !== "=") {
// If we're checking for a prior attribute and the next token we get is a tag or an html comment or
// an undefined token class, then we've already scanned past our original cursor location.
// So just return an empty tag info.
if (isPriorAttr &&
(!ctx.token.type ||
(ctx.token.type && ctx.token.type !== "attribute" &&
ctx.token.type.indexOf("error") === -1 &&
ctx.token.string.indexOf("<") !== -1))) {
return createTagInfo();
}
return createTagInfo(ATTR_NAME, offset, tagName, attrName);
}
if (!TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx)) {
return createTagInfo(ATTR_NAME, offset, tagName, attrName);
}
//this should be the attrvalue
var attrInfo = _extractAttrVal(ctx),
attrVal = attrInfo.val,
quoteChar = attrInfo.quoteChar,
hasEndQuote = attrInfo.hasEndQuote;
return createTagInfo(ATTR_NAME, offset, tagName, attrName, attrVal, true, quoteChar, hasEndQuote);
}
/**
* Figure out if we're in a tag, and if we are return info about it
* An example token stream for this tag is <span id="open-files-disclosure-arrow"></span> :
* className:tag string:"<span"
* className: string:" "
* className:attribute string:"id"
* className: string:"="
* className:string string:""open-files-disclosure-arrow""
* className:tag string:"></span>"
* @param {Editor} editor An instance of a Brackets editor
* @param {{ch: number, line: number}} constPos A CM pos (likely from editor.getCursorPos())
* @param {isHtmlMode:boolean} let the module know we are in html mode
* @return {{tagName:string,
* attr:{name:string, value:string, valueAssigned:boolean, quoteChar:string, hasEndQuote:boolean},
* position:{tokenType:string, offset:number}
* }}
* A tagInfo object with some context about the current tag hint.
*/
function getTagInfo(editor, constPos, isHtmlMode) {
// We're going to be changing pos a lot, but we don't want to mess up
// the pos the caller passed in so we use extend to make a safe copy of it.
var pos = $.extend({}, constPos),
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos),
offset = TokenUtils.offsetInToken(ctx),
tagInfo,
tokenType;
// Check if this is not known to be in html mode and inside a style block.
if (!isHtmlMode && editor.getModeForSelection() !== "html") {
return createTagInfo();
}
// Check and see where we are in the tag
if (ctx.token.string.length > 0 && !/\S/.test(ctx.token.string)) {
// token at (i.e. before) pos is whitespace, so test token at next pos
//
// note: getTokenAt() does range checking for ch. If it detects that ch is past
// EOL, it uses EOL, same token is returned, and the following condition fails,
// so we don't need to worry about testPos being valid.
var testPos = {ch: ctx.pos.ch + 1, line: ctx.pos.line},
testToken = editor._codeMirror.getTokenAt(testPos, true);
if (testToken.string.length > 0 && /\S/.test(testToken.string) &&
testToken.string.charAt(0) !== ">") {
// pos has whitespace before it and non-whitespace after it, so use token after
ctx.token = testToken;
// Check whether the token type is one of the types prefixed with "tag"
// (e.g. "tag", "tag error", "tag brackets")
if (tagPrefixedRegExp.test(ctx.token.type)) {
// Check to see if the cursor is just before a "<" but not in any tag.
if (ctx.token.string.charAt(0) === "<") {
return createTagInfo();
}
} else if (ctx.token.type === "attribute") {
// Check to see if the user is going to add a new attr before an existing one
return _getTagInfoStartingFromAttrName(ctx, false);
} else if (ctx.token.string === "=") {
// We're between a whitespace and "=", so return an empty tag info.
return createTagInfo();
}
} else {
// We get here if ">" or white spaces after testPos.
// Check if there is an equal sign after testPos by creating a new ctx
// with the original pos. We can't use the current ctx since we need to
// use it to scan backwards if we don't find an equal sign here.
// Comment out this block to fix issue #1510.
// if (testToken.string.length > 0 && testToken.string.charAt(0) !== ">") {
// tempCtx = TokenUtils.getInitialContext(editor._codeMirror, pos);
// if (TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, tempCtx) && tempCtx.token.string === "=") {
// // Return an empty tag info since we're between an atribute name and the equal sign.
// return createTagInfo();
// }
// }
// next, see what's before pos
if (!TokenUtils.movePrevToken(ctx)) {
return createTagInfo();
}
if (ctx.token.type === "comment") {
return createTagInfo();
} else if (!tagPrefixedRegExp.test(ctx.token.type) && ctx.token.string !== "=") {
// If it wasn't the tag name, assume it was an attr value
// Also we don't handle the "=" here.
tagInfo = _getTagInfoStartingFromAttrValue(ctx);
// Check to see if this is the closing of a tag (either the start or end)
// or a comment tag.
if (ctx.token.type === "comment" ||
(tagPrefixedRegExp.test(ctx.token.type) &&
(ctx.token.string === ">" || ctx.token.string === "/>" ||
ctx.token.string === "</"))) {
return createTagInfo();
}
// If it wasn't an attr value, assume it was an empty attr (ie. attr with no value)
if (!tagInfo.tagName) {
tagInfo = _getTagInfoStartingFromAttrName(ctx, true);
}
// We don't want to give context for the previous attr
// and we want it to look like the user is going to add a new attr
if (tagInfo.tagName) {
return createTagInfo(ATTR_NAME, 0, tagInfo.tagName);
}
return createTagInfo();
}
// We know the tag was here, so the user is adding an attr name
tokenType = ATTR_NAME;
offset = 0;
}
}
if (tagPrefixedRegExp.test(ctx.token.type)) {
if (ctx.token.type !== "tag bracket") {
// Check if the user just typed a white space after "<" that made an existing tag invalid.
if (TokenUtils.movePrevToken(ctx) && !/\S/.test(ctx.token.string)) {
return createTagInfo();
}
// Check to see if this is a closing tag
if (ctx.token.type === "tag bracket" && ctx.token.string === "</") {
tokenType = CLOSING_TAG;
}
// Restore the original ctx by moving back to next context since we call
// movePrevToken above to detect "<" or "</".
TokenUtils.moveNextToken(ctx);
}
// Check to see if this is the closing of a start tag or a self closing tag
if (ctx.token.string === ">" || ctx.token.string === "/>") {
return createTagInfo();
}
// Make sure the cursor is not after an equal sign or a quote before we report the context as a tag.
if (ctx.token.string !== "=" && ctx.token.string.match(/^["']/) === null) {
if (!tokenType) {
tokenType = TAG_NAME;
if (ctx.token.type === "tag bracket") {
// Check to see if this is a closing tag
if (ctx.token.string === "</") {
tokenType = CLOSING_TAG;
offset -= 2;
} else {
offset = 0;
}
// If the cursor is right after the "<" or "</", then
// move context to next one so that _extractTagName
// call below can get the tag name if there is one.
if (offset === 0) {
TokenUtils.moveNextToken(ctx);
}
}
}
// We're actually in the tag, just return that as we have no relevant
// info about what attr is selected
return createTagInfo(tokenType, offset, _extractTagName(ctx));
}
}
if (ctx.token.string === "=") {
// We could be between the attr and the value
// Step back and check
if (!TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctx) || ctx.token.type !== "attribute") {
return createTagInfo();
}
// The "=" is added, time to hint for values
tokenType = ATTR_VALUE;
offset = 0;
}
if (ctx.token.type === "attribute") {
tagInfo = _getTagInfoStartingFromAttrName(ctx, false);
// If we're in attr value, then we may need to calculate the correct offset
// from the beginning of the attribute value. If the cursor position is to
// the left of attr value, then the offset is negative.
// e.g. if the cursor is just to the right of the "=" in <a rel= "rtl", then
// the offset will be -2.
if (tagInfo.attr.quoteChar) {
offset = constPos.ch - ctx.pos.ch;
} else if (tokenType === ATTR_VALUE && (constPos.ch + 1) < ctx.pos.ch) {
// The cursor may be right before an unquoted attribute or another attribute name.
// Since we can't distinguish between them, we will empty the value so that the
// caller can just insert a new attribute value.
tagInfo.attr.value = "";
}
} else {
// if we're not at a tag, "=", or attribute name, assume we're in the value
tagInfo = _getTagInfoStartingFromAttrValue(ctx);
}
if (tokenType && tagInfo.tagName) {
tagInfo.position.tokenType = tokenType;
tagInfo.position.offset = offset;
}
return tagInfo;
}
/**
* Returns an Array of info about all blocks whose token mode name matches that passed in,
* in the given Editor's HTML document (assumes the Editor contains HTML text).
* @param {!Editor} editor - the editor containing the HTML text
* @param {string} modeName - the mode name of the tokens to look for
* @return {Array.<{start:{line:number, ch:number}, end:{line:number, ch:number}, text:string}>}
*/
function findBlocks(editor, modeName) {
// Start scanning from beginning of file
var ctx = TokenUtils.getInitialContext(editor._codeMirror, {line: 0, ch: 0}),
blocks = [],
currentBlock = null,
inBlock = false,
outerMode = editor._codeMirror.getMode(),
tokenModeName,
previousMode;
while (TokenUtils.moveNextToken(ctx, false)) {
tokenModeName = CodeMirror.innerMode(outerMode, ctx.token.state).mode.name;
if (inBlock) {
if (!currentBlock.end) {
// Handle empty blocks
currentBlock.end = currentBlock.start;
}
// Check for end of this block
if (tokenModeName === previousMode) {
// currentBlock.end is already set to pos of the last token by now
currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end);
inBlock = false;
} else {
currentBlock.end = { line: ctx.pos.line, ch: ctx.pos.ch };
}
} else {
// Check for start of a block
if (tokenModeName === modeName) {
currentBlock = {
start: { line: ctx.pos.line, ch: ctx.pos.ch }
};
blocks.push(currentBlock);
inBlock = true;
} else {
previousMode = tokenModeName;
}
// else, random token: ignore
}
}
return blocks;
}
/**
* Returns an Array of info about all <style> blocks in the given Editor's HTML document (assumes
* the Editor contains HTML text).
* @param {!Editor} editor
* @return {Array.<{start:{line:number, ch:number}, end:{line:number, ch:number}, text:string}>}
*/
function findStyleBlocks(editor) {
return findBlocks(editor, "css");
}
// Define public API
exports.TAG_NAME = TAG_NAME;
exports.CLOSING_TAG = CLOSING_TAG;
exports.ATTR_NAME = ATTR_NAME;
exports.ATTR_VALUE = ATTR_VALUE;
exports.getTagInfo = getTagInfo;
exports.getTagAttributes = getTagAttributes;
//The createTagInfo is really only for the unit tests so they can make the same structure to
//compare results with
exports.createTagInfo = createTagInfo;
exports.findStyleBlocks = findStyleBlocks;
exports.findBlocks = findBlocks;
});