1
0
silverbullet/plug-api/lib/change.ts
Ian Shehadeh 7d3303251d
WIP: Plug API document change event (#488)
* add support for basic on doc change event

* move change API core into plug-api/lib; add docs

* add overlap utility

* Maintain modal focus

* Federated URL backend handling

* Fix small typo in Query.md (#483)

* Federation progress

* Cleanup and federation prep

* Robustness and federation sync

* Federation: rewrite page references in federated content

* Don't sync service worker and index.json to client on silverbullet.md

* Federation listing timeouts

* Switching onboarding over to federation links

* Reduce amount of sync related log messages a bit

* Attribute indexing and code completion

* Shift-Enter in the page navigator now takes the input literally

* Updated changelog

* Completion for handlebar template variables

* Make 'pos' a number in tasks

* Updated install instructions to include edge builds

* WIP: CLI running of plugs

* Upgrade deno in Docker to 1.36.0

* Implement CLI store using Deno store

* Rerun directives

* Fixes #485

* 0.3.8

* 0.3.9

* Changelog

* Instantly sync updated pages when ticking off a task in a directive

* Sync current open page every 5s

* Optimize requests

* Make attribute extensible

* Debugging sync getting stuck

* Misaligning sync cycles (to avoid no-op cycles)

* Fixes #500: New apply page template command

* Changelog

* More sync debugging statements

* More sync debugging

* Even more debug

* Dial down excessive debug logging

* Fixes #115: By introducing MQ workers

* Use MQ for updating directives in entire space

* Work on plug:run

* touch up docs

* Fix htmlLanguage dependency

---------

Co-authored-by: Zef Hemel <zef@zef.me>
Co-authored-by: johnl <johnlunney@users.noreply.github.com>
2023-08-16 15:15:19 +02:00

44 lines
1.1 KiB
TypeScript

// API for working with changes to document text
/** Denotes a region in the document, based on character indicices
*/
export type Range = {
/** The starting index of the span, 0-based, inclusive
*/
from: number;
/** The ending index of the span, 0-based, exclusive
*/
to: number;
};
/** A modification to the document */
export type TextChange = {
/** The new text */
inserted: string;
/** The modified range **before** this change took effect.
*
* Example: "aaabbbccc" => "aaaccc", oldRange is [3, 6)
*/
oldRange: Range;
/** The modified range **after** this change took effect.
*
* Example: "aaabbbccc" => "aaaccc", newRange is [3, 3)
*/
newRange: Range;
};
/** Get this distance between the start and end of a range */
export function rangeLength(range: Range): number {
return range.to - range.from;
}
export function rangesOverlap(a: Range, b: Range): boolean {
// `b.from >= a.to` => "b" starts after "a"
// `a.from >= b.to` => "b" ends before "a"
// if neither is true these two ranges must overlap
return !(b.from >= a.to || a.from >= b.to);
}