(doc, pos)
| 1018 | // actually exist within the document. |
| 1019 | function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));} |
| 1020 | function clipPos(doc, pos) { |
| 1021 | if (pos.line < doc.first) return Pos(doc.first, 0); |
| 1022 | var last = doc.first + doc.size - 1; |
| 1023 | if (pos.line > last) return Pos(last, getLine(doc, last).text.length); |
| 1024 | return clipToLen(pos, getLine(doc, pos.line).text.length); |
| 1025 | } |
| 1026 | function clipToLen(pos, linelen) { |
| 1027 | var ch = pos.ch; |
| 1028 | if (ch == null || ch > linelen) return Pos(pos.line, linelen); |
no test coverage detected