Skip to content

Commit 271ae8f

Browse files
committed
Changed a logic for console windows.
1 parent ce266f9 commit 271ae8f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace WindowTextExtractor.Extensions
4+
{
5+
public static class StringExtensions
6+
{
7+
public static string TrimEnd(this string text, string value, StringComparison comparisonType = StringComparison.CurrentCulture)
8+
{
9+
var result = text;
10+
while (result.EndsWith(value, comparisonType))
11+
{
12+
result = result.Substring(0, result.Length - value.Length);
13+
}
14+
return result;
15+
}
16+
}
17+
}

WindowTextExtractor/Forms/MainForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public bool PreFilterMessage(ref Message m)
218218

219219
if (!element.Current.IsPassword && _isButtonTargetTextMouseDown)
220220
{
221-
var text = element.GetTextFromConsole() ?? element.GetTextFromWindow();
222-
txtContent.Text = text;
221+
var text = element.GetTextFromWindow();
222+
txtContent.Text = text == null ? "" : text.TrimEnd().TrimEnd(Environment.NewLine);
223223
txtContent.ScrollTextToEnd();
224224
UpdateStatusBar();
225225
}

WindowTextExtractor/WindowTextExtractor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<ItemGroup>
8989
<Compile Include="Extensions\AutomationElementExtensions.cs" />
9090
<Compile Include="Extensions\ProcessExtensions.cs" />
91+
<Compile Include="Extensions\StringExtensions.cs" />
9192
<Compile Include="Extensions\TextBoxExtensions.cs" />
9293
<Compile Include="Forms\AboutForm.cs">
9394
<SubType>Form</SubType>

0 commit comments

Comments
 (0)