Debugger: Fixed issues with textbox when strings are padded with spaces (to find word behind mouse cursor)
This commit is contained in:
parent
2058ded5ae
commit
0587c59cbb
1 changed files with 30 additions and 37 deletions
|
@ -498,9 +498,10 @@ namespace Mesen.GUI.Debugger
|
||||||
|
|
||||||
public int GetLineIndexAtPosition(int yPos)
|
public int GetLineIndexAtPosition(int yPos)
|
||||||
{
|
{
|
||||||
int charIndex;
|
int lineIndex = this.ScrollPosition + this.GetLineAtPosition(yPos);
|
||||||
int lineIndex;
|
if(lineIndex > _contents.Length && _contents.Length != 0) {
|
||||||
GetCharIndex(new Point(0, yPos), out charIndex, out lineIndex);
|
lineIndex = _contents.Length - 1;
|
||||||
|
}
|
||||||
return lineIndex;
|
return lineIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,29 +516,20 @@ namespace Mesen.GUI.Debugger
|
||||||
|
|
||||||
private bool GetCharIndex(Point position, out int charIndex, out int lineIndex)
|
private bool GetCharIndex(Point position, out int charIndex, out int lineIndex)
|
||||||
{
|
{
|
||||||
charIndex = -1;
|
charIndex = int.MaxValue;
|
||||||
using(Graphics g = Graphics.FromHwnd(this.Handle)) {
|
using(Graphics g = Graphics.FromHwnd(this.Handle)) {
|
||||||
int marginLeft = this.GetMargin(g, true);
|
int marginLeft = this.GetMargin(g, true);
|
||||||
int positionX = position.X - marginLeft;
|
lineIndex = this.GetLineIndexAtPosition(position.Y);
|
||||||
lineIndex = this.ScrollPosition + this.GetLineAtPosition(position.Y);
|
if(lineIndex >= _contents.Length) {
|
||||||
if(lineIndex > _contents.Length && _contents.Length != 0) {
|
return false;
|
||||||
lineIndex = _contents.Length - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(positionX >= 0 && lineIndex < _contents.Length) {
|
int positionX = position.X - marginLeft;
|
||||||
string text = this.GetFullWidthString(lineIndex).Trim();
|
positionX -= (LineIndentations != null ? LineIndentations[lineIndex] : 0);
|
||||||
//Adjust background color highlights based on number of spaces in front of content
|
if(positionX >= 0) {
|
||||||
positionX -= (LineIndentations != null ? LineIndentations[lineIndex] : 0);
|
float charWidth = g.MeasureString("W", this.Font, int.MaxValue, StringFormat.GenericTypographic).Width;
|
||||||
|
charIndex = (int)(positionX / charWidth);
|
||||||
int previousWidth = 0;
|
return true;
|
||||||
for(int i = 0, len = text.Length; i < len; i++) {
|
|
||||||
int width = (int)g.MeasureString(text.Substring(0, i+1), this.Font, int.MaxValue, StringFormat.GenericTypographic).Width;
|
|
||||||
if(width >= positionX && previousWidth <= positionX) {
|
|
||||||
charIndex = i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
previousWidth = width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -549,22 +541,23 @@ namespace Mesen.GUI.Debugger
|
||||||
int charIndex;
|
int charIndex;
|
||||||
int lineIndex;
|
int lineIndex;
|
||||||
if(this.GetCharIndex(position, out charIndex, out lineIndex)) {
|
if(this.GetCharIndex(position, out charIndex, out lineIndex)) {
|
||||||
string text = this.GetFullWidthString(lineIndex).Trim();
|
string text = this.GetFullWidthString(lineIndex);
|
||||||
|
if(charIndex < text.Length) {
|
||||||
if(_wordDelimiters.Contains(text[charIndex])) {
|
if(_wordDelimiters.Contains(text[charIndex])) {
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
} else {
|
|
||||||
int endIndex = text.IndexOfAny(_wordDelimiters, charIndex);
|
|
||||||
if(endIndex == -1) {
|
|
||||||
endIndex = text.Length;
|
|
||||||
}
|
|
||||||
int startIndex = text.LastIndexOfAny(_wordDelimiters, charIndex);
|
|
||||||
|
|
||||||
if(startIndex >= 0 && text[startIndex] == '#' && text.Length > startIndex && text[startIndex + 1] == '$') {
|
|
||||||
//Special case for immediate values. e.g: we want to show a tooltip for #MyLabel, but not for #$EF
|
|
||||||
return text.Substring(startIndex, endIndex - startIndex);
|
|
||||||
} else {
|
} else {
|
||||||
return text.Substring(startIndex + 1, endIndex - startIndex - 1);
|
int endIndex = text.IndexOfAny(_wordDelimiters, charIndex);
|
||||||
|
if(endIndex == -1) {
|
||||||
|
endIndex = text.Length;
|
||||||
|
}
|
||||||
|
int startIndex = text.LastIndexOfAny(_wordDelimiters, charIndex);
|
||||||
|
|
||||||
|
if(startIndex >= 0 && text[startIndex] == '#' && text.Length > startIndex && text[startIndex + 1] == '$') {
|
||||||
|
//Special case for immediate values. e.g: we want to show a tooltip for #MyLabel, but not for #$EF
|
||||||
|
return text.Substring(startIndex, endIndex - startIndex);
|
||||||
|
} else {
|
||||||
|
return text.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue