@@ -7,7 +7,7 @@ import { cached } from '@glimmer/tracking';
7
7
8
8
import { task , timeout } from ' ember-concurrency' ;
9
9
10
- // import { modifier } from 'ember-modifier';
10
+ import { modifier } from ' ember-modifier' ;
11
11
12
12
import { resource , use } from ' ember-resources' ;
13
13
@@ -43,6 +43,7 @@ import type { CardDef } from 'https://cardstack.com/base/card-api';
43
43
import ApplyButton from ' ../ai-assistant/apply-button' ;
44
44
import { type ApplyButtonState } from ' ../ai-assistant/apply-button' ;
45
45
import Preview from ' ../preview' ;
46
+ import { next } from ' @ember/runloop' ;
46
47
47
48
interface Signature {
48
49
Element: HTMLDivElement ;
@@ -123,36 +124,23 @@ export default class RoomMessageCommand extends Component<Signature> {
123
124
);
124
125
};
125
126
126
- // TODO need to reevalutate this modifier--do we want to hijack the scroll
127
- // when the user views the code?
128
- // private scrollBottomIntoView = modifier((element: HTMLElement) => {
129
- // if (this.args.currentEditor !== this.args.messageIndex) {
130
- // return;
131
- // }
132
-
133
- // let height = this.monacoService.getContentHeight();
134
- // if (!height || height < 0) {
135
- // return;
136
- // }
137
- // element.style.height = `${height}px`;
138
-
139
- // let outerContainer = document.getElementById(
140
- // `message-container-${this.args.messageIndex}`,
141
- // );
142
- // if (!outerContainer) {
143
- // return;
144
- // }
145
- // this.scrollIntoView(outerContainer);
146
- // });
147
-
148
- // private scrollIntoView(element: HTMLElement) {
149
- // let { top, bottom } = element.getBoundingClientRect();
150
- // let isVerticallyInView = top >= 0 && bottom <= window.innerHeight;
151
-
152
- // if (!isVerticallyInView) {
153
- // element.scrollIntoView({ block: 'end' });
154
- // }
155
- // }
127
+ private scrollBottomIntoView = modifier ((element : HTMLElement ) => {
128
+ let height = this .monacoService .getContentHeight ();
129
+ if (! height || height < 0 ) {
130
+ return ;
131
+ }
132
+ element .style .height = ` ${height }px ` ; // max-height is constrained by CSS
133
+ next (this , this .scrollIntoView , element .parentElement as HTMLElement );
134
+ });
135
+
136
+ private scrollIntoView(element : HTMLElement ) {
137
+ let { top, bottom } = element .getBoundingClientRect ();
138
+ let isVerticallyInView = top >= 0 && bottom <= window .innerHeight ;
139
+
140
+ if (! isVerticallyInView ) {
141
+ element .scrollIntoView ({ block: ' end' });
142
+ }
143
+ }
156
144
157
145
private get headerTitle() {
158
146
if (this .commandResultCard .card ) {
@@ -244,7 +232,7 @@ export default class RoomMessageCommand extends Component<Signature> {
244
232
</Button >
245
233
<div
246
234
class =' monaco-container'
247
- {{! this.scrollBottomIntoView }}
235
+ {{this .scrollBottomIntoView }}
248
236
{{monacoModifier
249
237
content =this . previewCommandCode
250
238
contentChanged =undefined
0 commit comments