Skip to content

✨ Minimap #33

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

Open
austincondiff opened this issue Mar 31, 2022 · 10 comments
Open

✨ Minimap #33

austincondiff opened this issue Mar 31, 2022 · 10 comments
Assignees
Labels
editor enhancement New feature or request UI

Comments

@austincondiff
Copy link
Collaborator

austincondiff commented Mar 31, 2022

Description

The Minimap provides a compact visual summary of your code, helping you quickly get a sense of the file’s structure and flow. It appears along the right edge of the editor and lets you instantly jump to different parts of the file by clicking or dragging within the highlighted view area.

Implement the visual display system for the Minimap in the source editor. The Minimap should provide a vertically compressed, non-interactive rendering of the entire file's syntax structure. It visually represents the document using color rectangles, offering users an overview for orientation and navigation.

Requirements

  • Display a vertical Minimap next to the code editor view

  • The Minimap should:

    • Represent the full document using only color rectangles, not text
    • Use syntax highlighting colors from the active theme
    • Dynamically reflect updates in the main editor (insert, delete, scroll, etc.)
  • Scrolling and navigation:

    • Scrolling the editor updates the Minimap viewport
    • Clicking or dragging in the Minimap scrolls the editor to the corresponding position
    • A translucent viewport rectangle highlights the currently visible section of the document
  • Selection handling:

    • If there is no selection, highlight the current line
    • If there is a text selection, highlight the selected range
    • If there are multiple selections, show all selection ranges
  • Integration with editor features:

    • Display search result locations (e.g., from Find/Replace)
    • Display error and warning markers (e.g., from diagnostics)
    • Indicate folded regions if any exist
  • Behavior and customization:

    • The Minimap should be toggleable in editor settings

Implementation Details

  • Rendering should be GPU-accelerated or use offscreen rendering for performance
  • Consider lazy rendering or caching for large files to reduce memory and CPU usage
  • The Minimap should not allow direct text editing
  • Rendering of syntax highlight colors can reuse the existing tokenization model

Additional Context

This feature provides users with a consistent and performant way to understand the overall structure of their code. It is especially helpful in long files and serves as a complement to navigation and issue reporting systems in the editor.

This lays the foundation for future enhancements such as semantic structure previews, bookmarks, and inline annotations inside the Minimap.

Screenshots

Image

Resources

Related Issues

@austincondiff austincondiff changed the title Minimap ✨ Minimap Mar 31, 2022
@austincondiff austincondiff added enhancement New feature or request UI editor and removed enhancement New feature or request labels Mar 31, 2022
@nanashili
Copy link

This is do able just not sure where to do it or where to add it in the codebase

@stale stale bot added the wontfix This will not be worked on label Jun 3, 2022
@CodeEditApp CodeEditApp deleted a comment from stale bot Jun 3, 2022
@stale stale bot removed the wontfix This will not be worked on label Jun 3, 2022
@austincondiff austincondiff transferred this issue from CodeEditApp/CodeEdit Jun 24, 2022
@Carlos-Mero
Copy link

Actually I'd prefer the minimap like Xcode rather than VScode. The minimap of Xcode contains more useful features and looks cleaner and much more beautiful. It will definitely take more work to make one like that, but I believe you'll love it too.

@tjkohli
Copy link

tjkohli commented Nov 23, 2022

@Yellow-GGG I agree the Xcode minimap is far more useful; however at the same time I think it may be wiser to ship a minimap with minimal functionality and then add complexity in future releases.

@austincondiff
Copy link
Collaborator Author

@tjkohli I completely agree. We need to get something in place first, then we can iterate and improve.

@Eliulm
Copy link
Contributor

Eliulm commented Apr 2, 2023

Hey @austincondiff, could you assign this to me? I already got some of the CodeEditorView code working:

Image

@matthijseikelenboom matthijseikelenboom moved this from 📋 Todo to 🏃‍♂️ In Progress in CodeEdit Project Apr 6, 2023
@Eliulm
Copy link
Contributor

Eliulm commented Apr 11, 2023

This is the current state of the minimap. Still a lot of bugs to fix, but I am getting there slowly...

Screen.Recording.2023-04-11.at.13.17.24.mov

@thecoolwinter I need to set the bounds of the visibleRange in STTextview+VisibleRange to the visibleBounds of the MinimapView conditionally. How should I rewrite the code, so that I can pass props to visibleTextRange variable?

@austincondiff
Copy link
Collaborator Author

Looks great! Where are we with this?

@Eliulm
Copy link
Contributor

Eliulm commented Apr 30, 2023

Unfortunately, I have had little time recently, since I am currently working on my degree.

I have decided that I am going re-implement the minimap in textkit2, instead of textkit1, since the resizing was very laggy. I have also encountered multiple issues like #184, which need to be resolved first, so that the minimap can work properly.

@austincondiff
Copy link
Collaborator Author

austincondiff commented Feb 27, 2025

@Eliulm are you willing to finish this? If not can you provide the code so we can pick up where you left off?

Edit: I just realized this was done back when we were using STTextView. We are using our own text view. I'd still be interested in seeing what you have though if you still have it.

@thecoolwinter
Copy link
Collaborator

thecoolwinter commented Apr 10, 2025

I'm going to be taking this on, here's my basic plan (I'll be going a similar direction to CodeEditorView like mentioned above):

The minimap is basically another TextView, except it lays out and renders it's lines using small dots. Because the layout manager is related to the text storage now, we can have the minimap and textview share a storage, but each have their own layout information.

The outline of required changes:

  • Create an API to allow for overriding layout and drawing for the layout manager cetv pr
  • Create a Minimap View that tells the layout manager about it's available space, and draws text as small dots
  • Overlay the minimap view on the scrollview in CESE
  • Create a 'viewport' view that tracks the scroll offset of the editor, and matches it on the minimap.

@thecoolwinter thecoolwinter mentioned this issue Apr 11, 2025
10 tasks
thecoolwinter added a commit to CodeEditApp/CodeEditTextView that referenced this issue Apr 19, 2025
### Description

Introduces an API to override how text is laid out by the layout manager. An API consumer can implement an object conforming to the `TextLayoutManagerRenderDelegate` protocol to provide custom behavior.

Introduces tests for new APIs.

Specific changes:
- Created a new `TextLayoutManagerRenderDelegate` which contains optional methods to override layout behavior. All methods are optional, and default to the default implementation.
- Updates the layout manager to use these methods where relevant.
  - Estimated height, line height.
  - Finding `x` position in a line fragment.
  - Creating a view to render a line fragment (`LineFragmentView` by default, but the render delegate can give a custom one).
- Makes lots of variables and methods public that weren't previously. Since we're allowing using the layout manager outside the context of a text view, these are necessarily public.
- `LineFragmentView` is now an `open` class to allow for overriding methods.
- Two methods on `LineFragment` have been marked as depreciated (`xPos` and `rectFor`). These were moved to the `TextLayoutManger` to ensure that the new render delegate can inject it's own behavior for both those methods if available.
- `TextSelectionManager`
  - `draw` method is now public, for drawing selections in a custom context.
  - Updates some methods that were calculating drawing rects to use the layout manager information, rather than text view information. This allows the selection manager's behavior to reflect overridden layout manager behavior.
- Documented exactly what `layoutLines` does in `TextLayoutManager`.
- Removed two misleading methods. `ensureLayoutUntil` was used once, and it was not being used correctly. `preparePositionForDisplay` was only used by that method. Both of these methods destroyed layout information without recourse, sometimes causing text to just disappear despite a perfectly valid layout pass. 
  - `ensureLayoutUntil` could be added back, but needs to be implemented in a way that's additive, rather than removing layout information.
  - Removing these changes didn't effect the ability to jump to scroll positions, or emphasize text ranges.

### Related Issues

* CodeEditApp/CodeEditSourceEditor#33

### Checklist

- [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots
thecoolwinter added a commit that referenced this issue Apr 21, 2025
### Description

Adds a minimap to the editor.

Specific changes:
- Created a new `MinimapView`. This view acts as the container view for
the entire minimap contents including the separator, text bubbles, and
scroll view.
- New classes for the minimap:
- `MinimapContentView` Displays the real contents of the minimap. The
layout manager and selection manager place views and draw into this
view.
- `MinimapLineRenderer` uses the new layout overriding APIs to render
small bubbles rather than text for the minimap. This delegates all
bubble calculation and drawing to a custom view
`MinimapLineFragmentView`.
- `MinimapLineFragmentView` is a subclass of `LineFragmentView` that
calculates and draws bubbles instead of text based on the foreground
color of the line fragment it displays.
- Added a new `showMinimap` parameter to `TextViewController` and
`CodeEditSourceEditor` types.
- Moved all content inset calculation to two methods.
- `updateContentInsets` updates all relevant content insets for the
scroll view, find panel, and minimap in one central place. This method
is deterministic and builds on work @austincondiff and I discussed.
  - `updateTextInsets` updates the text view's insets.

Example app:
- Added minimap toggle
- Moved toggles and settings to it's own view, it was getting large.

### Related Issues

* #33

### Checklist

- [x] Render minimap.
- [x] Make minimap scrollable.
- [x] Add 'visible pane' to minimap.
- [x] Add selections to minimap.
- [x] I read and understood the [contributing
guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md)
as well as the [code of
conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots

Demo resizing & toggling minimap with selections being drawn and
responding to scrolling.


https://github.com/user-attachments/assets/038187d0-df01-4d19-b51c-ce160a891607

Demo scrolling a long document


https://github.com/user-attachments/assets/65a98f74-d201-443e-8f0a-3ee81361f54d

Demo editing text, with selections, dragging, and syntax highlighting.
Note that syntax highlights haven't been updated to highlight the
*entire* minimap visible region. That will be done, but adding to this
PR I think will complicate this PR too much.


https://github.com/user-attachments/assets/6188d560-ffc5-4cef-b6b8-e3c711e8ca27
thecoolwinter added a commit that referenced this issue Apr 22, 2025
### Description

The highlighter should now highlight all ‘visible’ text, including text that is visible in the minimap but not in the TextView. This PR merges the visible text in the minimap with the visible text in the TextView to highlight both. If the minimap is hidden, the highlighter will behave as before and only highlight the text visible in the TextView.

### Related Issues

* #33 

### Checklist

- [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots

https://github.com/user-attachments/assets/4bb7ead0-947d-41bc-96c1-7c7c4df3ad8b
thecoolwinter added a commit to CodeEditApp/CodeEdit that referenced this issue Apr 27, 2025
### Description

Adds a minimap to CodeEdit's editor, as well as a new trailing editor accessory (that only appears when the selected document is a code document), a command to toggle the minimap, and a setting to toggle the minimap.

### Related Issues

* CodeEditApp/CodeEditSourceEditor#33

### Checklist

- [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots

https://github.com/user-attachments/assets/07f21d48-23cf-42dc-b39a-02ba395956cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor enhancement New feature or request UI
Projects
Status: 🏃‍♂️ In Progress
Development

No branches or pull requests

6 participants