countLines returns a paste's visual line count. Terminals disagree on separators (\n unix, \r old-mac, \r\n Windows); max of the \n and \r counts handles all three without double-counting \r\n.
(s string)
| 208 | // separators (\n unix, \r old-mac, \r\n Windows); max of the \n and \r counts |
| 209 | // handles all three without double-counting \r\n. |
| 210 | func countLines(s string) int { |
| 211 | n := strings.Count(s, "\n") |
| 212 | if r := strings.Count(s, "\r"); r > n { |
| 213 | n = r |
| 214 | } |
| 215 | return n + 1 |
| 216 | } |
| 217 | |
| 218 | // handleChipKey gives chips atomic-token semantics: Backspace/Delete at a |
| 219 | // boundary removes the whole chip, ←/→ jumps across it, and a cursor inside a |
no outgoing calls
no test coverage detected