Skip to content

Commit

Permalink
feat(json-crdt-peritext-ui): 🎸 anchor boolean slice end point "before…
Browse files Browse the repository at this point in the history
…" next char
  • Loading branch information
streamich committed Nov 6, 2024
1 parent d4c68db commit 77afdc1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/json-crdt-peritext-ui/events/PeritextEventDefaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {Peritext} from '../../json-crdt-extensions/peritext';
import type {EditorSlices} from '../../json-crdt-extensions/peritext/editor/EditorSlices';
import {Anchor} from '../../json-crdt-extensions/peritext/rga/constants';
import {CursorAnchor} from '../../json-crdt-extensions/peritext/slice/constants';
import type {PeritextEventHandlerMap, PeritextEventTarget} from './PeritextEventTarget';
import type * as events from './types';
Expand Down Expand Up @@ -99,7 +100,7 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
};

public readonly inline = (event: CustomEvent<events.InlineDetail>) => {
const {type, store = 'saved', behavior = 'overwrite', data, pos} = event.detail;
const {type, store = 'saved', behavior = 'overwrite', data} = event.detail;
const editor = this.txt.editor;
const slices: EditorSlices = store === 'saved' ? editor.saved : store === 'extra' ? editor.extra : editor.local;
switch (behavior) {
Expand All @@ -110,6 +111,18 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
slices.insErase(type, data);
break;
default:
for (let i = editor.cursors0(), cursor = i(); cursor; cursor = i()) {
// For inline boolean slices, ref endpoint "before" the next character
// as per the Peritext paper, so that, say, bold text automatically
// includes the next character typed.
if (cursor.end.anchor !== Anchor.Before || cursor.start.anchor !== Anchor.Before) {
const start = cursor.start.clone();
const end = cursor.end.clone();
start.refBefore();
end.refBefore();
cursor.set(start, end);
}
}
slices.insOverwrite(type, data);
}
};
Expand Down

0 comments on commit 77afdc1

Please sign in to comment.