Skip to content

Commit e066dbf

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 improve entangled overlay rendering
1 parent 5ff00df commit e066dbf

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/json-crdt-peritext-ui/components/EntangledPortal.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class EntangledPortalState implements UiLifeCycles {
8585
}
8686

8787
export interface EntangledPortalProps extends EntangledPortalStateOpts {
88+
span?: React.HTMLAttributes<HTMLSpanElement>;
8889
children?: React.ReactNode;
8990
}
9091

@@ -94,16 +95,13 @@ export interface EntangledPortalProps extends EntangledPortalStateOpts {
9495
* with the <span> on resize and scroll.
9596
*/
9697
export const EntangledPortal: React.FC<EntangledPortalProps> = (props) => {
97-
const {children} = props;
98+
const {span, children} = props;
9899
const state = React.useMemo(() => new EntangledPortalState(props), []);
99100
state.opts = props;
100101
React.useEffect(state.start, [state]);
101102

102103
return (
103-
<span
104-
style={{width: 1, height: 1, display: 'inline-block', border: '1px solid red'}}
105-
ref={state.base}
106-
>
104+
<span {...span} ref={state.base}>
107105
<Portal>
108106
<div ref={state.dest}>
109107
{children}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as React from 'react';
2+
import {rule} from 'nano-theme';
23
import {ManageFormattingsCard} from '../../../formatting/ManageFormattingsCard';
34
import {EntangledPortal, EntangledPortalStateOpts} from '../../../../../components/EntangledPortal';
45
import type {CaretViewProps} from '../../../../../web/react/cursor/CaretView';
56

7+
const spanClass = rule({
8+
pe: 'none',
9+
});
10+
611
const gap = 4
712
const position: EntangledPortalStateOpts['position'] = (base, dest) => {
813
let x = base.x - (dest.width >> 1);
@@ -12,6 +17,13 @@ const position: EntangledPortalStateOpts['position'] = (base, dest) => {
1217
return [x, y];
1318
};
1419

20+
const span = {className: spanClass};
21+
22+
const entangledProps = {
23+
position,
24+
span,
25+
};
26+
1527
export interface CaretBottomOverlayProps extends CaretViewProps {
1628
children: React.ReactNode;
1729
}
@@ -23,7 +35,7 @@ export const CaretBottomOverlay: React.FC<CaretBottomOverlayProps> = (props) =>
2335
if (!inline) return;
2436

2537
return (
26-
<EntangledPortal position={position}>
38+
<EntangledPortal {...entangledProps}>
2739
<ManageFormattingsCard inline={inline} />
2840
</EntangledPortal>
2941
);

0 commit comments

Comments
 (0)