Skip to content

Commit

Permalink
fix(json-crdt-extensions): 馃悰 allow setting non-constant slice data
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 2, 2024
1 parent c529aaf commit 2f87b8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/json-crdt-extensions/peritext/Peritext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export class Peritext implements Printable {
}

/**
* Creates a point at a view position in the text. The `pos` argument specifies
* the position of the character, not the gap between characters.
* Creates a point at a view position in the text. The `pos` argument
* specifies the position of the character, not the gap between characters.
*
* @param pos Position of the character in the text.
* @param anchor Whether the point should attach before or after a character.
Expand Down Expand Up @@ -162,7 +162,8 @@ export class Peritext implements Printable {
}

/**
* Creates a range from two points, the points have to be in the correct order.
* Creates a range from two points, the points have to be in the correct
* order.
*
* @param start Start point of the range, must be before or equal to end.
* @param end End point of the range, must be after or equal to start.
Expand All @@ -173,8 +174,8 @@ export class Peritext implements Printable {
}

/**
* A convenience method for creating a range from a view position and a length.
* See {@link Range.at} for more information.
* A convenience method for creating a range from a view position and a
* length. See {@link Range.at} for more information.
*
* @param start Position in the text.
* @param length Length of the range.
Expand Down
4 changes: 4 additions & 0 deletions src/json-crdt-extensions/peritext/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import type {SliceType} from '../slice/types';
import type {MarkerSlice} from '../slice/MarkerSlice';
import type {Slices} from '../slice/Slices';

/**
* Rename to `PeritextApi`.
*/
export class Editor implements Printable {
/**
* Cursor is the the current user selection. It can be a caret or a
Expand All @@ -25,6 +28,7 @@ export class Editor implements Printable {
) {
const point = txt.pointAbsStart();
const range = txt.range(point, point.clone());
// TODO: Add ability to remove cursor.
this.cursor = slices.ins<Cursor, typeof Cursor>(range, SliceBehavior.Cursor, CursorAnchor.Start, undefined, Cursor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-extensions/peritext/slice/PersistedSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PersistedSlice<T = string> extends Range<T> implements MutableSlice
this.type = params.type;
changes.push([SliceTupleIndex.Type, s.con(this.type)]);
}
if (hasOwnProperty(params, 'data')) changes.push([SliceTupleIndex.Data, s.con(params.data)]);
if (hasOwnProperty(params, 'data')) changes.push([SliceTupleIndex.Data, params.data]);
if (updateHeader) {
const header =
(this.behavior << SliceHeaderShift.Behavior) +
Expand Down

0 comments on commit 2f87b8a

Please sign in to comment.