Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Remove fixed height for editor #4915

Merged
merged 7 commits into from
Dec 20, 2023
Merged

[FIX] Remove fixed height for editor #4915

merged 7 commits into from
Dec 20, 2023

Conversation

rix0rrr
Copy link
Collaborator

@rix0rrr rix0rrr commented Dec 17, 2023

Fixes #4895

We used to set fixed pixel heights for the (CodeMirror) editor; one of the things we would do is measure the height of the container during editor initialization, and then force the editor to have that height.

On the slides page, where we would load a lot of pages in <iframe>s that would start out hidden, the calculated height would sometimes be measured as 0px, which would then be copied onto the editor. The end result would be that the editor would appear empty on some pages.

Instead, in this PR: remove all height calculations. We will set a height on the grid cells that contain the editor and output box, and add the CSS declarations necessary to make the actual editor automatically resize to take up available remaining space, after any fixed elements in the same cell are taken away (like the error and success popups, the "handed in" warning box, etc).

This makes it no longer necessary to recalculate the height of the editor every time one of those popups is shown or hidden.

For the "developer mode" toggle, we introduce a new attribute: data-devmodeheight="22rem,36rem", and the toggle will switch between the two sizes in the attribute. This avoids having to duplicate element sizes between HTML and JavaScript.

How to test

Verify this solves #4895 by examining the slides of level 1 and seeing that all code blocks are always shown.

We used to set fixed pixel heights for the (CodeMirror) editor; one
of the things we would do is measure the height of the container
during editor initialization, and then force the editor to have that
height.

On the slides page, where we would load a lot of pages in `<iframe>`s
that would start out hidden, the calculated height would sometimes
be measured as `0px`, which would then be copied onto the editor.
The end result would be that the editor would appear empty on some
pages.

Instead, in this PR: remove all height calculations. We will set a
height on the entire editor grid (containing the editor and output box,
and navigation buttons), and add the CSS declarations necessary to make
the editor automatically resize to take up available remaining
space, after the fixed elements are taken away (like the buttons
at the bottom, the error and success popups, the "handed in" warning
box, etc).

This makes it no longer necessary to recalculate the height of the
editor every time one of those popups is shown or hidden.
@rix0rrr rix0rrr requested a review from jpelay December 17, 2023 13:07
@ghost
Copy link

ghost commented Dec 17, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@hasan-sh hasan-sh self-requested a review December 18, 2023 09:52
Copy link
Member

@jpelay jpelay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great! When I am in the /hedy page, the editor get resized properly. Also, now the embedded editor adjusts nicely to the iframe settings. There are some things that I wonder if we might do a bit better.

In the slides when the code overflows the width, 2 scroll-bars are shown.
image

Now the gutter looks a bit different than the background, I wonder if maybe we can set it to be the same color as the background so the editor doesn't look incomplete?

image

Sort of like Vs Code does

image

@rix0rrr
Copy link
Collaborator Author

rix0rrr commented Dec 18, 2023

Ah good call. Let me fiddle some more then.

Copy link
Collaborator

@hasan-sh hasan-sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to dev mode works.

I also noticed the issue that Jesus pointed out. In addition, we have the following:

Screenshot from 2023-12-18 14-10-08

The iframe is not taking the full height. It's more noticable here:

Screenshot from 2023-12-18 16-42-47

and
Screenshot from 2023-12-18 16-48-19

I think both can be solved in a separate PR? Shall we create an issue for this?

@rix0rrr
Copy link
Collaborator Author

rix0rrr commented Dec 19, 2023

Yeah, the layout of the slides itself is out of scope for this PR. Good attention to detail! We can ask Felienne how she wants it to look.

@rix0rrr
Copy link
Collaborator Author

rix0rrr commented Dec 19, 2023

@jpelay @hasan-sh I've changed the method to limit the height of the editor; instead of having a growing editor inside a container that we limit using Tailwind, I've added some styles on the .cm-xxx elements themselves in a way I found recommended on the CodeMirror forums.

Added a new container tag so this readonly editors used for sample code highlighting (#4924) can still grow with the content.

I don't have an easy way to check how this looks on Windows. Can one of you check if this fixes the scrollbar issue?

@hasan-sh
Copy link
Collaborator

hasan-sh commented Dec 19, 2023

@jpelay @hasan-sh I've changed the method to limit the height of the editor; instead of having a growing editor inside a container that we limit using Tailwind, I've added some styles on the .cm-xxx elements themselves in a way I found recommended on the CodeMirror forums.

Great!

I don't have an easy way to check how this looks on Windows. Can one of you check if this fixes the scrollbar issue?

I use and it works on linux so I don't have Windows either. Hopefully Jesus does! Otherwise will figure something out!

@rix0rrr
Copy link
Collaborator Author

rix0rrr commented Dec 19, 2023

Linux is also fine. Just another platform than Mac -- Mac really de-emphasizes the scroll bars by default which makes it hard to see when they're wrong.

@Felienne
Copy link
Member

Great! If all is well you may approve this @hasan-sh!

Copy link
Collaborator

@hasan-sh hasan-sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

mergify bot commented Dec 20, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@jpelay
Copy link
Member

jpelay commented Dec 20, 2023

Works great!!! Just tested this on windows and it works properly there too on Chrome and Firefox

Copy link
Contributor

mergify bot commented Dec 20, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 47f061d into main Dec 20, 2023
11 checks passed
@mergify mergify bot deleted the no-fixed-height branch December 20, 2023 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Code in slides not rendered, also achievements mustn't show
4 participants