Skip to content

Commit b62e0fa

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 highglight caret and editor focus in debug mode
1 parent 369b2b3 commit b62e0fa

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@ import {Console} from './Console';
66
import {ValueSyncStore} from '../../../util/events/sync-store';
77
import {useSyncStore} from '../../web/react/hooks';
88
import {DebugState} from './state';
9+
import {CssClass} from '../../web/constants';
910
import type {PeritextSurfaceState} from '../../web';
1011

1112
const blockClass = rule({
1213
pos: 'relative',
1314
});
1415

16+
const blockClassEnabled = rule({
17+
pos: 'relative',
18+
['& .' + CssClass.Editor]: {
19+
'caret-color': 'red',
20+
'::selection': {
21+
bgc: 'red',
22+
},
23+
'&:focus': {
24+
out: '2px solid blue',
25+
},
26+
}
27+
});
28+
1529
const btnClass = drule({
1630
d: 'flex',
1731
alignItems: 'center',
@@ -38,7 +52,7 @@ export interface RenderPeritextProps {
3852
export const RenderPeritext: React.FC<RenderPeritextProps> = ({state: state_, ctx, button, children}) => {
3953
const theme = useTheme();
4054
const state = React.useMemo(() => state_ ?? new DebugState(), [state_]);
41-
useSyncStore(state.enabled);
55+
const enabled = useSyncStore(state.enabled);
4256
const value = React.useMemo(
4357
() => ({
4458
state,
@@ -56,7 +70,7 @@ export const RenderPeritext: React.FC<RenderPeritextProps> = ({state: state_, ct
5670
return (
5771
<context.Provider value={value}>
5872
<div
59-
className={blockClass}
73+
className={blockClass + (enabled ? blockClassEnabled : '')}
6074
onKeyDown={(event) => {
6175
switch (event.key) {
6276
case 'D': {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ToolbarState implements UiLifeCycles {
4747
const {dom, events} = surface;
4848
const {et} = events;
4949
const mouseDown = dom!.cursor.mouseDown;
50-
const source = dom!.opts.source;
50+
const source = dom.el;
5151

5252
const changeUnsubscribe = et.subscribe('change', (ev) => {
5353
const lastEvent = ev.detail.ev;

0 commit comments

Comments
 (0)