diff options
| author | eunhhu <[email protected]> | 2026-09-26 11:01:21 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 11:01:21 +0100 |
| commit | 6e50736c576b93c09345dc63488bbb95e9203c13 (patch) | |
| tree | 6c267b464f141edcaa340dbe24604069efda82d1 /prototypes/connections/module.c | |
| parent | b230b70252f09cf3425a8b4b959b3dfd72075b31 (diff) | |
| download | pure-6e50736c576b93c09345dc63488bbb95e9203c13.tar.gz pure-6e50736c576b93c09345dc63488bbb95e9203c13.zip | |
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.
Diffstat (limited to 'prototypes/connections/module.c')
| -rw-r--r-- | prototypes/connections/module.c | 8 |
1 files changed, 6 insertions, 2 deletions
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; } } |
