.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
1.1 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Input;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.Snippets
{
/// <summary>
/// Sets the caret position after interactive mode has finished.
/// </summary>
[Serializable]
public class SnippetCaretElement : SnippetElement
{
/// <inheritdoc/>
public override void Insert(InsertionContext context)
{
if (!string.IsNullOrEmpty(context.SelectedText))
SetCaret(context);
}
internal static void SetCaret(InsertionContext context)
{
TextAnchor pos = context.Document.CreateAnchor(context.InsertionPosition);
pos.MovementType = AnchorMovementType.BeforeInsertion;
pos.SurviveDeletion = true;
context.Deactivated += (sender, e) => {
if (e.Reason == DeactivateReason.ReturnPressed || e.Reason == DeactivateReason.NoActiveElements) {
context.TextArea.Caret.Offset = pos.Offset;
}
};
}
}
}