(doc, pos)
| 995 | // actually exist within the document. |
| 996 | function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))} |
| 997 | function clipPos(doc, pos) { |
| 998 | if (pos.line < doc.first) { return Pos(doc.first, 0) } |
| 999 | var last = doc.first + doc.size - 1; |
| 1000 | if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) } |
| 1001 | return clipToLen(pos, getLine(doc, pos.line).text.length) |
| 1002 | } |
| 1003 | function clipToLen(pos, linelen) { |
| 1004 | var ch = pos.ch; |
| 1005 | if (ch == null || ch > linelen) { return Pos(pos.line, linelen) } |
no test coverage detected