3 ms·
> Wouldn’t it be easier to track of where the to-be-substituted patterns are in the document? Tracking the location of substrings within a document under activ
by thangalin 4y ago
> Wouldn’t it be easier to track of where the to-be-substituted patterns are in the document?
Tracking the location of substrings within a document under active edits is not trivial. Performing string substitutions in a separate thread prior to rendering for preview (or exporting to PDF) is straightforward and has no impact on UI performance.
- Someone 4y ago> Tracking the location of substrings within a document under active edits is not trivial. Why not? Many word processors do that all the time to track text styles. You have an array of (start offset, end offset) pairs, optionally with a pointer to expansion info. When the text is edited, say by inserting c characters at offset O, go through the array, and update all offsets ≥ O by c. When you find a pair where you have to update only one of the offsets, the text of the to-be-expanded variable changed. Deletions can be treated in a similar fashion.
- deleted 4y ago[deleted]
- thangalin 4y agoSee: https://raw.githubusercontent.com/DaveJarvis/KeenWrite/main/docs/images/architecture/architecture.png https://raw.githubusercontent.com/DaveJarvis/KeenWrite/main/... Architecturally, variable processing knows nothing about text editing, it's just another step along the chain of document transformations. > Why not? It introduces more problems (edge cases) than it solves: empty documents, detection of partially matching variables, variable name at the end of the document, unmatched sigils, sigil insertion detection, sigil deletion, dynamic sigil changes, clipboard paste parsing and sigil detection, additional keyboard hooks, unit testing for off-by-one errors, supporting multiple sigil types within the same document, performance testing, and more. It's not trivial.