Merge branch 'master' into watermark-support
This commit is contained in:
Коммит
64babb981a
|
@ -34,6 +34,7 @@
|
|||
<PackageReference Include="Avalonia" Version="$(AvaloniaSampleVersion)" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaSampleVersion)" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaSampleVersion)"/>
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="$(AvaloniaSampleVersion)"/>
|
||||
<PackageReference Include="ReactiveUI" Version="20.1.1" />
|
||||
<ProjectReference Include="..\AvaloniaEdit\AvaloniaEdit.csproj" />
|
||||
<ProjectReference Include="..\AvaloniaEdit.TextMate\AvaloniaEdit.TextMate.csproj" />
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace AvaloniaEdit.Demo
|
|||
{
|
||||
double visualY = e.GetPosition(TextView).Y + TextView.VerticalOffset;
|
||||
VisualLine visualLine = TextView.GetVisualLineFromVisualTop(visualY);
|
||||
return visualLine.FirstDocumentLine.LineNumber;
|
||||
return (visualLine == null) ? -1 : visualLine.FirstDocumentLine.LineNumber;
|
||||
}
|
||||
|
||||
protected override void OnPointerMoved(PointerEventArgs e)
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace AvaloniaEdit.Demo
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.AttachDevTools();
|
||||
|
||||
_textEditor = this.FindControl<TextEditor>("Editor");
|
||||
_textEditor.HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Visible;
|
||||
_textEditor.Background = Brushes.Transparent;
|
||||
|
|
|
@ -82,28 +82,29 @@ namespace AvaloniaEdit.Editing
|
|||
|
||||
static CaretNavigationCommandHandler()
|
||||
{
|
||||
var keymap = Application.Current.PlatformSettings.HotkeyConfiguration;
|
||||
var keymap = HotkeyConfiguration.Keymap;
|
||||
var boxSelectionModifiers = HotkeyConfiguration.BoxSelectionModifiers;
|
||||
|
||||
AddBinding(EditingCommands.MoveLeftByCharacter, KeyModifiers.None, Key.Left, OnMoveCaret(CaretMovementType.CharLeft));
|
||||
AddBinding(EditingCommands.SelectLeftByCharacter, keymap.SelectionModifiers, Key.Left, OnMoveCaretExtendSelection(CaretMovementType.CharLeft));
|
||||
AddBinding(RectangleSelection.BoxSelectLeftByCharacter, KeyModifiers.Alt | keymap.SelectionModifiers, Key.Left, OnMoveCaretBoxSelection(CaretMovementType.CharLeft));
|
||||
AddBinding(RectangleSelection.BoxSelectLeftByCharacter, boxSelectionModifiers | keymap.SelectionModifiers, Key.Left, OnMoveCaretBoxSelection(CaretMovementType.CharLeft));
|
||||
AddBinding(EditingCommands.MoveRightByCharacter, KeyModifiers.None, Key.Right, OnMoveCaret(CaretMovementType.CharRight));
|
||||
AddBinding(EditingCommands.SelectRightByCharacter, keymap.SelectionModifiers, Key.Right, OnMoveCaretExtendSelection(CaretMovementType.CharRight));
|
||||
AddBinding(RectangleSelection.BoxSelectRightByCharacter, KeyModifiers.Alt | keymap.SelectionModifiers, Key.Right, OnMoveCaretBoxSelection(CaretMovementType.CharRight));
|
||||
AddBinding(RectangleSelection.BoxSelectRightByCharacter, boxSelectionModifiers | keymap.SelectionModifiers, Key.Right, OnMoveCaretBoxSelection(CaretMovementType.CharRight));
|
||||
|
||||
AddBinding(EditingCommands.MoveLeftByWord, keymap.WholeWordTextActionModifiers, Key.Left, OnMoveCaret(CaretMovementType.WordLeft));
|
||||
AddBinding(EditingCommands.SelectLeftByWord, keymap.WholeWordTextActionModifiers | keymap.SelectionModifiers, Key.Left, OnMoveCaretExtendSelection(CaretMovementType.WordLeft));
|
||||
AddBinding(RectangleSelection.BoxSelectLeftByWord, keymap.WholeWordTextActionModifiers | KeyModifiers.Alt | keymap.SelectionModifiers, Key.Left, OnMoveCaretBoxSelection(CaretMovementType.WordLeft));
|
||||
AddBinding(RectangleSelection.BoxSelectLeftByWord, keymap.WholeWordTextActionModifiers | boxSelectionModifiers | keymap.SelectionModifiers, Key.Left, OnMoveCaretBoxSelection(CaretMovementType.WordLeft));
|
||||
AddBinding(EditingCommands.MoveRightByWord, keymap.WholeWordTextActionModifiers, Key.Right, OnMoveCaret(CaretMovementType.WordRight));
|
||||
AddBinding(EditingCommands.SelectRightByWord, keymap.WholeWordTextActionModifiers | keymap.SelectionModifiers, Key.Right, OnMoveCaretExtendSelection(CaretMovementType.WordRight));
|
||||
AddBinding(RectangleSelection.BoxSelectRightByWord, keymap.WholeWordTextActionModifiers | KeyModifiers.Alt | keymap.SelectionModifiers, Key.Right, OnMoveCaretBoxSelection(CaretMovementType.WordRight));
|
||||
AddBinding(RectangleSelection.BoxSelectRightByWord, keymap.WholeWordTextActionModifiers | boxSelectionModifiers | keymap.SelectionModifiers, Key.Right, OnMoveCaretBoxSelection(CaretMovementType.WordRight));
|
||||
|
||||
AddBinding(EditingCommands.MoveUpByLine, KeyModifiers.None, Key.Up, OnMoveCaret(CaretMovementType.LineUp));
|
||||
AddBinding(EditingCommands.SelectUpByLine, keymap.SelectionModifiers, Key.Up, OnMoveCaretExtendSelection(CaretMovementType.LineUp));
|
||||
AddBinding(RectangleSelection.BoxSelectUpByLine, KeyModifiers.Alt | keymap.SelectionModifiers, Key.Up, OnMoveCaretBoxSelection(CaretMovementType.LineUp));
|
||||
AddBinding(RectangleSelection.BoxSelectUpByLine, boxSelectionModifiers | keymap.SelectionModifiers, Key.Up, OnMoveCaretBoxSelection(CaretMovementType.LineUp));
|
||||
AddBinding(EditingCommands.MoveDownByLine, KeyModifiers.None, Key.Down, OnMoveCaret(CaretMovementType.LineDown));
|
||||
AddBinding(EditingCommands.SelectDownByLine, keymap.SelectionModifiers, Key.Down, OnMoveCaretExtendSelection(CaretMovementType.LineDown));
|
||||
AddBinding(RectangleSelection.BoxSelectDownByLine, KeyModifiers.Alt | keymap.SelectionModifiers, Key.Down, OnMoveCaretBoxSelection(CaretMovementType.LineDown));
|
||||
AddBinding(RectangleSelection.BoxSelectDownByLine, boxSelectionModifiers | keymap.SelectionModifiers, Key.Down, OnMoveCaretBoxSelection(CaretMovementType.LineDown));
|
||||
|
||||
AddBinding(EditingCommands.MoveDownByPage, KeyModifiers.None, Key.PageDown, OnMoveCaret(CaretMovementType.PageDown));
|
||||
AddBinding(EditingCommands.SelectDownByPage, keymap.SelectionModifiers, Key.PageDown, OnMoveCaretExtendSelection(CaretMovementType.PageDown));
|
||||
|
@ -119,8 +120,8 @@ namespace AvaloniaEdit.Editing
|
|||
foreach (var keyGesture in keymap.MoveCursorToTheEndOfLineWithSelection)
|
||||
AddBinding(EditingCommands.SelectToLineEnd, keyGesture, OnMoveCaretExtendSelection(CaretMovementType.LineEnd));
|
||||
|
||||
AddBinding(RectangleSelection.BoxSelectToLineStart, KeyModifiers.Alt | keymap.SelectionModifiers, Key.Home, OnMoveCaretBoxSelection(CaretMovementType.LineStart));
|
||||
AddBinding(RectangleSelection.BoxSelectToLineEnd, KeyModifiers.Alt | keymap.SelectionModifiers, Key.End, OnMoveCaretBoxSelection(CaretMovementType.LineEnd));
|
||||
AddBinding(RectangleSelection.BoxSelectToLineStart, boxSelectionModifiers | keymap.SelectionModifiers, Key.Home, OnMoveCaretBoxSelection(CaretMovementType.LineStart));
|
||||
AddBinding(RectangleSelection.BoxSelectToLineEnd, boxSelectionModifiers | keymap.SelectionModifiers, Key.End, OnMoveCaretBoxSelection(CaretMovementType.LineEnd));
|
||||
|
||||
foreach (var keyGesture in keymap.MoveCursorToTheStartOfDocument)
|
||||
AddBinding(EditingCommands.MoveToDocumentStart, keyGesture, OnMoveCaret(CaretMovementType.DocumentStart));
|
||||
|
|
|
@ -25,6 +25,7 @@ using AvaloniaEdit.Document;
|
|||
using Avalonia.Input;
|
||||
using AvaloniaEdit.Utils;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace AvaloniaEdit.Editing
|
||||
{
|
||||
|
@ -73,8 +74,6 @@ namespace AvaloniaEdit.Editing
|
|||
OnDelete(CaretMovementType.WordLeft));
|
||||
AddBinding(EditingCommands.EnterParagraphBreak, KeyModifiers.None, Key.Enter, OnEnter);
|
||||
AddBinding(EditingCommands.EnterLineBreak, KeyModifiers.Shift, Key.Enter, OnEnter);
|
||||
AddBinding(EditingCommands.TabForward, KeyModifiers.None, Key.Tab, OnTab);
|
||||
AddBinding(EditingCommands.TabBackward, KeyModifiers.Shift, Key.Tab, OnShiftTab);
|
||||
|
||||
AddBinding(ApplicationCommands.Delete, OnDelete(CaretMovementType.None), CanDelete);
|
||||
AddBinding(ApplicationCommands.Copy, OnCopy, CanCopy);
|
||||
|
@ -115,7 +114,7 @@ namespace AvaloniaEdit.Editing
|
|||
/// transformLine needs to handle read-only segments!
|
||||
/// </summary>
|
||||
private static void TransformSelectedLines(Action<TextArea, DocumentLine> transformLine, object target,
|
||||
ExecutedRoutedEventArgs args, DefaultSegmentType defaultSegmentType)
|
||||
RoutedEventArgs args, DefaultSegmentType defaultSegmentType)
|
||||
{
|
||||
var textArea = GetTextArea(target);
|
||||
if (textArea?.Document != null)
|
||||
|
@ -228,7 +227,7 @@ namespace AvaloniaEdit.Editing
|
|||
|
||||
#region Tab
|
||||
|
||||
private static void OnTab(object target, ExecutedRoutedEventArgs args)
|
||||
public static void OnTab(object target, RoutedEventArgs args)
|
||||
{
|
||||
var textArea = GetTextArea(target);
|
||||
if (textArea?.Document != null)
|
||||
|
@ -264,9 +263,11 @@ namespace AvaloniaEdit.Editing
|
|||
textArea.Caret.BringCaretToView();
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
TextBox textBox = new TextBox();
|
||||
}
|
||||
|
||||
private static void OnShiftTab(object target, ExecutedRoutedEventArgs args)
|
||||
public static void OnShiftTab(object target, RoutedEventArgs args)
|
||||
{
|
||||
TransformSelectedLines(
|
||||
delegate (TextArea textArea, DocumentLine line)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Avalonia;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Input.Platform;
|
||||
|
||||
namespace AvaloniaEdit.Editing;
|
||||
|
||||
public static class HotkeyConfiguration
|
||||
{
|
||||
public static KeyModifiers BoxSelectionModifiers { get; private set; }
|
||||
|
||||
public static PlatformHotkeyConfiguration Keymap
|
||||
{
|
||||
get { return Application.Current.PlatformSettings.HotkeyConfiguration; }
|
||||
}
|
||||
|
||||
static HotkeyConfiguration()
|
||||
{
|
||||
BoxSelectionModifiers = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
|
||||
KeyModifiers.Control : KeyModifiers.Alt;
|
||||
}
|
||||
}
|
|
@ -438,7 +438,7 @@ namespace AvaloniaEdit.Editing
|
|||
|
||||
if (TextArea.CapturePointer(e.Pointer))
|
||||
{
|
||||
if (modifiers.HasFlag(KeyModifiers.Alt) && TextArea.Options.EnableRectangularSelection)
|
||||
if (modifiers.HasFlag(HotkeyConfiguration.BoxSelectionModifiers) && TextArea.Options.EnableRectangularSelection)
|
||||
{
|
||||
_mode = SelectionMode.Rectangular;
|
||||
if (shift && TextArea.Selection is RectangleSelection)
|
||||
|
|
|
@ -969,6 +969,20 @@ namespace AvaloniaEdit.Editing
|
|||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
|
||||
if (e.Key == Key.Tab && Options.AcceptsTab)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (e.KeyModifiers == KeyModifiers.Shift)
|
||||
{
|
||||
EditingCommandHandler.OnShiftTab(this, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditingCommandHandler.OnTab(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
TextView.InvalidateCursorIfPointerWithinTextView();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace AvaloniaEdit.Rendering
|
|||
internal readonly static Regex DefaultLinkRegex = new Regex(@"\b(https?://|ftp://|www\.)[\w\d\._/\-~%@()+:?&=#!]*[\w\d/]");
|
||||
|
||||
// try to detect email addresses
|
||||
internal readonly static Regex DefaultMailRegex = new Regex(@"\b[\w\d\.\-]+\@[\w\d\.\-]+\.[a-z]{2,6}\b");
|
||||
internal readonly static Regex DefaultMailRegex = new Regex(@"\b[\w\d\.\-\+]+\@[\w\d\.\-]+\.[a-z]{2,6}\b");
|
||||
|
||||
private readonly Regex _linkRegex;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace AvaloniaEdit
|
|||
#region Constructors
|
||||
static TextEditor()
|
||||
{
|
||||
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
|
||||
FocusableProperty.OverrideDefaultValue<TextEditor>(false);
|
||||
HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
|
||||
VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
|
||||
|
||||
|
|
|
@ -77,6 +77,28 @@ namespace AvaloniaEdit
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region AccepsTab
|
||||
|
||||
bool _acceptsTab = true;
|
||||
[DefaultValue(true)]
|
||||
public virtual bool AcceptsTab
|
||||
{
|
||||
get
|
||||
{
|
||||
return _acceptsTab;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_acceptsTab != value)
|
||||
{
|
||||
_acceptsTab = value;
|
||||
OnPropertyChanged(nameof(AcceptsTab));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ShowSpaces / ShowTabs / ShowEndOfLine / ShowBoxForControlCharacters
|
||||
|
||||
private bool _showSpaces;
|
||||
|
|
Загрузка…
Ссылка в новой задаче