forked from PowerShell/PSReadLine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New - PowerShell#333 Supports linewise yanks.
- Loading branch information
Maxime Labelle
committed
Apr 9, 2019
1 parent
73af195
commit 15579d2
Showing
10 changed files
with
608 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace Microsoft.PowerShell | ||
{ | ||
public class Range | ||
{ | ||
public int Offset { get; set; } | ||
public int Count { get; set; } | ||
} | ||
|
||
public static class StringBuilderLinewiseExtensions | ||
{ | ||
/// <summary> | ||
/// Determines the offset and the length of the fragment | ||
/// in the specified buffer that corresponds to a | ||
/// given number of lines starting from the specified line index | ||
/// </summary> | ||
/// <param name="buffer" /> | ||
/// <param name="lineIndex" /> | ||
/// <param name="lineCount" /> | ||
public static Range GetRange(this StringBuilder buffer, int lineIndex, int lineCount) | ||
{ | ||
var length = buffer.Length; | ||
|
||
var startPosition = 0; | ||
var startPositionIdentified = false; | ||
|
||
var endPosition = length - 1; | ||
var endPositionIdentified = false; | ||
|
||
var currentLine = 0; | ||
|
||
for (var position = 0; position < length; position++) | ||
{ | ||
if (currentLine == lineIndex && !startPositionIdentified) | ||
{ | ||
startPosition = position; | ||
startPositionIdentified = true; | ||
} | ||
|
||
if (buffer[position] == '\n') | ||
{ | ||
currentLine++; | ||
} | ||
|
||
if (currentLine == lineIndex + lineCount && !endPositionIdentified) | ||
{ | ||
endPosition = position; | ||
endPositionIdentified = true; | ||
} | ||
} | ||
|
||
return new Range | ||
{ | ||
Offset = startPosition, | ||
Count = endPosition - startPosition + 1, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.