MCPcopy Create free account
hub / github.com/TruthHun/BookStack / getFragmentAround

Function getFragmentAround

static/editor.md/lib/codemirror/addon/tern/tern.js:542–567  ·  view source on GitHub ↗
(data, start, end)

Source from the content-addressed store, hash-verified

540 }
541
542 function getFragmentAround(data, start, end) {
543 var doc = data.doc;
544 var minIndent = null, minLine = null, endLine, tabSize = 4;
545 for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {
546 var line = doc.getLine(p), fn = line.search(/\bfunction\b/);
547 if (fn < 0) continue;
548 var indent = CodeMirror.countColumn(line, null, tabSize);
549 if (minIndent != null && minIndent <= indent) continue;
550 minIndent = indent;
551 minLine = p;
552 }
553 if (minLine == null) minLine = min;
554 var max = Math.min(doc.lastLine(), end.line + 20);
555 if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))
556 endLine = max;
557 else for (endLine = end.line + 1; endLine < max; ++endLine) {
558 var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);
559 if (indent <= minIndent) break;
560 }
561 var from = Pos(minLine, 0);
562
563 return {type: "part",
564 name: data.name,
565 offsetLines: from.line,
566 text: doc.getRange(from, Pos(endLine, 0))};
567 }
568
569 // Generic utilities
570

Callers 1

buildRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected