Correct suggestions for multiple comment boxes
What does this MR do and why?
For #330996 (closed)
This MR fixes the lines used for suggestions (and the multiline header) so that every discussion form has the correct values.
Problem
The previous implementation sets a single global variable that has the current comment range/position. If multiple comment forms are open, the most recent multi-line form will always be the lines used (e.g. for suggestions).
Solution
This MR just moves the local question "what lines is this comment form related to" to be local state.
There are two basic parts:
- When the view is interacted with, a single "range" property is updated, and when the form is opened, that range is sent to the form and disconnected from live updates. This keeps each form isolated once it's been opened.
- When the user manually changes the start line using the multi-line header (whether it started as multi-line or not), the note form is updated with the new range so that suggestions update appropriately.
Screenshots or screen recordings
There are a number of different scenarios that can appear with this defect, since it's basically just "any discussion after the first will use the most recently opened."
However, here are two common scenarios:
- two multi-line discussions are opened
- a multi-line discussion is opened, followed by a single-line discussion
Before | After | |
---|---|---|
Scenario 1 | ||
Scenario 2 |
Also note in Scenario 2 (before), the multi-line header was incorrectly showing the start line of the above multi-line comment even though the open discussion form was a single-line (comment bubble click) on a later line. This is a symptom of the same problem, but it's notably wrong - and corrected in this MR.
How to set up and validate locally
- Create an MR with a file that has at least 5 lines of changes
- Create a comment by dragging the comment bubble from line 1 to line 2
- Click the insert suggestion button (note that the lines should reflect lines 1 & 2)
- Create a comment by dragging the comment bubble from line 3 to line 4
- Click the insert suggestion button (note that the lines should reflect lines 3 & 4)
- Click the comment bubble on line 5
- Click the insert suggestion button (note that the line should reflect line 5)
Without the changes, the following happens:
-
-
- This still works
-
- This still works, however, on the open comment box created in step 3, the
Insert suggestion
button now inserts lines 3 & 4 -
- This suggestion text is the lines from the most recently opened discussion form. In this case, lines 3 & 4.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.