Skip to content

Commit b0754e6

Browse files
committed
1 parent 19bbdfc commit b0754e6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/components/write/AddLink.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const AddLinkBlock = styled.div`
5555

5656
interface AddLinkProps {
5757
left: number;
58-
top: number;
58+
top: number | null;
59+
bottom: number | null;
5960
stickToRight?: boolean;
6061
onConfirm: (link: string) => void;
6162
onClose: () => void;
@@ -68,6 +69,7 @@ const { useCallback, useRef, useEffect } = React;
6869
const AddLink: React.FC<AddLinkProps> = ({
6970
left,
7071
top,
72+
bottom,
7173
stickToRight,
7274
onConfirm,
7375
onClose,
@@ -92,7 +94,8 @@ const AddLink: React.FC<AddLinkProps> = ({
9294
<AddLinkBlock
9395
style={{
9496
left: stickToRight ? 'initial' : left,
95-
top,
97+
top: top || 'initial',
98+
bottom: bottom || 'initial',
9699
right: stickToRight ? '3rem' : 'initial',
97100
}}
98101
>

src/components/write/WriteMarkdownEditor.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export interface MarkdownEditorProps {
3434
type MarkdownEditorState = {
3535
shadow: boolean;
3636
addLink: {
37-
top: number;
37+
top: number | null;
38+
bottom: number | null;
3839
left: number;
3940
visible: boolean;
4041
stickToRight: boolean;
@@ -235,6 +236,7 @@ export default class WriteMarkdownEditor extends React.Component<
235236
shadow: false,
236237
addLink: {
237238
top: 0,
239+
bottom: 0,
238240
left: 0,
239241
visible: false,
240242
stickToRight: false,
@@ -404,15 +406,20 @@ export default class WriteMarkdownEditor extends React.Component<
404406
const cursorPos = this.codemirror.cursorCoords(cursor);
405407
if (!this.block.current) return;
406408
const stickToRight = cursorPos.left > this.block.current.clientWidth - 341;
407-
409+
const calculatedTop =
410+
this.block.current.scrollTop +
411+
cursorPos.top +
412+
this.codemirror.defaultTextHeight() / 2 +
413+
1;
414+
415+
const isAtBottom = calculatedTop + 173 > this.block.current?.clientHeight;
416+
const pos = isAtBottom
417+
? { top: null, bottom: 64 }
418+
: { top: calculatedTop, bottom: null };
408419
this.setState({
409420
addLink: {
410421
visible: true,
411-
top:
412-
this.block.current.scrollTop +
413-
cursorPos.top +
414-
this.codemirror.defaultTextHeight() / 2 +
415-
1,
422+
...pos,
416423
left: cursorPos.left,
417424
stickToRight,
418425
},
@@ -838,6 +845,7 @@ ${selected}
838845
defaultValue=""
839846
left={addLink.left}
840847
top={addLink.top}
848+
bottom={addLink.bottom}
841849
stickToRight={addLink.stickToRight}
842850
onConfirm={this.handleConfirmAddLink}
843851
onClose={this.handleCancelAddLink}

0 commit comments

Comments
 (0)