Basic cursor movement, handling end of buffer, end of line in drawing
This commit is contained in:
@@ -252,17 +252,22 @@ Line FindLine(Buffer &buffer, int64_t pos) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int64_t AdjustUTF8Pos(const Buffer &buffer, int64_t pos, int64_t direction = 1) {
|
||||
int64_t result = pos;
|
||||
for (; result >= 0 && result < buffer.len;) {
|
||||
char c = GetChar(buffer, pos);
|
||||
if (IsUTF8ContinuationByte(c)) {
|
||||
result += direction;
|
||||
int64_t AdjustUTF8Pos(String string, int64_t pos, int64_t direction) {
|
||||
for (; pos >= 0 && pos < string.len;) {
|
||||
if (IsUTF8ContinuationByte(string.data[pos])) {
|
||||
pos += direction;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return pos;
|
||||
}
|
||||
|
||||
int64_t AdjustUTF8Pos(const Buffer &buffer, int64_t pos, int64_t direction = 1, bool clamp = true) {
|
||||
String string = GetString(buffer);
|
||||
pos = AdjustUTF8Pos(string, pos, direction);
|
||||
if (clamp) pos = Clamp(buffer, pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
uint32_t GetUTF32(Buffer &buffer, int64_t pos, int64_t *codepoint_size) {
|
||||
@@ -317,7 +322,7 @@ void Advance(BufferIter *iter) {
|
||||
if (iter->direction == ITERATE_FORWARD) {
|
||||
iter->pos += iter->utf8_codepoint_size;
|
||||
} else {
|
||||
iter->pos = AdjustUTF8Pos(*iter->buffer, iter->pos - 1, ITERATE_BACKWARD);
|
||||
iter->pos = AdjustUTF8Pos(*iter->buffer, iter->pos - 1, ITERATE_BACKWARD, false);
|
||||
}
|
||||
|
||||
if (!IsValid(*iter)) return;
|
||||
|
||||
Reference in New Issue
Block a user