|
@@ -1,4 +1,3 @@
|
|
-using System.Data;
|
|
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using Terminal.Gui.Resources;
|
|
using Terminal.Gui.Resources;
|
|
|
|
|
|
@@ -25,14 +24,14 @@ public class TextField : View
|
|
/// </summary>
|
|
/// </summary>
|
|
public TextField ()
|
|
public TextField ()
|
|
{
|
|
{
|
|
- _historyText = new HistoryText ();
|
|
|
|
|
|
+ _historyText = new ();
|
|
_isButtonReleased = true;
|
|
_isButtonReleased = true;
|
|
_selectedStart = -1;
|
|
_selectedStart = -1;
|
|
- _text = new List<Rune> ();
|
|
|
|
- CaptionColor = new Color (Color.DarkGray);
|
|
|
|
|
|
+ _text = new ();
|
|
|
|
+ CaptionColor = new (Color.DarkGray);
|
|
ReadOnly = false;
|
|
ReadOnly = false;
|
|
Autocomplete = new TextFieldAutocomplete ();
|
|
Autocomplete = new TextFieldAutocomplete ();
|
|
- Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1);
|
|
|
|
|
|
+ Height = Dim.Auto (DimAutoStyle.Text, 1);
|
|
|
|
|
|
CanFocus = true;
|
|
CanFocus = true;
|
|
CursorVisibility = CursorVisibility.Default;
|
|
CursorVisibility = CursorVisibility.Default;
|
|
@@ -405,13 +404,12 @@ public class TextField : View
|
|
|
|
|
|
_currentCulture = Thread.CurrentThread.CurrentUICulture;
|
|
_currentCulture = Thread.CurrentThread.CurrentUICulture;
|
|
|
|
|
|
- ContextMenu = new ContextMenu { Host = this };
|
|
|
|
|
|
+ ContextMenu = new() { Host = this };
|
|
ContextMenu.KeyChanged += ContextMenu_KeyChanged;
|
|
ContextMenu.KeyChanged += ContextMenu_KeyChanged;
|
|
|
|
|
|
KeyBindings.Add (ContextMenu.Key, KeyBindingScope.HotKey, Command.Context);
|
|
KeyBindings.Add (ContextMenu.Key, KeyBindingScope.HotKey, Command.Context);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Provides autocomplete context menu based on suggestions at the current cursor position. Configure
|
|
/// Provides autocomplete context menu based on suggestions at the current cursor position. Configure
|
|
/// <see cref="ISuggestionGenerator"/> to enable this feature.
|
|
/// <see cref="ISuggestionGenerator"/> to enable this feature.
|
|
@@ -545,13 +543,13 @@ public class TextField : View
|
|
if (!Secret && !_historyText.IsFromHistory)
|
|
if (!Secret && !_historyText.IsFromHistory)
|
|
{
|
|
{
|
|
_historyText.Add (
|
|
_historyText.Add (
|
|
- new List<List<RuneCell>> { TextModel.ToRuneCellList (oldText) },
|
|
|
|
- new Point (_cursorPosition, 0)
|
|
|
|
|
|
+ new() { TextModel.ToRuneCellList (oldText) },
|
|
|
|
+ new (_cursorPosition, 0)
|
|
);
|
|
);
|
|
|
|
|
|
_historyText.Add (
|
|
_historyText.Add (
|
|
- new List<List<RuneCell>> { TextModel.ToRuneCells (_text) },
|
|
|
|
- new Point (_cursorPosition, 0),
|
|
|
|
|
|
+ new() { TextModel.ToRuneCells (_text) },
|
|
|
|
+ new (_cursorPosition, 0),
|
|
HistoryText.LineStatus.Replaced
|
|
HistoryText.LineStatus.Replaced
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -647,8 +645,8 @@ public class TextField : View
|
|
}
|
|
}
|
|
|
|
|
|
_historyText.Add (
|
|
_historyText.Add (
|
|
- new List<List<RuneCell>> { TextModel.ToRuneCells (_text) },
|
|
|
|
- new Point (_cursorPosition, 0)
|
|
|
|
|
|
+ new() { TextModel.ToRuneCells (_text) },
|
|
|
|
+ new (_cursorPosition, 0)
|
|
);
|
|
);
|
|
|
|
|
|
if (SelectedLength == 0)
|
|
if (SelectedLength == 0)
|
|
@@ -701,8 +699,8 @@ public class TextField : View
|
|
}
|
|
}
|
|
|
|
|
|
_historyText.Add (
|
|
_historyText.Add (
|
|
- new List<List<RuneCell>> { TextModel.ToRuneCells (_text) },
|
|
|
|
- new Point (_cursorPosition, 0)
|
|
|
|
|
|
+ new() { TextModel.ToRuneCells (_text) },
|
|
|
|
+ new (_cursorPosition, 0)
|
|
);
|
|
);
|
|
|
|
|
|
if (SelectedLength == 0)
|
|
if (SelectedLength == 0)
|
|
@@ -727,10 +725,7 @@ public class TextField : View
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public override Attribute GetNormalColor ()
|
|
|
|
- {
|
|
|
|
- return GetFocusColor ();
|
|
|
|
- }
|
|
|
|
|
|
+ public override Attribute GetNormalColor () { return GetFocusColor (); }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Inserts the given <paramref name="toAdd"/> text at the current cursor position exactly as if the user had just
|
|
/// Inserts the given <paramref name="toAdd"/> text at the current cursor position exactly as if the user had just
|
|
@@ -1042,8 +1037,6 @@ public class TextField : View
|
|
|
|
|
|
//if (SelectedLength != 0 && !(Application.MouseGrabView is MenuBar))
|
|
//if (SelectedLength != 0 && !(Application.MouseGrabView is MenuBar))
|
|
// ClearAllSelection ();
|
|
// ClearAllSelection ();
|
|
-
|
|
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// TODO: Flush out these docs
|
|
/// TODO: Flush out these docs
|
|
@@ -1144,6 +1137,7 @@ public class TextField : View
|
|
|
|
|
|
int pos = _cursorPosition - ScrollOffset + Math.Min (Frame.X, 0);
|
|
int pos = _cursorPosition - ScrollOffset + Math.Min (Frame.X, 0);
|
|
Move (pos, 0);
|
|
Move (pos, 0);
|
|
|
|
+
|
|
return new Point (pos, 0);
|
|
return new Point (pos, 0);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1252,73 +1246,70 @@ public class TextField : View
|
|
|
|
|
|
private MenuBarItem BuildContextMenuBarItem ()
|
|
private MenuBarItem BuildContextMenuBarItem ()
|
|
{
|
|
{
|
|
- return new MenuBarItem (
|
|
|
|
- new MenuItem []
|
|
|
|
- {
|
|
|
|
- new (
|
|
|
|
- Strings.ctxSelectAll,
|
|
|
|
- "",
|
|
|
|
- () => SelectAll (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.SelectAll)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxDeleteAll,
|
|
|
|
- "",
|
|
|
|
- () => DeleteAll (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.DeleteAll)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxCopy,
|
|
|
|
- "",
|
|
|
|
- () => Copy (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.Copy)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxCut,
|
|
|
|
- "",
|
|
|
|
- () => Cut (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.Cut)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxPaste,
|
|
|
|
- "",
|
|
|
|
- () => Paste (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.Paste)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxUndo,
|
|
|
|
- "",
|
|
|
|
- () => Undo (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.Undo)
|
|
|
|
- ),
|
|
|
|
- new (
|
|
|
|
- Strings.ctxRedo,
|
|
|
|
- "",
|
|
|
|
- () => Redo (),
|
|
|
|
- null,
|
|
|
|
- null,
|
|
|
|
- (KeyCode)KeyBindings.GetKeyFromCommands (Command.Redo)
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
|
|
+ return new (
|
|
|
|
+ new MenuItem []
|
|
|
|
+ {
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxSelectAll,
|
|
|
|
+ "",
|
|
|
|
+ () => SelectAll (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.SelectAll)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxDeleteAll,
|
|
|
|
+ "",
|
|
|
|
+ () => DeleteAll (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.DeleteAll)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxCopy,
|
|
|
|
+ "",
|
|
|
|
+ () => Copy (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Copy)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxCut,
|
|
|
|
+ "",
|
|
|
|
+ () => Cut (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Cut)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxPaste,
|
|
|
|
+ "",
|
|
|
|
+ () => Paste (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Paste)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxUndo,
|
|
|
|
+ "",
|
|
|
|
+ () => Undo (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Undo)
|
|
|
|
+ ),
|
|
|
|
+ new (
|
|
|
|
+ Strings.ctxRedo,
|
|
|
|
+ "",
|
|
|
|
+ () => Redo (),
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Redo)
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
- private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e)
|
|
|
|
- {
|
|
|
|
- KeyBindings.ReplaceKey (e.OldKey.KeyCode, e.NewKey.KeyCode);
|
|
|
|
- }
|
|
|
|
|
|
+ private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.ReplaceKey (e.OldKey.KeyCode, e.NewKey.KeyCode); }
|
|
|
|
|
|
private List<Rune> DeleteSelectedText ()
|
|
private List<Rune> DeleteSelectedText ()
|
|
{
|
|
{
|
|
@@ -1344,13 +1335,13 @@ public class TextField : View
|
|
List<RuneCell> currentLine = TextModel.ToRuneCellList (Text);
|
|
List<RuneCell> currentLine = TextModel.ToRuneCellList (Text);
|
|
int cursorPosition = Math.Min (CursorPosition, currentLine.Count);
|
|
int cursorPosition = Math.Min (CursorPosition, currentLine.Count);
|
|
|
|
|
|
- Autocomplete.Context = new AutocompleteContext (
|
|
|
|
- currentLine,
|
|
|
|
- cursorPosition,
|
|
|
|
- Autocomplete.Context != null
|
|
|
|
- ? Autocomplete.Context.Canceled
|
|
|
|
- : false
|
|
|
|
- );
|
|
|
|
|
|
+ Autocomplete.Context = new (
|
|
|
|
+ currentLine,
|
|
|
|
+ cursorPosition,
|
|
|
|
+ Autocomplete.Context != null
|
|
|
|
+ ? Autocomplete.Context.Canceled
|
|
|
|
+ : false
|
|
|
|
+ );
|
|
|
|
|
|
Autocomplete.GenerateSuggestions (
|
|
Autocomplete.GenerateSuggestions (
|
|
Autocomplete.Context
|
|
Autocomplete.Context
|
|
@@ -1371,15 +1362,15 @@ public class TextField : View
|
|
|
|
|
|
if (ColorScheme is null)
|
|
if (ColorScheme is null)
|
|
{
|
|
{
|
|
- cs = new ColorScheme ();
|
|
|
|
|
|
+ cs = new ();
|
|
}
|
|
}
|
|
|
|
|
|
if (cs.Disabled.Foreground == cs.Focus.Background)
|
|
if (cs.Disabled.Foreground == cs.Focus.Background)
|
|
{
|
|
{
|
|
- return new Attribute (cs.Focus.Foreground, cs.Focus.Background);
|
|
|
|
|
|
+ return new (cs.Focus.Foreground, cs.Focus.Background);
|
|
}
|
|
}
|
|
|
|
|
|
- return new Attribute (cs.Disabled.Foreground, cs.Focus.Background);
|
|
|
|
|
|
+ return new (cs.Disabled.Foreground, cs.Focus.Background);
|
|
}
|
|
}
|
|
|
|
|
|
private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemEventArgs obj)
|
|
private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemEventArgs obj)
|
|
@@ -1397,8 +1388,8 @@ public class TextField : View
|
|
private void InsertText (Key a, bool usePreTextChangedCursorPos)
|
|
private void InsertText (Key a, bool usePreTextChangedCursorPos)
|
|
{
|
|
{
|
|
_historyText.Add (
|
|
_historyText.Add (
|
|
- new List<List<RuneCell>> { TextModel.ToRuneCells (_text) },
|
|
|
|
- new Point (_cursorPosition, 0)
|
|
|
|
|
|
+ new() { TextModel.ToRuneCells (_text) },
|
|
|
|
+ new (_cursorPosition, 0)
|
|
);
|
|
);
|
|
|
|
|
|
List<Rune> newText = _text;
|
|
List<Rune> newText = _text;
|
|
@@ -1532,7 +1523,6 @@ public class TextField : View
|
|
|
|
|
|
private bool MoveLeft ()
|
|
private bool MoveLeft ()
|
|
{
|
|
{
|
|
-
|
|
|
|
if (_cursorPosition > 0)
|
|
if (_cursorPosition > 0)
|
|
{
|
|
{
|
|
ClearAllSelection ();
|
|
ClearAllSelection ();
|
|
@@ -1671,13 +1661,10 @@ public class TextField : View
|
|
offB = SuperView.Frame.Right - Frame.Right - 1;
|
|
offB = SuperView.Frame.Right - Frame.Right - 1;
|
|
}
|
|
}
|
|
|
|
|
|
- return 0;//offB;
|
|
|
|
|
|
+ return 0; //offB;
|
|
}
|
|
}
|
|
|
|
|
|
- private int PositionCursor (MouseEvent ev)
|
|
|
|
- {
|
|
|
|
- return PositionCursor (TextModel.GetColFromX (_text, ScrollOffset, ev.Position.X), false);
|
|
|
|
- }
|
|
|
|
|
|
+ private int PositionCursor (MouseEvent ev) { return PositionCursor (TextModel.GetColFromX (_text, ScrollOffset, ev.Position.X), false); }
|
|
|
|
|
|
private int PositionCursor (int x, bool getX = true)
|
|
private int PositionCursor (int x, bool getX = true)
|
|
{
|
|
{
|
|
@@ -1771,7 +1758,6 @@ public class TextField : View
|
|
|
|
|
|
private void DrawAutocomplete ()
|
|
private void DrawAutocomplete ()
|
|
{
|
|
{
|
|
-
|
|
|
|
if (SelectedLength > 0)
|
|
if (SelectedLength > 0)
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
@@ -1862,10 +1848,7 @@ public class TextField : View
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void TextField_Removed (object sender, SuperViewChangedEventArgs e)
|
|
|
|
- {
|
|
|
|
- Autocomplete.HostControl = null;
|
|
|
|
- }
|
|
|
|
|
|
+ private void TextField_Removed (object sender, SuperViewChangedEventArgs e) { Autocomplete.HostControl = null; }
|
|
|
|
|
|
private void TextField_Initialized (object sender, EventArgs e)
|
|
private void TextField_Initialized (object sender, EventArgs e)
|
|
{
|
|
{
|