Skip to content

Resolve "Selection Highlight Oversteps Bounds in Web IDE"

Tomas Vik requested to merge 216491-monaco-diff-selection into master

What does this MR do?

This MR fixes WebIDE Monaco editor styling to remove several overlay issues.

TL;DR: Our styles were breaking Monaco. Monaco layers overlays (selection, diff and other highlights) over each line of code. The UI was broken because we set full opacity to diff highlight (instead of 0.2) and we displayed text selection highlight with the highest z-index when it was supposed to be the lowest.

Issue in detail

Each line in Monaco editor can have multiple overlays.

Example overlays:

  • tip ligthbulb small13

  • matching parenthesis highlight small14

  • line and character diff highlight small15

  • function scope line small16

  • text selection small17

The overlays have a certain order that's implemented in Monaco itself. For example, in the issue #216491 (closed) of selection overstepping boundary the overlays look as follows:

issue-higlighted

Screenshot_2020-09-04_at_10.30.56_AM

The issue of overlay overstepping boundary was caused by us forcing the .selected-text z-index. This broke the Monaco internal logic, which layers background tile over the .selected-text highlight.

History: Setting full opacity to the diff highlight caused selected text highlight not being visible gitlab-foss#47771 (closed) and so we fixed it by setting z-index on the selected text highlight

The solution

We must style the overlays the same way Monaco does to prevent this and future issues. In our case, it means:

  • not setting z-index on text selection highlight so it can be overlayed with other layers
  • making the diff highlight colors transparent so they don't completely cover the overlays below them (this only affects light-mode, because we didn't change the values for dark mode)

Screenshots

Light mode

scenario before after
selecting a function Screenshot_2020-09-04_at_10.25.46_AM Screenshot_2020-09-04_at_10.25.16_AM
diff view (should look the same) Screenshot_2020-09-04_at_10.35.39_AM Screenshot_2020-09-04_at_10.35.59_AM
diff view with cursor in function body (notice the function scope line missing) Screenshot_2020-09-04_at_10.36.45_AM Screenshot_2020-09-04_at_10.37.00_AM
selection in diff mode notice the how the selection highlight hid diff higligting and the lightbulb Screenshot_2020-09-04_at_10.38.00_AM Screenshot_2020-09-04_at_10.38.11_AM

Dark mode

We didn't override the diff highlighting in dark mode and so this MR only fixes selection-related issues:

scenario before after
diff view (should look the same) Screenshot_2020-09-04_at_10.44.26_AM Screenshot_2020-09-04_at_10.44.45_AM
selecting a function Screenshot_2020-09-04_at_10.48.11_AM Screenshot_2020-09-04_at_10.48.22_AM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Part of #216491 (closed)

Edited by Tomas Vik

Merge request reports