From 6e50736c576b93c09345dc63488bbb95e9203c13 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 11:01:21 +0100 Subject: Let a cursor stay before text inserted at it (a mark) Text inserted at a cursor's position pushed every cursor there behind it. That suits a caret, not a remembered position: a mark, a selection's start or a bookmark should stay before the new text. A cursor state's reserved word in the module now carries a flag: 1 makes it a mark, which stays where text is inserted at it and otherwise follows edits as any cursor does. The flag is refused on other states and other values; existing modules, with 0 there, keep their meaning. --- prototypes/connections/module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'prototypes/connections/module.c') diff --git a/prototypes/connections/module.c b/prototypes/connections/module.c index 5e2b98f..7af1d5c 100644 --- a/prototypes/connections/module.c +++ b/prototypes/connections/module.c @@ -356,8 +356,11 @@ PURE_COLD PureResult pure_module_load(const void *bytes, size_t size, PureModule out->initial[i] = read_double(at + 8); if (!isfinite(out->initial[i])) REFUSE("non-finite initial value", i); } else { - if (read32(at + 12) || read32(at + 8) > UINT16_MAX) REFUSE("state reference", i); + uint32_t flags = read32(at + 12); + if ((flags && (out->state_type[i] != PURE_STATE_CURSOR || flags != PURE_CURSOR_STAYS)) || + read32(at + 8) > UINT16_MAX) REFUSE("state reference", i); out->state_ref[i] = (uint16_t)read32(at + 8); + out->state_flags[i] = (uint8_t)flags; } } for (uint32_t i = 0; i < out->collections; ++i, at += COLLECTION_BYTES) { @@ -648,7 +651,8 @@ static void move_cursors(const PureModule *m, double *values, uint32_t text, siz if (removed) { if (position >= at + removed) position -= (double)removed; else if (position > at) position = (double)at; - } else if (position >= at) position += (double)inserted; + } else if (position > at || (position == at && !(m->state_flags[c] & PURE_CURSOR_STAYS))) + position += (double)inserted; values[c] = position; } } -- cgit v1.2.3