-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt-extensions): 🎸 add iteration over block points
- Loading branch information
Showing
6 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/json-crdt-extensions/peritext/block/__tests__/Block.iteration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {setupHelloWorldKit} from '../../__tests__/setup'; | ||
import {OverlayPoint} from '../../overlay/OverlayPoint'; | ||
|
||
describe('points', () => { | ||
test('no iteration in empty document', () => { | ||
const {peritext} = setupHelloWorldKit(); | ||
peritext.refresh(); | ||
const blocks = peritext.blocks; | ||
const block = blocks.root.children[0]!; | ||
const iterator = block.points0(); | ||
expect(iterator()).toBe(undefined); | ||
}); | ||
|
||
test('returns all overlay points in single block document', () => { | ||
const {peritext} = setupHelloWorldKit(); | ||
peritext.editor.cursor.setAt(3, 3); | ||
peritext.editor.saved.insStack('bold'); | ||
peritext.refresh(); | ||
const block = peritext.blocks.root.children[0]!; | ||
const iterator = block.points0(); | ||
const point1 = iterator(); | ||
const point2 = iterator(); | ||
const point3 = iterator(); | ||
expect(point1).toBeInstanceOf(OverlayPoint); | ||
expect(point2).toBeInstanceOf(OverlayPoint); | ||
expect(point3).toBe(undefined); | ||
}); | ||
|
||
test('returns only points within that block, in two-block document', () => { | ||
const {peritext} = setupHelloWorldKit(); | ||
peritext.editor.cursor.setAt(1, 2); | ||
peritext.editor.saved.insStack('bold'); | ||
peritext.editor.cursor.setAt(7, 2); | ||
peritext.editor.saved.insStack('italic'); | ||
peritext.editor.cursor.setAt(8, 2); | ||
peritext.editor.saved.insStack('underline'); | ||
peritext.editor.cursor.setAt(6); | ||
peritext.editor.saved.insMarker('p'); | ||
peritext.editor.delCursors(); | ||
peritext.refresh(); | ||
expect(peritext.blocks.root.children.length).toBe(2); | ||
const block1 = peritext.blocks.root.children[0]!; | ||
const block2 = peritext.blocks.root.children[1]!; | ||
const points1 = [...block1.points()]; | ||
const points2 = [...block2.points()]; | ||
expect(points1.length).toBe(2); | ||
expect(points2.length).toBe(4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters