diff --git a/src/json-crdt-peritext-ui/events/PeritextEventDefaults.ts b/src/json-crdt-peritext-ui/events/PeritextEventDefaults.ts index adc5c14338..01ff7d6b95 100644 --- a/src/json-crdt-peritext-ui/events/PeritextEventDefaults.ts +++ b/src/json-crdt-peritext-ui/events/PeritextEventDefaults.ts @@ -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'; @@ -99,7 +100,7 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap { }; public readonly inline = (event: CustomEvent) => { - 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) { @@ -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); } };