File tree Expand file tree Collapse file tree 3 files changed +5
-35
lines changed
src/json-crdt-peritext-ui Expand file tree Collapse file tree 3 files changed +5
-35
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export const App: React.FC = () => {
6262 state . events . et . buffer ( {
6363 action : 'paste' ,
6464 format : 'md' ,
65- unit : [ 0 , 0 ] ,
65+ at : [ 0 ] ,
6666 data : {
6767 text : markdown ,
6868 } ,
Original file line number Diff line number Diff line change @@ -226,23 +226,16 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
226226 this . undo ?. capture ( ) ;
227227 } ;
228228
229- public readonly buffer = async ( event : CustomEvent < events . BufferDetail > ) => {
229+ public readonly buffer = async ( { detail} : CustomEvent < events . BufferDetail > ) => {
230+ const selection = [ ...this . getSelSet ( detail ) ] ;
231+ this . moveSelSet ( selection , detail ) ;
230232 const opts = this . opts ;
231233 const clipboard = opts . clipboard ;
232234 if ( ! clipboard ) return ;
233- const detail = event . detail ;
234235 const { action, format} = detail ;
235- let range : undefined | Range < any > ;
236236 const txt = this . txt ;
237237 const editor = txt . editor ;
238- if ( detail . unit ) {
239- const p1 = editor . pos2point ( detail . unit [ 0 ] ) ;
240- const p2 = editor . pos2point ( detail . unit [ 1 ] ) ;
241- range = txt . rangeFromPoints ( p1 , p2 ) ;
242- } else {
243- range = editor . getCursor ( ) ?. range ( ) ;
244- if ( ! range ) range = txt . rangeAll ( ) ;
245- }
238+ let range : undefined | Range < any > = selection [ 0 ] ?? txt . rangeAll ( ) ;
246239 if ( ! range ) return ;
247240 switch ( action ) {
248241 case 'cut' :
Original file line number Diff line number Diff line change @@ -377,29 +377,6 @@ export interface BufferDetail extends RangeEventDetail {
377377 */
378378 format ?: 'auto' | 'text' | 'json' | 'jsonml' | 'hast' | 'html' | 'mdast' | 'md' | 'fragment' | 'style' ;
379379
380- /**
381- * The range of text to cut or copy. If not specified, the first selection of
382- * the current cursor is used. If not specified and there is no cursor, the
383- * whole document is used.
384- *
385- * When multiple cursors are present, the range is calculated by using the
386- * first cursor.
387- *
388- * Below is a description of the possible values:
389- *
390- * - `cursor`: The current cursor selection.
391- * - `word`: The word at the current cursor position. Left and right edges of
392- * the selection are moved to the beginning and end of the word.
393- * - `line`: The line at the current cursor caret or focus position.
394- * - `block`: The block at the current cursor caret or focus position.
395- * - `all`: The whole document.
396- * - `[start, end]`: A specific range of text to cut or copy.
397- *
398- * @default 'cursor'
399- */
400- // unit?: [start: Position, end: Position] | 'cursor' | 'word' | 'line' | 'block' | 'all';
401- unit ?: [ start : Position , end : Position ] ;
402-
403380 /**
404381 * The data to paste into the document, when `action` is `"paste"`. If not
405382 * specified, an attempt is made to retrieve the data from the clipboard.
You can’t perform that action at this time.
0 commit comments