Skip to content

Commit 2a5cdd8

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 show only main cursor toolbar over focus caret
1 parent c26aaab commit 2a5cdd8

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

‎src/json-crdt-peritext-ui/plugins/toolbar/RenderFocus.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface RenderFocusProps extends CaretViewProps {
2727
children: React.ReactNode;
2828
}
2929

30-
export const RenderFocus: React.FC<RenderFocusProps> = ({children}) => {
30+
export const RenderFocus: React.FC<RenderFocusProps> = ({children, cursor}) => {
3131
const {toolbar} = useToolbarPlugin()!;
3232
const showInlineToolbar = toolbar.showInlineToolbar;
3333
const [showInlineToolbarValue, toolbarVisibilityChangeTime] = useSyncStore(showInlineToolbar);
@@ -43,7 +43,7 @@ export const RenderFocus: React.FC<RenderFocusProps> = ({children}) => {
4343

4444
let toolbarElement: React.ReactNode = null;
4545

46-
if (showInlineToolbarValue && !isScrubbing)
46+
if (showInlineToolbarValue && !isScrubbing && (toolbar.txt.editor.mainCursor() === cursor))
4747
toolbarElement = (
4848
<CaretToolbar
4949
disabled={!enableAfterCoolDown /* || (!focus && blurTimeout) */}

‎src/json-crdt-peritext-ui/plugins/toolbar/block/LeafBlockFrame/index.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const topLeftOverlay = rule({
1818
l: '-72px',
1919
});
2020

21-
const topRightOverlay = rule({
22-
d: 'block',
23-
pos: 'absolute',
24-
t: '-36px',
25-
r: '-16px',
26-
});
21+
// const topRightOverlay = rule({
22+
// d: 'block',
23+
// pos: 'absolute',
24+
// t: '-36px',
25+
// r: '-16px',
26+
// });
2727

2828
export interface LeafBlockFrameProps extends RenderBlockProps {}
2929

‎src/json-crdt-peritext-ui/web/react/BlockView.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ export const BlockView: React.FC<BlockViewProps> = React.memo(
2626
const hasCursor = inline.hasCursor();
2727
if (hasCursor) {
2828
const attr = inline.attr();
29-
const italic = attr[CommonSliceType.i] && attr[CommonSliceType.i][0];
29+
const italic = attr[CommonSliceType.i]?.[0];
3030
const cursorStart = inline.cursorStart();
3131
if (cursorStart) {
3232
const key = cursorStart.start.key() + '-a';
3333
let element: React.ReactNode;
3434
if (cursorStart.isStartFocused()) {
3535
if (cursorStart.isCollapsed())
36-
element = <CaretView key={key} italic={!!italic} point={cursorStart.start} />;
36+
element = <CaretView key={key} italic={!!italic} point={cursorStart.start} cursor={cursorStart} />;
3737
else {
3838
const isItalic = italic instanceof InlineAttrEnd || italic instanceof InlineAttrPassing;
39-
element = <FocusView key={key} italic={isItalic} />;
39+
element = <FocusView key={key} italic={isItalic} cursor={cursorStart} />;
4040
}
4141
} else element = <AnchorView key={key} />;
4242
elements.push(element);
@@ -46,18 +46,19 @@ export const BlockView: React.FC<BlockViewProps> = React.memo(
4646
if (hasCursor) {
4747
const cursorEnd = inline.cursorEnd();
4848
const attr = inline.attr();
49-
const italic = attr[CommonSliceType.i] && attr[CommonSliceType.i][0];
49+
const italic = attr[CommonSliceType.i]?.[0];
5050
if (cursorEnd) {
5151
const key = cursorEnd.end.key() + '-b';
5252
let element: React.ReactNode;
5353
if (cursorEnd.isEndFocused()) {
54-
if (cursorEnd.isCollapsed()) element = <CaretView key={key} italic={!!italic} point={cursorEnd.start} />;
54+
if (cursorEnd.isCollapsed()) element = <CaretView key={key} italic={!!italic} point={cursorEnd.start} cursor={cursorEnd} />;
5555
else
5656
element = (
5757
<FocusView
5858
key={key}
5959
left
6060
italic={italic instanceof InlineAttrStart || italic instanceof InlineAttrPassing}
61+
cursor={cursorEnd}
6162
/>
6263
);
6364
} else element = <AnchorView key={key} />;

‎src/json-crdt-peritext-ui/web/react/cursor/CaretView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import * as React from 'react';
33
import {usePeritext} from '../context';
44
import {Caret} from './Caret';
5+
import type {Cursor} from '../../../../json-crdt-extensions/peritext/editor/Cursor';
56
import type {Point} from '../../../../json-crdt-extensions/peritext/rga/Point';
67

78
export interface CaretViewProps {
89
italic?: boolean;
910
point: Point<string>;
11+
cursor: Cursor<string>;
1012
}
1113

1214
export const CaretView: React.FC<CaretViewProps> = (props) => {

‎src/json-crdt-peritext-ui/web/react/cursor/FocusView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import * as React from 'react';
33
import {usePeritext} from '../context';
44
import {Caret} from './Caret';
5+
import type {Cursor} from '../../../../json-crdt-extensions/peritext/editor/Cursor';
56

67
export interface FocusViewProps {
78
left?: boolean;
89
italic?: boolean;
10+
cursor: Cursor<string>;
911
}
1012

1113
export const FocusView: React.FC<FocusViewProps> = (props) => {

0 commit comments

Comments
 (0)