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

Programming exercises: Remember scrolling position when switching between files in the online editor #10053

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

chrisknedl
Copy link
Contributor

@chrisknedl chrisknedl commented Dec 19, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.

Motivation and Context

Closes #8402.

Description

The scrollTop attribute is added to the editor file session. It stores the absolute distance from the top of the viewport to the beginning of the file. This makes it possible to restore the scroll positions of files that have been previously looked at in a straightforward way.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 programming exercise with online editor and manual assessment
  1. Open the code editor
  2. Scroll down in one of the files in the editor (if necessary, add some text so that you can actually scroll down)
  3. Switch to a different file, and go back to the file where you scrolled down
  4. It should still show the lines that it showed before switching
    -> Try different files and different scrolling positions
  5. Manually assess a programming exercise submission via the assessment dashboard
  6. Add inline comments by clicking on the '+' sign on the left of the code editor
  7. Repeat steps 2 - 4 for the assessment editor. It should still remember the scroll position correctly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
code-editor-monaco.component.ts 93.53%
monaco-editor.component.ts 94.87%

Summary by CodeRabbit

  • New Features

    • The code editor now remembers and restores the vertical scroll position when navigating between files.
    • New methods added to control the scroll position of the editor externally.
  • Bug Fixes

    • Updated tests to ensure the scroll position is correctly managed and verified during file selection and other operations.
  • Tests

    • Enhanced test suite to include scenarios for the new scroll position functionality.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Dec 19, 2024
@b-fein b-fein changed the title Programming exercises: Remember scroll position when switching between files Programming exercises: Remember scroll position when switching between files in the online editor Dec 20, 2024
@chrisknedl chrisknedl added component:MarkdownEditor assessment Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module enhancement feature labels Dec 20, 2024
@chrisknedl chrisknedl changed the title Programming exercises: Remember scroll position when switching between files in the online editor Programming exercises: Remember scrolling position when switching between files in the online editor Dec 20, 2024
@chrisknedl chrisknedl marked this pull request as ready for review December 20, 2024 12:26
@chrisknedl chrisknedl requested a review from a team as a code owner December 20, 2024 12:26
Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request addresses the issue of maintaining scroll positions when switching between files in the Monaco code editor. The changes involve updating the FileSession type to include a scrollTop property, which tracks the vertical scroll position for each file. New methods are introduced in the CodeEditorMonacoComponent and MonacoEditorComponent to manage and restore scroll positions when navigating between files, ensuring that users can return to their previous scroll location in each file.

Changes

File Change Summary
src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts - Updated FileSession type to include scrollTop
- Added switchToSelectedFile method
- Modified ngOnChanges, selectFileInEditor, and onFileTextChanged to handle scroll position
src/main/webapp/app/shared/monaco-editor/monaco-editor.component.ts - Added getScrollTop() method
- Added setScrollTop(scrollTop: number) method
src/test/javascript/spec/component/code-editor/code-editor-monaco.component.spec.ts - Updated test cases to include scrollTop property
- Added test to verify scroll position persistence

Assessment against linked issues

Objective Addressed Explanation
Persist scrolling position when switching files [#8402]
Maintain scroll state across different files
Support scroll position tracking in online editor

Possibly related PRs

Suggested labels

bugfix, ready to merge

Suggested reviewers

  • az108
  • JohannesStoehr
  • coolchock
  • egekurt123
  • b-fein
  • Jan-Thurner

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts (1)

220-224: Consider simplifying the scroll position access.

The null coalescing operator is unnecessary since the scrollTop property is guaranteed to exist in the FileSession type.

-        this.editor().setScrollTop(this.fileSession()[this.selectedFile()!].scrollTop ?? 0);
+        this.editor().setScrollTop(this.fileSession()[selectedFileName].scrollTop);

Also, consider using the selectedFileName parameter instead of this.selectedFile()! for consistency and to avoid the non-null assertion.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d0a9e9 and ff52315.

📒 Files selected for processing (3)
  • src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts (4 hunks)
  • src/main/webapp/app/shared/monaco-editor/monaco-editor.component.ts (1 hunks)
  • src/test/javascript/spec/component/code-editor/code-editor-monaco.component.spec.ts (13 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/main/webapp/app/shared/monaco-editor/monaco-editor.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/code-editor/code-editor-monaco.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (7)
src/test/javascript/spec/component/code-editor/code-editor-monaco.component.spec.ts (1)

485-497: LGTM! Comprehensive test coverage for scroll position functionality.

The new test case effectively verifies that the scroll position is preserved when switching between files. The test setup is clear and the assertions are precise.

src/main/webapp/app/shared/monaco-editor/monaco-editor.component.ts (1)

192-198: LGTM: Clean implementation of scroll position management.

The new methods provide a clean interface for managing scroll positions in the Monaco editor, properly exposing the underlying Monaco editor's scroll functionality.

src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts (5)

45-45: LGTM: Well-structured type definition.

The FileSession type has been properly extended to include the scrollTop property for tracking scroll positions.


160-164: LGTM: Proper scroll position preservation.

The implementation correctly saves the scroll position before switching files, with appropriate null checks for safety.


204-207: LGTM: Clean initialization of new file sessions.

New file sessions are properly initialized with default values, including a scroll position of 0.


229-234: LGTM: Proper scroll position preservation during content updates.

The implementation correctly preserves the scroll position when updating file content.


425-425: LGTM: Proper initialization of new files.

New files are correctly initialized with default values, including a scroll position of 0.

Copy link
Contributor

@b-fein b-fein left a comment

Choose a reason for hiding this comment

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

Code looks good.

Also tested for the manual assessment scenario with many inline feedbacks for the files. They were always rendered in the correct location and the scroll position remained correct when switching back to a file. 👍

Good job, very nice improvement!

@github-actions github-actions bot removed the assessment Pull requests that affect the corresponding module label Dec 20, 2024
Copy link

@sawys777 sawys777 left a comment

Choose a reason for hiding this comment

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

Tested on TS3, everything works as described.

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

Tested on TS1. Everything works as expected

Copy link

@Cathy0123456789 Cathy0123456789 left a comment

Choose a reason for hiding this comment

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

Tested on TS1. Works as described, scroll positions are maintained in both scenarios

Copy link

@flbrgit flbrgit left a comment

Choose a reason for hiding this comment

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

Tested on TS1, everything works as expected in code and assessment editor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

Programming exercises: Scrolling position does not persist over a file switch in the online editor
7 participants