Fix IDE0057
This commit is contained in:
committed by
Pavel Penev
parent
5254348819
commit
023d80b94d
@@ -51,13 +51,13 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (highlightStart > 0 && highlightEnd > highlightStart)
|
||||
{
|
||||
// Normal line segment before highlight
|
||||
var lineNormal = line.Substring(0, highlightStart);
|
||||
var lineNormal = line[..highlightStart];
|
||||
components.Add((lineNormal, false));
|
||||
|
||||
// Highlight line segment
|
||||
var lineHighlight = line.Substring(highlightStart + 1, highlightEnd - highlightStart - 1);
|
||||
var lineHighlight = line[(highlightStart + 1)..highlightEnd];
|
||||
components.Add((lineHighlight, true));
|
||||
line = line.Substring(highlightEnd + 1);
|
||||
line = line[(highlightEnd + 1)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -676,15 +676,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
name = source.Name;
|
||||
var compare = Platform.CurrentPlatform == PlatformType.Windows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
|
||||
if (name.StartsWith(modData.Manifest.Package.Name, compare))
|
||||
name = "$" + modData.Manifest.Id + "/" + name.Substring(modData.Manifest.Package.Name.Length + 1);
|
||||
name = "$" + modData.Manifest.Id + "/" + name[(modData.Manifest.Package.Name.Length + 1)..];
|
||||
else if (name.StartsWith(Platform.EngineDir, compare))
|
||||
name = "./" + name.Substring(Platform.EngineDir.Length);
|
||||
name = "./" + name[Platform.EngineDir.Length..];
|
||||
else if (name.StartsWith(Platform.SupportDir, compare))
|
||||
name = "^" + name.Substring(Platform.SupportDir.Length);
|
||||
name = "^" + name[Platform.SupportDir.Length..];
|
||||
}
|
||||
|
||||
if (name.Length > 18)
|
||||
name = "..." + name.Substring(name.Length - 15);
|
||||
name = "..." + name[^15..];
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
else
|
||||
{
|
||||
ipField.Text = text.Substring(0, last);
|
||||
portField.Text = text.Substring(last + 1);
|
||||
ipField.Text = text[..last];
|
||||
portField.Text = text[(last + 1)..];
|
||||
}
|
||||
|
||||
var joinButton = panel.Get<ButtonWidget>("JOIN_BUTTON");
|
||||
|
||||
@@ -205,8 +205,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return (null, null);
|
||||
|
||||
var split = input.IndexOf(token, StringComparison.Ordinal);
|
||||
var first = split > 0 ? input.Substring(0, split) : input;
|
||||
var second = split > 0 ? input.Substring(split + token.Length) : null;
|
||||
var first = split > 0 ? input[..split] : input;
|
||||
var second = split > 0 ? input[(split + token.Length)..] : null;
|
||||
return (first, second);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
prefix = "/";
|
||||
suffix = "";
|
||||
toComplete = text.Substring(1);
|
||||
toComplete = text[1..];
|
||||
candidates = Commands.Where(x => x.StartsWith(toComplete, StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||
}
|
||||
else if (Names != null)
|
||||
@@ -52,9 +52,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var oneWord = text.Contains(' ');
|
||||
if (oneWord)
|
||||
{
|
||||
prefix = text.Substring(0, text.LastIndexOf(' ') + 1);
|
||||
prefix = text[..(text.LastIndexOf(' ') + 1)];
|
||||
suffix = "";
|
||||
toComplete = text.Substring(prefix.Length);
|
||||
toComplete = text[prefix.Length..];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var minValue = int.MaxValue;
|
||||
for (var i = 0; i <= apparentText.Length; i++)
|
||||
{
|
||||
var dist = Math.Abs(start + font.Measure(apparentText.Substring(0, i)).X - x);
|
||||
var dist = Math.Abs(start + font.Measure(apparentText[..i]).X - x);
|
||||
if (dist > minValue)
|
||||
break;
|
||||
minValue = dist;
|
||||
@@ -168,12 +168,12 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
int GetPrevWhitespaceIndex()
|
||||
{
|
||||
return Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
||||
return Text[..CursorPosition].TrimEnd().LastIndexOf(' ') + 1;
|
||||
}
|
||||
|
||||
int GetNextWhitespaceIndex()
|
||||
{
|
||||
var substr = Text.Substring(CursorPosition);
|
||||
var substr = Text[CursorPosition..];
|
||||
var substrTrimmed = substr.TrimStart();
|
||||
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
||||
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
||||
@@ -335,7 +335,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition > 0)
|
||||
{
|
||||
// Write directly to the Text backing field to avoid unnecessary validation
|
||||
text = text.Substring(CursorPosition);
|
||||
text = text[CursorPosition..];
|
||||
CursorPosition = 0;
|
||||
ClearSelection();
|
||||
OnTextEdited();
|
||||
@@ -350,7 +350,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var lowestIndex = selectionStartIndex < selectionEndIndex ? selectionStartIndex : selectionEndIndex;
|
||||
var highestIndex = selectionStartIndex < selectionEndIndex ? selectionEndIndex : selectionStartIndex;
|
||||
Game.Renderer.SetClipboardText(Text.Substring(lowestIndex, highestIndex - lowestIndex));
|
||||
Game.Renderer.SetClipboardText(Text[lowestIndex..highestIndex]);
|
||||
|
||||
RemoveSelectedText();
|
||||
}
|
||||
@@ -363,7 +363,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var lowestIndex = selectionStartIndex < selectionEndIndex ? selectionStartIndex : selectionEndIndex;
|
||||
var highestIndex = selectionStartIndex < selectionEndIndex ? selectionEndIndex : selectionStartIndex;
|
||||
Game.Renderer.SetClipboardText(Text.Substring(lowestIndex, highestIndex - lowestIndex));
|
||||
Game.Renderer.SetClipboardText(Text[lowestIndex..highestIndex]);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -377,7 +377,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
// Write directly to the Text backing field to avoid unnecessary validation
|
||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||
text = text.Substring(0, CursorPosition) + text.Substring(GetNextWhitespaceIndex());
|
||||
text = text[..CursorPosition] + text[GetNextWhitespaceIndex()..];
|
||||
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||
text = text.Remove(CursorPosition);
|
||||
else
|
||||
@@ -400,12 +400,12 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||
{
|
||||
var prevWhitespace = GetPrevWhitespaceIndex();
|
||||
text = text.Substring(0, prevWhitespace) + text.Substring(CursorPosition);
|
||||
text = text[..prevWhitespace] + text[CursorPosition..];
|
||||
CursorPosition = prevWhitespace;
|
||||
}
|
||||
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||
{
|
||||
text = text.Substring(CursorPosition);
|
||||
text = text[CursorPosition..];
|
||||
CursorPosition = 0;
|
||||
}
|
||||
else
|
||||
@@ -432,7 +432,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
// Take only the first line of the clipboard contents
|
||||
var nl = clipboardText.IndexOf('\n');
|
||||
if (nl > 0)
|
||||
clipboardText = clipboardText.Substring(0, nl);
|
||||
clipboardText = clipboardText[..nl];
|
||||
|
||||
clipboardText = clipboardText.Trim();
|
||||
if (clipboardText.Length > 0)
|
||||
@@ -479,7 +479,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
pasteLength = Math.Min(input.Length, MaxLength - Text.Length);
|
||||
|
||||
// Write directly to the Text backing field to avoid repeating the invalid character validation
|
||||
text = text.Insert(CursorPosition, input.Substring(0, pasteLength));
|
||||
text = text.Insert(CursorPosition, input[..pasteLength]);
|
||||
CursorPosition += pasteLength;
|
||||
ClearSelection();
|
||||
OnTextEdited();
|
||||
@@ -551,7 +551,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var pos = RenderOrigin;
|
||||
|
||||
var textSize = font.Measure(apparentText);
|
||||
var cursorPosition = font.Measure(apparentText.Substring(0, CursorPosition));
|
||||
var cursorPosition = font.Measure(apparentText[..CursorPosition]);
|
||||
|
||||
var disabled = IsDisabled();
|
||||
var hover = Ui.MouseOverWidget == this || Children.Any(c => c == Ui.MouseOverWidget);
|
||||
@@ -580,8 +580,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var visualSelectionStartIndex = selectionStartIndex < selectionEndIndex ? selectionStartIndex : selectionEndIndex;
|
||||
var visualSelectionEndIndex = selectionStartIndex < selectionEndIndex ? selectionEndIndex : selectionStartIndex;
|
||||
var highlightStartX = font.Measure(apparentText.Substring(0, visualSelectionStartIndex)).X;
|
||||
var highlightEndX = font.Measure(apparentText.Substring(0, visualSelectionEndIndex)).X;
|
||||
var highlightStartX = font.Measure(apparentText[..visualSelectionStartIndex]).X;
|
||||
var highlightEndX = font.Measure(apparentText[..visualSelectionEndIndex]).X;
|
||||
|
||||
WidgetUtils.FillRectWithColor(
|
||||
new Rectangle(textPos.X + highlightStartX, textPos.Y, highlightEndX - highlightStartX, Bounds.Height - verticalMargin * 2), TextColorHighlight);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (spaceIndex == -1)
|
||||
break;
|
||||
|
||||
var fragmentWidth = font.Measure(line.Substring(0, spaceIndex)).X;
|
||||
var fragmentWidth = font.Measure(line[..spaceIndex]).X;
|
||||
if (fragmentWidth > width)
|
||||
break;
|
||||
|
||||
@@ -258,8 +258,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
if (start > 0)
|
||||
{
|
||||
lines[i] = line.Substring(0, start - 1);
|
||||
lines.Insert(i + 1, line.Substring(start));
|
||||
lines[i] = line[..(start - 1)];
|
||||
lines.Insert(i + 1, line[start..]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var trimmed = text;
|
||||
while (trimmedWidth > width && trimmed.Length > 3)
|
||||
{
|
||||
trimmed = text.Substring(0, trimmed.Length - 4) + "...";
|
||||
trimmed = text[..(trimmed.Length - 4)] + "...";
|
||||
trimmedWidth = font.Measure(trimmed).X;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user