- function getLineLength( e ) {
- return Math.floor( e.scrollWidth / ( $.client.profile().platform === 'linux' ? 7 : 8 ) );
- }
- function getCaretScrollPosition( e ) {
- // FIXME: This functions sucks and is off by a few lines most
- // of the time. It should be replaced by something decent.
- var i, j,
- nextSpace,
- text = e.value.replace( /\r/g, '' ),
- caret = $( e ).textSelection( 'getCaretPosition' ),
- lineLength = getLineLength( e ),
- row = 0,
- charInLine = 0,
- lastSpaceInLine = 0;
-
- for ( i = 0; i < caret; i++ ) {
- charInLine++;
- if ( text.charAt( i ) === ' ' ) {
- lastSpaceInLine = charInLine;
- } else if ( text.charAt( i ) === '\n' ) {
- lastSpaceInLine = 0;
- charInLine = 0;
- row++;
- }
- if ( charInLine > lineLength ) {
- if ( lastSpaceInLine > 0 ) {
- charInLine = charInLine - lastSpaceInLine;
- lastSpaceInLine = 0;
- row++;
- }
- }
- }
- nextSpace = 0;
- for ( j = caret; j < caret + lineLength; j++ ) {
- if (
- text.charAt( j ) === ' ' ||
- text.charAt( j ) === '\n' ||
- caret === text.length
- ) {
- nextSpace = j;
- break;
- }
- }
- if ( nextSpace > lineLength && caret <= lineLength ) {
- charInLine = caret - lastSpaceInLine;
- row++;
- }
- return ( $.client.profile().platform === 'mac' ? 13 : ( $.client.profile().platform === 'linux' ? 15 : 16 ) ) * row;
- }