-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
WIP: Retain the view position on update of FileViewer and GoToLine #5474
Conversation
d7e3795
to
a99382f
Compare
a99382f
to
4ea58a9
Compare
It is almost done. Are there concerns against my approach? |
Apologies, I haven't had a chance to look, I have a lot of RL commitments atm that are taking precedence. |
I didn't want to push you. With the first commit and the WIP PR, I just wanted to indicate that I work on these issues. Today, I mainly wanted to get some reinsurance. This can wait. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to run it, just reviewed it in GH UI.
In general I very much like the idea of centralising the behaviour and removing it from consumers. I think it is a move in the right direction.
On a flip side I'm finding the new code somewhat difficult to comprehend. The lack of tests and testability (of the new code) is very concerning to me as well.
I totally appreciate the existing code isn't particularly extensible and doesn't lend itself well to testing, but we shouldn't continue with bad practices :)
At the moment I don't have any suggestions on how to restructure the code to be testable or easier to read, but I'll think about in coming days.
private bool _visible = true; | ||
|
||
public DiffViewerLineNumberControl(TextArea textArea) : base(textArea) | ||
{ | ||
DiffLines = new Dictionary<int, DiffLineNum>(); | ||
} | ||
|
||
/// <summary> | ||
/// returns the according line numbers or null if the caretLine is not mapped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rephrase the summary, it is quite confusing now
@@ -14,21 +14,33 @@ internal class DiffViewerLineNumberControl : AbstractMargin | |||
|
|||
private Dictionary<int, DiffLineNum> DiffLines { get; set; } | |||
|
|||
private int _maxValueOfLineNum; | |||
public int MaxValueOfLineNum { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to MaxLineNumber
to keep it consistent with DiffLineNumAnalyzer.Result.MaxLineNumber
Worth adding a comment explaining the purpose of the property
GitUI/Editor/FileViewerInternal.cs
Outdated
|
||
public Action OpenWithDifftool { get; private set; } | ||
|
||
private struct ViewPosition | ||
{ | ||
internal string FirstLine; // contains the file names in case of a diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change comments to proper xml-doc
Same for the rest of fields in the struct.
GitUI/Editor/FileViewerInternal.cs
Outdated
private struct ViewPosition | ||
{ | ||
internal string FirstLine; // contains the file names in case of a diff | ||
internal int TotalNumberOfLines; // if changed, CaretPosition and FirstVisibleLine must be ignored and the line number must be searched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is not very clear on its intent
GitUI/Editor/FileViewerInternal.cs
Outdated
_previousViewPosition.ActiveLineNum = null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made a rule to keep all private functions (if they are necessary) at the end of parent functions, after return
statement. If return
statement is missing, it gets added.
Please move this function to the end.
GitUI/Editor/FileViewerInternal.cs
Outdated
void SetActiveLineNum(int line) | ||
{ | ||
_previousViewPosition.ActiveLineNum = _lineNumbersControl.GetLineNum(line); | ||
if (_previousViewPosition.ActiveLineNum != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please invert all if
s to reduce nesting.
This applies to other cases as well.
GitUI/Editor/FileViewerInternal.cs
Outdated
int initialActiveLine = _previousViewPosition.CaretVisible ? _previousViewPosition.CaretPosition.Line : _previousViewPosition.FirstVisibleLine; | ||
if (/*a diff was displayed*/!TextEditor.ShowLineNumbers) | ||
{ | ||
void SetActiveLineNum(int line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make the method "purer", that is determine the value of ActiveLineNum
and return it, rather than set it to _previousViewPosition.ActiveLineNum
.
{ | ||
return lineNumber - 1; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
is redundant
GitUI/Editor/FileViewerInternal.cs
Outdated
_previousViewPosition.TotalNumberOfLines = TotalNumberOfLines; | ||
_previousViewPosition.CaretPosition = TextEditor.ActiveTextAreaControl.Caret.Position; | ||
_previousViewPosition.FirstVisibleLine = FirstVisibleLine; | ||
_previousViewPosition.CaretVisible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the only place where CaretVisible
is set. And for the most part it is based off what the struct already "knows" bar TextEditor.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount
.
It kind of feels it would be a good candidate for a method placed in ViewPosition
however it also becomes dependent on the order in which other properties are set, which is equally bad...
I had a little bit of time and tweaked the API slightly, these tweaks mainly deal with the overall hygiene of the code related to the PR (not necessarily originated by you). |
Extract functionality get/set of the current view position into own methods.
232819f
to
c292e7c
Compare
To faciliate testing `GitHighlightingStrategyBase` must depend on `IGitModule` instead of `GitModule`. This change requires a little hack because `IConfigFileSettings` does not expose `GetString(string, stirng)` that is exposed by `ConfigFileSettings` class. This will need to be reconciled separately later.
Michael, please have a look at the refactor I pushed. Eager to hear your thoughts. |
|
||
if (isDiff) | ||
{ | ||
_lineNumbersControl.DisplayLineNumFor(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be too early now: _lineNumbersControl
holds a reference to the TextEditor.ActiveTextAreaControl.TextArea
but TextEditor.Text
has not been updated yet.
I'll check whether this matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check, I grouped them together but the order may matter
return false; | ||
} | ||
if (index == 1 && char.IsWhiteSpace(c)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, this additional indentation was not intended, was it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it wasn't. Looks like my VS settings are different
Thank you for the refactorings (I like the very descriptive identifier |
Superseded by #5563 |
Fixes #5327
base functionality for #5328
Changes proposed in this pull request:
The following will be done in a dedicated PR for #5328:
FileViewer
Maybe a new issue:
Screenshots before and after (if PR changes UI):
What did I do to test the code and ensure quality:
Has been tested on (remove any that don't apply):