MCPcopy Index your code
hub / github.com/witheve/Eve / domTextBetween

Function domTextBetween

src/codemirror.js:1968–2007  ·  view source on GitHub ↗
(cm, from, to, fromLine, toLine)

Source from the content-addressed store, hash-verified

1966 }
1967
1968 function domTextBetween(cm, from, to, fromLine, toLine) {
1969 var text = "", closing = false, lineSep = cm.doc.lineSeparator();
1970 function recognizeMarker(id) { return function(marker) { return marker.id == id; }; }
1971 function walk(node) {
1972 if (node.nodeType == 1) {
1973 var cmText = node.getAttribute("cm-text");
1974 if (cmText != null) {
1975 if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "");
1976 text += cmText;
1977 return;
1978 }
1979 var markerID = node.getAttribute("cm-marker"), range;
1980 if (markerID) {
1981 var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
1982 if (found.length && (range = found[0].find()))
1983 text += getBetween(cm.doc, range.from, range.to).join(lineSep);
1984 return;
1985 }
1986 if (node.getAttribute("contenteditable") == "false") return;
1987 for (var i = 0; i < node.childNodes.length; i++)
1988 walk(node.childNodes[i]);
1989 if (/^(pre|div|p)$/i.test(node.nodeName))
1990 closing = true;
1991 } else if (node.nodeType == 3) {
1992 var val = node.nodeValue;
1993 if (!val) return;
1994 if (closing) {
1995 text += lineSep;
1996 closing = false;
1997 }
1998 text += val;
1999 }
2000 }
2001 for (;;) {
2002 walk(from);
2003 if (from == to) break;
2004 from = from.nextSibling;
2005 }
2006 return text;
2007 }
2008
2009 CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
2010

Callers 1

codemirror.jsFile · 0.85

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected