-
Notifications
You must be signed in to change notification settings - Fork 20
/
ReferencesTransform.js
41 lines (32 loc) · 1.15 KB
/
ReferencesTransform.js
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
/**
* Ternific Copyright (c) 2014 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (/*require, exports, module*/) {
"use strict";
function ReferenceTransform(reference, content /*, file*/) {
//{Object.<fullPath: string, {
// matches: Array.<{
// start: {line:number, ch:number},
// end: {line:number, ch:number},
// startOffset: number,
// endOffset: number,
// line: string}>,
// collapsed: boolean}>
//}
var lineNumber = reference.start.line,
lineStart = lineNumber,
result, matchOffset;
// Calculate where in the buffer the line number is pointing to
while(lineStart--) {
matchOffset = content.indexOf('\n', matchOffset + 1);
}
matchOffset++; // Advance this to make sure the line accounts for the leading \n
result = $.extend(true, {}, reference);
result.line = content.substr(matchOffset, content.indexOf('\n', matchOffset + 1) - matchOffset);
result.isChecked = true;
return result;
}
return ReferenceTransform;
});