MCPcopy Create free account
hub / github.com/breck7/scroll / splitSpaces

Function splitSpaces

external/.scrollLibs.js:2998–3013  ·  view source on GitHub ↗
(text, trailingBefore)

Source from the content-addressed store, hash-verified

2996 // Change some spaces to NBSP to prevent the browser from collapsing
2997 // trailing spaces at the end of a line when rendering text (issue #1362).
2998 function splitSpaces(text, trailingBefore) {
2999 if (text.length > 1 && !/ /.test(text)) {
3000 return text
3001 }
3002 var spaceBefore = trailingBefore,
3003 result = ""
3004 for (var i = 0; i < text.length; i++) {
3005 var ch = text.charAt(i)
3006 if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) {
3007 ch = "\u00a0"
3008 }
3009 result += ch
3010 spaceBefore = ch == " "
3011 }
3012 return result
3013 }
3014
3015 // Work around nonsense dimensions being reported for stretches of
3016 // right-to-left text.

Callers 1

buildTokenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected