tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
highlight text manually if focused in other input
awarm.space
2 years ago
60545c29
e4039eae
+45
-1
4 changed files
expand all
collapse all
unified
split
app
globals.css
components
Blocks
TextBlock
index.tsx
plugins.ts
index.tsx
+13
app/globals.css
···
105
105
@apply rounded-[4px];
106
106
@apply box-decoration-clone;
107
107
}
108
108
+
109
109
+
.selection-highlight {
110
110
+
background-color: Highlight;
111
111
+
@apply py-[1.5px];
112
112
+
}
113
113
+
114
114
+
.ProseMirror:focus-within .selection-highlight {
115
115
+
background-color: transparent;
116
116
+
}
117
117
+
118
118
+
.Multiple-Selected:focus-within .selection-highlight {
119
119
+
background-color: transparent;
120
120
+
}
+2
components/Blocks/TextBlock/index.tsx
···
39
39
import { rangeHasMark } from "src/utils/prosemirror/rangeHasMark";
40
40
import { useEntitySetContext } from "components/EntitySetProvider";
41
41
import { useHandlePaste } from "./useHandlePaste";
42
42
+
import { highlightSelectionPlugin } from "./plugins";
42
43
43
44
export function TextBlock(props: BlockProps & { className: string }) {
44
45
let initialized = useInitialPageLoad();
···
171
172
ySyncPlugin(value),
172
173
TextBlockKeymap(propsRef, repRef),
173
174
keymap(baseKeymap),
175
175
+
highlightSelectionPlugin,
174
176
],
175
177
}),
176
178
});
+27
components/Blocks/TextBlock/plugins.ts
···
1
1
+
import { Decoration, DecorationSet } from "prosemirror-view";
2
2
+
import { Plugin } from "prosemirror-state";
3
3
+
export const highlightSelectionPlugin = new Plugin({
4
4
+
state: {
5
5
+
init(_, { doc }) {
6
6
+
return DecorationSet.empty;
7
7
+
},
8
8
+
apply(tr, oldDecorations, oldState, newState) {
9
9
+
let decorations = [];
10
10
+
11
11
+
// Check if there's a selection
12
12
+
const { from, to } = newState.selection;
13
13
+
if (from !== to) {
14
14
+
decorations.push(
15
15
+
Decoration.inline(from, to, { class: "selection-highlight" }),
16
16
+
);
17
17
+
}
18
18
+
19
19
+
return DecorationSet.create(newState.doc, decorations);
20
20
+
},
21
21
+
},
22
22
+
props: {
23
23
+
decorations(state) {
24
24
+
return this.getState(state);
25
25
+
},
26
26
+
},
27
27
+
});
+3
-1
components/Blocks/index.tsx
···
299
299
props.type !== "heading" &&
300
300
props.type !== "text" &&
301
301
`first:pt-0 sm:first:pt-0 pl-3 pr-3 sm:pl-4 sm:pr-4 pt-1 pb-2`
302
302
-
}`}
302
302
+
}
303
303
+
${selectedBlocks.length > 1 ? "Multiple-Selected" : ""}
304
304
+
`}
303
305
id={elementId.block(props.entityID).container}
304
306
>
305
307
{selected && selectedBlocks.length > 1 && (