feat: add API for editing points and ranges

This commit is contained in:
Amaan Qureshi 2025-09-18 23:28:34 -04:00 committed by Amaan Qureshi
parent 1a0868c487
commit a69367f739
9 changed files with 209 additions and 39 deletions

17
lib/src/point.c Normal file
View file

@ -0,0 +1,17 @@
#include "point.h"
void ts_point_edit(TSPoint *point, uint32_t *byte, const TSInputEdit *edit) {
uint32_t start_byte = *byte;
TSPoint start_point = *point;
if (start_byte >= edit->old_end_byte) {
start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte);
start_point = point_add(edit->new_end_point, point_sub(start_point, edit->old_end_point));
} else if (start_byte > edit->start_byte) {
start_byte = edit->new_end_byte;
start_point = edit->new_end_point;
}
*point = start_point;
*byte = start_byte;
}