Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SCI_SET{X,Y}CARETPOLICY functions #57

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Scintilla.NET/Scintilla.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="..\Shared\BiDirectionalDisplayType.cs" Link="BiDirectionalDisplayType.cs" />
<Compile Include="..\Shared\CallTipClickEventArgs.cs" Link="CallTipClickEventArgs.cs" />
<Compile Include="..\Shared\CallTipClickType.cs" Link="CallTipClickType.cs" />
<Compile Include="..\Shared\CaretPolicy.cs" Link="CaretPolicy.cs" />
<Compile Include="..\Shared\CaretStyle.cs" Link="CaretStyle.cs" />
<Compile Include="..\Shared\ChangeAnnotationEventArgs.cs" Link="ChangeAnnotationEventArgs.cs" />
<Compile Include="..\Shared\CharAddedEventArgs.cs" Link="CharAddedEventArgs.cs" />
Expand Down
42 changes: 42 additions & 0 deletions Shared/CaretPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace ScintillaNET
{
/// <summary>
/// The caret policy.
/// </summary>
[Flags]
public enum CaretPolicy
{
/// <summary>
/// If set, we can define a slop value: caretSlop. This value defines an unwanted zone (UZ)
/// where the caret is... unwanted. This zone is defined as a number of pixels near the
/// vertical margins, and as a number of lines near the horizontal margins. By keeping the
/// caret away from the edges, it is seen within its context. This makes it likely that the
/// identifier that the caret is on can be completely seen, and that the current line is seen
/// with some of the lines following it, which are often dependent on that line.
/// </summary>
Slop = NativeMethods.CARET_SLOP,

/// <summary>
/// If set, the policy set by CARET_SLOP is enforced... strictly. The caret is centered on the
/// display if caretSlop is not set, and cannot go in the UZ if caretSlop is set.
/// </summary>
Strict = NativeMethods.CARET_STRICT,

/// <summary>
/// If set, the display is moved more energetically so the caret can move in the same direction
/// longer before the policy is applied again. '3UZ' notation is used to indicate three time
/// the size of the UZ as a distance to the margin.
/// </summary>
Jumps = NativeMethods.CARET_JUMPS,

/// <summary>
/// If not set, instead of having symmetrical UZs, the left and bottom UZs are extended up to
/// right and top UZs respectively. This way, we favour the displaying of useful information:
/// the beginning of lines, where most code reside, and the lines after the caret, for example,
/// the body of a function.
/// </summary>
Even = NativeMethods.CARET_EVEN
}
}
6 changes: 6 additions & 0 deletions Shared/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public static class NativeMethods
public const int SCI_CSHIFT = (SCI_CTRL | SCI_SHIFT);
public const int SCI_ASHIFT = (SCI_ALT | SCI_SHIFT);

// Caret policy flags
public const int CARET_SLOP = 0x01;
public const int CARET_STRICT = 0x04;
public const int CARET_JUMPS = 0x10;
public const int CARET_EVEN = 0x08;

// Caret styles
public const int CARETSTYLE_INVISIBLE = 0;
public const int CARETSTYLE_LINE = 1;
Expand Down
20 changes: 20 additions & 0 deletions Shared/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,26 @@ public void SetWhitespaceForeColor(bool use, Color color)
DirectMessage(NativeMethods.SCI_SETWHITESPACEFORE, useWhitespaceForeColour, new IntPtr(colour));
}

/// <summary>
/// Sets the X caret policy.
/// </summary>
/// <param name="caretPolicy">a combination of <see cref="CaretPolicy"/> values.</param>
/// <param name="caretSlop">the caretSlop value</param>
public void SetXCaretPolicy(CaretPolicy caretPolicy, int caretSlop)
{
DirectMessage(NativeMethods.SCI_SETXCARETPOLICY, new IntPtr((int)caretPolicy), new IntPtr(caretSlop));
}

/// <summary>
/// Sets the Y caret policy.
/// </summary>
/// <param name="caretPolicy">a combination of <see cref="CaretPolicy"/> values.</param>
/// <param name="caretSlop">the caretSlop value</param>
public void SetYCaretPolicy(CaretPolicy caretPolicy, int caretSlop)
jmairboeck marked this conversation as resolved.
Show resolved Hide resolved
{
DirectMessage(NativeMethods.SCI_SETYCARETPOLICY, new IntPtr((int)caretPolicy), new IntPtr(caretSlop));
}

private bool ShouldSerializeAdditionalCaretForeColor()
{
return AdditionalCaretForeColor != Color.FromArgb(127, 127, 127);
Expand Down