@@ -1035,7 +1035,7 @@ internal Point ConvertOffsetToPoint(int offset)
1035
1035
int y = _initialY ;
1036
1036
1037
1037
int bufferWidth = _console . BufferWidth ;
1038
- var continuationPromptLength = Options . ContinuationPrompt . Length ;
1038
+ var continuationPromptLength = LengthInBufferCells ( Options . ContinuationPrompt ) ;
1039
1039
1040
1040
for ( int i = 0 ; i < offset ; i ++ )
1041
1041
{
@@ -1052,34 +1052,26 @@ internal Point ConvertOffsetToPoint(int offset)
1052
1052
// Wrap? No prompt when wrapping
1053
1053
if ( x >= bufferWidth )
1054
1054
{
1055
- int offsize = x - bufferWidth ;
1056
- if ( offsize % size == 0 )
1057
- {
1058
- x -= bufferWidth ;
1059
- }
1060
- else
1061
- {
1062
- x = size ;
1063
- }
1055
+ // If character didn't fit on current line, it will move entirely to the next line.
1056
+ x = ( ( x == bufferWidth ) ? 0 : size ) ;
1064
1057
1065
- // If the next character is newline, let the next loop
1066
- // iteration increment y and adjust x .
1067
- if ( ! ( i + 1 < offset && _buffer [ i + 1 ] == '\n ' ) )
1058
+ // If cursor is at column 0 and the next character is newline, let the next loop
1059
+ // iteration increment y.
1060
+ if ( x != 0 || ! ( i + 1 < offset && _buffer [ i + 1 ] == '\n ' ) )
1068
1061
{
1069
1062
y += 1 ;
1070
1063
}
1071
1064
}
1072
1065
}
1073
1066
}
1074
1067
1075
- //if the next character has bigger size than the remain space on this line,
1076
- //the cursor goes to next line where the next character is.
1077
- if ( _buffer . Length > offset )
1068
+ // If next character actually exists, and isn't newline, check if wider than the space left on the current line.
1069
+ if ( _buffer . Length > offset && _buffer [ offset ] != '\n ' )
1078
1070
{
1079
1071
int size = LengthInBufferCells ( _buffer [ offset ] ) ;
1080
- // next one is Wrapped to next line
1081
- if ( x + size > bufferWidth && ( x + size - bufferWidth ) % size != 0 )
1072
+ if ( x + size > bufferWidth )
1082
1073
{
1074
+ // Character was wider than remaining space, so character, and cursor, appear on next line.
1083
1075
x = 0 ;
1084
1076
y ++ ;
1085
1077
}
@@ -1095,7 +1087,7 @@ private int ConvertLineAndColumnToOffset(Point point)
1095
1087
int y = _initialY ;
1096
1088
1097
1089
int bufferWidth = _console . BufferWidth ;
1098
- var continuationPromptLength = Options . ContinuationPrompt . Length ;
1090
+ var continuationPromptLength = LengthInBufferCells ( Options . ContinuationPrompt ) ;
1099
1091
for ( offset = 0 ; offset < _buffer . Length ; offset ++ )
1100
1092
{
1101
1093
// If we are on the correct line, return when we find
@@ -1123,19 +1115,12 @@ private int ConvertLineAndColumnToOffset(Point point)
1123
1115
// Wrap? No prompt when wrapping
1124
1116
if ( x >= bufferWidth )
1125
1117
{
1126
- int offsize = x - bufferWidth ;
1127
- if ( offsize % size == 0 )
1128
- {
1129
- x -= bufferWidth ;
1130
- }
1131
- else
1132
- {
1133
- x = size ;
1134
- }
1118
+ // If character didn't fit on current line, it will move entirely to the next line.
1119
+ x = ( ( x == bufferWidth ) ? 0 : size ) ;
1135
1120
1136
- // If the next character is newline, let the next loop
1137
- // iteration increment y and adjust x .
1138
- if ( ! ( offset + 1 < _buffer . Length && _buffer [ offset + 1 ] == '\n ' ) )
1121
+ // If cursor is at column 0 and the next character is newline, let the next loop
1122
+ // iteration increment y.
1123
+ if ( x != 0 || ! ( offset + 1 < _buffer . Length && _buffer [ offset + 1 ] == '\n ' ) )
1139
1124
{
1140
1125
y += 1 ;
1141
1126
}
0 commit comments