Skip to content

Commit 7a03736

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 show caret bottom menu on direct caret placement
1 parent f50608d commit 7a03736

File tree

1 file changed

+17
-0
lines changed
  • src/json-crdt-peritext-ui/plugins/toolbar/cursor/caret/CaretBottomOverlay

1 file changed

+17
-0
lines changed

‎src/json-crdt-peritext-ui/plugins/toolbar/cursor/caret/CaretBottomOverlay/index.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22
import * as React from 'react';
33
import {FormattingsManagePane} from '../../../formatting/FormattingsManagePane';
44
import {BottomPanePortal} from '../../util/BottomPanePortal';
5+
import {useToolbarPlugin} from '../../../context';
6+
import {PeritextEventDetailMap} from '../../../../../events';
57
import type {CaretViewProps} from '../../../../../web/react/cursor/CaretView';
68

9+
const isDirectCaretPlacement = (event: PeritextEventDetailMap['change']['ev'] | undefined): boolean => {
10+
if (event && event.type === 'cursor') {
11+
const detail = event.detail;
12+
const at = detail.at;
13+
if (Array.isArray(at) && at.length === 1 && typeof at[0] === 'number') return true;
14+
const move = detail.move;
15+
if (Array.isArray(move) && move.length === 1 && Array.isArray(move[0]) && move[0][0] === 'focus' && typeof move[0][1] === 'number') return true;
16+
}
17+
return false;
18+
};
19+
720
export interface CaretBottomOverlayProps extends CaretViewProps {}
821

922
export const CaretBottomOverlay: React.FC<CaretBottomOverlayProps> = (props) => {
1023
const {fwd, bwd} = props;
1124
const inline = fwd || bwd;
25+
const {toolbar} = useToolbarPlugin()!;
26+
27+
console.log(toolbar.lastEvent?.detail);
1228

1329
if (!inline) return;
30+
if (!isDirectCaretPlacement(toolbar.lastEvent)) return;
1431

1532
return (
1633
<BottomPanePortal>

0 commit comments

Comments
 (0)