forked from PowerShell/PSReadLine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.cs
More file actions
89 lines (75 loc) · 2.83 KB
/
Position.cs
File metadata and controls
89 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
namespace Microsoft.PowerShell
{
public partial class PSConsoleReadLine
{
/// <summary>
/// Returns the position of the beginning of line
/// starting from the specified "current" position.
/// </summary>
/// <param name="current">The position in the current logical line.</param>
private static int GetBeginningOfLinePos(int current)
=> _singleton._buffer.GetBeginningOfLogicalLinePos(current);
/// <summary>
/// Returns the position of the beginning of line
/// for the 0-based specified line number.
/// </summary>
private static int GetBeginningOfNthLinePos(int lineIndex)
{
System.Diagnostics.Debug.Assert(lineIndex >= 0 || lineIndex < _singleton.GetLogicalLineCount());
var nth = 0;
var index = 0;
var result = 0;
for (; index < _singleton._buffer.Length; index++)
{
if (nth == lineIndex)
{
result = index;
break;
}
if (_singleton._buffer[index] == '\n')
{
nth++;
}
}
if (nth == lineIndex)
{
result = index;
}
return result;
}
/// <summary>
/// Returns the position of the end of the logical line
/// as specified by the "current" position.
/// </summary>
/// <param name="current"></param>
/// <returns></returns>
private static int GetEndOfLogicalLinePos(int current)
=> _singleton._buffer.GetEndOfLogicalLinePos(current);
/// <summary>
/// Returns the position of the end of the logical line
/// for the 0-based specified line number.
/// </summary>
private static int GetEndOfNthLogicalLinePos(int lineIndex)
{
return GetEndOfLogicalLinePos(
GetBeginningOfNthLinePos(lineIndex));
}
/// <summary>
/// Returns the position of the first non whitespace character in
/// the current logical line as specified by the "current" position.
/// </summary>
/// <param name="current">The position in the current logical line.</param>
private static int GetFirstNonBlankOfLogicalLinePos(int current)
{
var beginningOfLine = GetBeginningOfLinePos(current);
var newCurrent = beginningOfLine;
var buffer = _singleton._buffer;
while (newCurrent < buffer.Length && buffer.IsVisibleBlank(newCurrent))
{
newCurrent++;
}
return newCurrent;
}
}
}