@@ -34,7 +34,8 @@ export interface MarkdownEditorProps {
34
34
type MarkdownEditorState = {
35
35
shadow : boolean ;
36
36
addLink : {
37
- top : number ;
37
+ top : number | null ;
38
+ bottom : number | null ;
38
39
left : number ;
39
40
visible : boolean ;
40
41
stickToRight : boolean ;
@@ -235,6 +236,7 @@ export default class WriteMarkdownEditor extends React.Component<
235
236
shadow : false ,
236
237
addLink : {
237
238
top : 0 ,
239
+ bottom : 0 ,
238
240
left : 0 ,
239
241
visible : false ,
240
242
stickToRight : false ,
@@ -367,6 +369,7 @@ export default class WriteMarkdownEditor extends React.Component<
367
369
const { lastUploadedImage, initialBody } = this . props ;
368
370
if ( initialBody !== prevProps . initialBody ) {
369
371
if ( ! this . codemirror ) return ;
372
+ if ( this . codemirror . getValue ( ) === this . props . initialBody ) return ;
370
373
this . codemirror . setValue ( this . props . initialBody ) ;
371
374
}
372
375
if (
@@ -403,15 +406,20 @@ export default class WriteMarkdownEditor extends React.Component<
403
406
const cursorPos = this . codemirror . cursorCoords ( cursor ) ;
404
407
if ( ! this . block . current ) return ;
405
408
const stickToRight = cursorPos . left > this . block . current . clientWidth - 341 ;
406
-
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 } ;
407
419
this . setState ( {
408
420
addLink : {
409
421
visible : true ,
410
- top :
411
- this . block . current . scrollTop +
412
- cursorPos . top +
413
- this . codemirror . defaultTextHeight ( ) / 2 +
414
- 1 ,
422
+ ...pos ,
415
423
left : cursorPos . left ,
416
424
stickToRight,
417
425
} ,
@@ -837,6 +845,7 @@ ${selected}
837
845
defaultValue = ""
838
846
left = { addLink . left }
839
847
top = { addLink . top }
848
+ bottom = { addLink . bottom }
840
849
stickToRight = { addLink . stickToRight }
841
850
onConfirm = { this . handleConfirmAddLink }
842
851
onClose = { this . handleCancelAddLink }
0 commit comments