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

Highlight consumed batch input #196

Merged
merged 17 commits into from
May 30, 2022

Conversation

winniederidder
Copy link
Contributor

@winniederidder winniederidder commented May 22, 2022

This PR adds support for highlighting the lines that have been consumed in batch mode.
A div element with contenteditable=true has some undesirable default behaviour that is very clunky and error-prone to work with (first child is a TextNode before using divs, replacing that TextNode with a div causes new elements to appear, ...) so I decided to stop using it. Instead, CodeMirror already provides an editor with plenty of flexiblity and a useful API. This editor can then share some code with the CodeEditor-class.

To provide actual highlighting and gutters, I added new classes. The Gutters base class allows creating arbitrary gutters (such as the checkmark gutter, but also a breakpoint gutter (useful for #109)). To prevent code duplication in the BatchInputEditor, I created a base class grouping similar functionality between the input and the code editor together. I also used the CodeMirror theme extension to properly fix the layout of the editor is always correct.

The highlight-style is still up for debate. I currently use the built-in CodeMirror activeLine classes.

Closes #82
Depends on #195 (to be able to use cleaned version of onChange in the new Editor base class)

@winniederidder
Copy link
Contributor Author

Example of current styling with both a checkmark gutter and a highlighted line.
Thoughts @pdawyndt @bmesuere ? Do we want the gutter, the highlights, both, ...?
input-consumed

@pdawyndt
Copy link
Contributor

@winniederidder: can you deploy on /dev? Would help to see it in action

@winniederidder winniederidder temporarily deployed to production May 26, 2022 09:17 Inactive
@winniederidder
Copy link
Contributor Author

@winniederidder: can you deploy on /dev? Would help to see it in action

Branch is being deployed, should be available in a minute or two.

@pdawyndt
Copy link
Contributor

pdawyndt commented May 26, 2022

I get a blinking cursor that spans across two lines

image

and a dotted margin to the left and right of the input field

image

I would like to see a version that uses the gutter, as it seems valuable to have a tooltip somehow. Maybe also no background color change, but just grey out the consumed lines?
image

@winniederidder
Copy link
Contributor Author

I get a blinking cursor that spans across two lines

image

and a dotted margin to the left and right of the input field

image

I would like to see a version that uses the gutter, as it seems valuable to have a tooltip somehow. Maybe also no background color change, but just grey out the consumed lines? image

Seems I forgot to push, so the version you are using is not the one I used to make the screenshot with.
As far as the blinking cursor, this is because the placeholder spans two lines and the CodeMirror placeholder doesn't handle that very well. Maybe we can use a shorter piece of text if we don't want the two-line spanning.

@winniederidder winniederidder temporarily deployed to production May 26, 2022 09:36 Inactive
@pdawyndt
Copy link
Contributor

One other observation: after initial load, the code editor has a narrow gutter

image

and after a few seconds is given a broader gutter (probably after linting has become active)

image

This seems unwanted UI-behaviour.

@winniederidder
Copy link
Contributor Author

One other observation: after initial load, the code editor has a narrow gutter

image

and after a few seconds is given a broader gutter (probably after linting has become active)

image

This seems unwanted UI-behaviour.

This is indeed linting becoming active when a lintSource is provided. Currently, the gutters are absent until linting is possible, but I can add them by default again if this is unwanted behaviour.

@pdawyndt
Copy link
Contributor

Unwanted behaviour according to me.

@pdawyndt
Copy link
Contributor

pdawyndt commented May 26, 2022

Input field gutter doesn’t span entire height if height of input field increases.

image

@winniederidder winniederidder force-pushed the highlight-consumed-batch-input branch from ef539be to 57c83fc Compare May 26, 2022 15:41
@winniederidder winniederidder marked this pull request as ready for review May 26, 2022 20:25
@winniederidder winniederidder changed the base branch from main to run-doctests May 26, 2022 20:26
@winniederidder winniederidder force-pushed the highlight-consumed-batch-input branch from 534dae5 to d5e86a7 Compare May 26, 2022 20:28
@winniederidder winniederidder force-pushed the highlight-consumed-batch-input branch from d5e86a7 to ec7d824 Compare May 26, 2022 20:51
@pdawyndt
Copy link
Contributor

Also check UI in dark mode

@winniederidder winniederidder temporarily deployed to production May 27, 2022 07:52 Inactive
@pdawyndt
Copy link
Contributor

LGTM

Papyros.-.Google.Chrome.2022-05-27.10-39-33.mp4

@pdawyndt
Copy link
Contributor

pdawyndt commented May 27, 2022

If the goal was to make consumed input read-only, this still doesn't work. I can still edit lines after they have been consumed.

@winniederidder
Copy link
Contributor Author

If the goal was to make consumed input read-only, this still doesn't work. I can still edit lines after they have been consumed.

Currently, these are indeed not made read-only. This might indeed be something that we want.

@winniederidder winniederidder temporarily deployed to production May 27, 2022 09:45 Inactive
@winniederidder
Copy link
Contributor Author

If the goal was to make consumed input read-only, this still doesn't work. I can still edit lines after they have been consumed.

I have now also added support to making consumed lines read-only while the run is happening.

@winniederidder winniederidder requested a review from bmesuere May 27, 2022 09:45
@pdawyndt
Copy link
Contributor

We might add the prompt that was used when a line of input was consumed, to the tooltip of the icon (check mark) in the gutter of the input field. This way, students can inspect which line was consumed by which prompt.

Extension: if the same prompt is used more than once in the same run, we could add a number indicating what instance of the prompt we refer to (e.g. “What is your name? (3)” = third instance).

@winniederidder
Copy link
Contributor Author

winniederidder commented May 27, 2022

We might add the prompt that was used when a line of input was consumed, to the tooltip of the icon (check mark) in the gutter of the input field. This way, students can inspect which line was consumed by which prompt.

Extension: if the same prompt is used more than once in the same run, we could add a number indicating what instance of the prompt we refer to (e.g. “What is your name? (3)” = third instance).

It already shows the prompt, if there was one. Adding a number to duplicate prompts sounds like overly complicating things, as I don't think prompts will often have the same question (unless empty, but then it also doesn't serve a purpose to number it).
prompt

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.

Highlight consumed batch input
2 participants