Skip to content

Commit bdfcfc2

Browse files
committed
Restore scroll into view behavior
1 parent 1ff046c commit bdfcfc2

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

packages/host/app/components/matrix/room-message-command.gts

+20-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cached } from '@glimmer/tracking';
77

88
import { task, timeout } from 'ember-concurrency';
99

10-
// import { modifier } from 'ember-modifier';
10+
import { modifier } from 'ember-modifier';
1111

1212
import { resource, use } from 'ember-resources';
1313

@@ -43,6 +43,7 @@ import type { CardDef } from 'https://cardstack.com/base/card-api';
4343
import ApplyButton from '../ai-assistant/apply-button';
4444
import { type ApplyButtonState } from '../ai-assistant/apply-button';
4545
import Preview from '../preview';
46+
import { next } from '@ember/runloop';
4647

4748
interface Signature {
4849
Element: HTMLDivElement;
@@ -123,36 +124,23 @@ export default class RoomMessageCommand extends Component<Signature> {
123124
);
124125
};
125126

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+
}
156144

157145
private get headerTitle() {
158146
if (this.commandResultCard.card) {
@@ -244,7 +232,7 @@ export default class RoomMessageCommand extends Component<Signature> {
244232
</Button>
245233
<div
246234
class='monaco-container'
247-
{{! this.scrollBottomIntoView }}
235+
{{this.scrollBottomIntoView}}
248236
{{monacoModifier
249237
content=this.previewCommandCode
250238
contentChanged=undefined

0 commit comments

Comments
 (0)