@@ -8,13 +8,12 @@ import { tracked } from '@glimmer/tracking';
8
8
9
9
import { task } from ' ember-concurrency' ;
10
10
import perform from ' ember-concurrency/helpers/perform' ;
11
-
11
+ import { modifier } from ' ember-modifier ' ;
12
12
import { marked } from ' marked' ;
13
13
14
14
import { Button } from ' @cardstack/boxel-ui/components' ;
15
15
import { eq } from ' @cardstack/boxel-ui/helpers' ;
16
16
import { Copy as CopyIcon } from ' @cardstack/boxel-ui/icons' ;
17
- import { setCssVar } from ' @cardstack/boxel-ui/modifiers' ;
18
17
19
18
import { sanitizeHtml } from ' @cardstack/runtime-common' ;
20
19
@@ -47,6 +46,7 @@ interface Signature {
47
46
export default class Room extends Component <Signature > {
48
47
<template >
49
48
<AiAssistantMessage
49
+ id =' message-container-{{@ message.index }} '
50
50
class =' room-message'
51
51
@ formattedMessage ={{htmlSafe this . formattedMessage}}
52
52
@ datetime ={{@ message.created }}
@@ -110,7 +110,7 @@ export default class Room extends Component<Signature> {
110
110
</Button >
111
111
<div
112
112
class =' monaco-container'
113
- {{setCssVar monaco-container-height = this . monacoContainerHeight }}
113
+ {{this .scrollBottomIntoView }}
114
114
{{monacoModifier
115
115
content =this . previewPatchCode
116
116
contentChanged =undefined
@@ -251,13 +251,32 @@ export default class Room extends Component<Signature> {
251
251
}
252
252
}
253
253
254
- private get monacoContainerHeight() {
255
- if (this .args .currentEditor === this .args .message .index ) {
256
- let height = this .monacoService .getContentHeight ();
257
- if (height && height > 0 ) {
258
- return ` ${height }px ` ;
259
- }
254
+ private scrollBottomIntoView = modifier ((element : HTMLElement ) => {
255
+ if (this .args .currentEditor !== this .args .message .index ) {
256
+ return ;
257
+ }
258
+
259
+ let height = this .monacoService .getContentHeight ();
260
+ if (! height || height < 0 ) {
261
+ return ;
262
+ }
263
+ element .style .height = ` ${height }px ` ;
264
+
265
+ let outerContainer = document .getElementById (
266
+ ` message-container-${this .args .message .index } ` ,
267
+ );
268
+ if (! outerContainer ) {
269
+ return ;
270
+ }
271
+ this .scrollIntoView (outerContainer );
272
+ });
273
+
274
+ private scrollIntoView(element : HTMLElement ) {
275
+ let { top, bottom } = element .getBoundingClientRect ();
276
+ let isVerticallyInView = top >= 0 && bottom <= window .innerHeight ;
277
+
278
+ if (! isVerticallyInView ) {
279
+ element .scrollIntoView ({ block: ' end' });
260
280
}
261
- return undefined ;
262
281
}
263
282
}
0 commit comments