|
@@ -1,28 +1,4 @@
|
|
|
-//
|
|
|
// TextView.cs: multi-line text editing
|
|
|
-//
|
|
|
-// Authors:
|
|
|
-// Miguel de Icaza ([email protected])
|
|
|
-//
|
|
|
-//
|
|
|
-// TODO:
|
|
|
-// In ReadOnly mode backspace/space behave like pageup/pagedown
|
|
|
-// Attributed text on spans
|
|
|
-// Replace insertion with Insert method
|
|
|
-// String accumulation (Control-k, control-k is not preserving the last new line, see StringToRunes
|
|
|
-// Alt-D, Alt-Backspace
|
|
|
-// API to set the cursor position
|
|
|
-// API to scroll to a particular place
|
|
|
-// keybindings to go to top/bottom
|
|
|
-// public API to insert, remove ranges
|
|
|
-// Add word forward/word backwards commands
|
|
|
-// Save buffer API
|
|
|
-// Mouse
|
|
|
-//
|
|
|
-// Desirable:
|
|
|
-// Move all the text manipulation into the TextModel
|
|
|
-
|
|
|
-
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Globalization;
|
|
@@ -1039,120 +1015,119 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Multi-line text editing <see cref="View"/>
|
|
|
+ /// Multi-line text editing <see cref="View"/>.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// <para>
|
|
|
- /// <see cref="TextView"/> provides a multi-line text editor. Users interact
|
|
|
- /// with it with the standard Emacs commands for movement or the arrow
|
|
|
- /// keys.
|
|
|
- /// </para>
|
|
|
- /// <list type="table">
|
|
|
- /// <listheader>
|
|
|
- /// <term>Shortcut</term>
|
|
|
- /// <description>Action performed</description>
|
|
|
- /// </listheader>
|
|
|
- /// <item>
|
|
|
- /// <term>Left cursor, Control-b</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the editing point left.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Right cursor, Control-f</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the editing point right.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Alt-b</term>
|
|
|
- /// <description>
|
|
|
- /// Moves one word back.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Alt-f</term>
|
|
|
- /// <description>
|
|
|
- /// Moves one word forward.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Up cursor, Control-p</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the editing point one line up.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Down cursor, Control-n</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the editing point one line down
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Home key, Control-a</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the cursor to the beginning of the line.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>End key, Control-e</term>
|
|
|
- /// <description>
|
|
|
- /// Moves the cursor to the end of the line.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Control-Home</term>
|
|
|
- /// <description>
|
|
|
- /// Scrolls to the first line and moves the cursor there.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Control-End</term>
|
|
|
- /// <description>
|
|
|
- /// Scrolls to the last line and moves the cursor there.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Delete, Control-d</term>
|
|
|
- /// <description>
|
|
|
- /// Deletes the character in front of the cursor.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Backspace</term>
|
|
|
- /// <description>
|
|
|
- /// Deletes the character behind the cursor.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Control-k</term>
|
|
|
- /// <description>
|
|
|
- /// Deletes the text until the end of the line and replaces the kill buffer
|
|
|
- /// with the deleted text. You can paste this text in a different place by
|
|
|
- /// using Control-y.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Control-y</term>
|
|
|
- /// <description>
|
|
|
- /// Pastes the content of the kill ring into the current position.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Alt-d</term>
|
|
|
- /// <description>
|
|
|
- /// Deletes the word above the cursor and adds it to the kill ring. You
|
|
|
- /// can paste the contents of the kill ring with Control-y.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// <item>
|
|
|
- /// <term>Control-q</term>
|
|
|
- /// <description>
|
|
|
- /// Quotes the next input character, to prevent the normal processing of
|
|
|
- /// key handling to take place.
|
|
|
- /// </description>
|
|
|
- /// </item>
|
|
|
- /// </list>
|
|
|
+ /// <para>
|
|
|
+ /// <see cref="TextView"/> provides a multi-line text editor. Users interact
|
|
|
+ /// with it with the standard Windows, Mac, and Linux (Emacs) commands.
|
|
|
+ /// </para>
|
|
|
+ /// <list type="table">
|
|
|
+ /// <listheader>
|
|
|
+ /// <term>Shortcut</term>
|
|
|
+ /// <description>Action performed</description>
|
|
|
+ /// </listheader>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Left cursor, Control-b</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the editing point left.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Right cursor, Control-f</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the editing point right.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Alt-b</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves one word back.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Alt-f</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves one word forward.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Up cursor, Control-p</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the editing point one line up.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Down cursor, Control-n</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the editing point one line down
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Home key, Control-a</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the cursor to the beginning of the line.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>End key, Control-e</term>
|
|
|
+ /// <description>
|
|
|
+ /// Moves the cursor to the end of the line.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Control-Home</term>
|
|
|
+ /// <description>
|
|
|
+ /// Scrolls to the first line and moves the cursor there.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Control-End</term>
|
|
|
+ /// <description>
|
|
|
+ /// Scrolls to the last line and moves the cursor there.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Delete, Control-d</term>
|
|
|
+ /// <description>
|
|
|
+ /// Deletes the character in front of the cursor.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Backspace</term>
|
|
|
+ /// <description>
|
|
|
+ /// Deletes the character behind the cursor.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Control-k</term>
|
|
|
+ /// <description>
|
|
|
+ /// Deletes the text until the end of the line and replaces the kill buffer
|
|
|
+ /// with the deleted text. You can paste this text in a different place by
|
|
|
+ /// using Control-y.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Control-y</term>
|
|
|
+ /// <description>
|
|
|
+ /// Pastes the content of the kill ring into the current position.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Alt-d</term>
|
|
|
+ /// <description>
|
|
|
+ /// Deletes the word above the cursor and adds it to the kill ring. You
|
|
|
+ /// can paste the contents of the kill ring with Control-y.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// <item>
|
|
|
+ /// <term>Control-q</term>
|
|
|
+ /// <description>
|
|
|
+ /// Quotes the next input character, to prevent the normal processing of
|
|
|
+ /// key handling to take place.
|
|
|
+ /// </description>
|
|
|
+ /// </item>
|
|
|
+ /// </list>
|
|
|
/// </remarks>
|
|
|
public class TextView : View {
|
|
|
TextModel model = new TextModel ();
|
|
@@ -1177,14 +1152,14 @@ namespace Terminal.Gui {
|
|
|
/// Raised when the <see cref="Text"/> property of the <see cref="TextView"/> changes.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// The <see cref="Text"/> property of <see cref="TextView"/> only changes when it is explictly
|
|
|
+ /// The <see cref="Text"/> property of <see cref="TextView"/> only changes when it is explicitly
|
|
|
/// set, not as the user types. To be notified as the user changes the contents of the TextView
|
|
|
/// see <see cref="IsDirty"/>.
|
|
|
/// </remarks>
|
|
|
public event Action TextChanged;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Raised when the contents of the <see cref="TextView"/> are changed.
|
|
|
+ /// Raised when the contents of the <see cref="TextView"/> are changed.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// Unlike the <see cref="TextChanged"/> event, this event is raised whenever the user types or
|
|
@@ -1199,12 +1174,12 @@ namespace Terminal.Gui {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Provides autocomplete context menu based on suggestions at the current cursor
|
|
|
- /// position. Populate <see cref="Autocomplete.AllSuggestions"/> to enable this feature
|
|
|
+ /// position. Populate <see cref="Autocomplete.AllSuggestions"/> to enable this feature
|
|
|
/// </summary>
|
|
|
public IAutocomplete Autocomplete { get; protected set; } = new TextViewAutocomplete ();
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Initializes a <see cref="TextView"/> on the specified area, with absolute position and size.
|
|
|
+ /// Initializes a <see cref="TextView"/> on the specified area, with absolute position and size.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// </remarks>
|
|
@@ -1214,8 +1189,8 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Initializes a <see cref="TextView"/> on the specified area,
|
|
|
- /// with dimensions controlled with the X, Y, Width and Height properties.
|
|
|
+ /// Initializes a <see cref="TextView"/> on the specified area,
|
|
|
+ /// with dimensions controlled with the X, Y, Width and Height properties.
|
|
|
/// </summary>
|
|
|
public TextView () : base ()
|
|
|
{
|
|
@@ -1495,7 +1470,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Sets or gets the text in the <see cref="TextView"/>.
|
|
|
+ /// Sets or gets the text in the <see cref="TextView"/>.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// The <see cref="TextChanged"/> event is fired whenever this property is set. Note, however,
|
|
@@ -1576,12 +1551,12 @@ namespace Terminal.Gui {
|
|
|
public int Maxlength => model.GetMaxVisibleLine (topRow, topRow + Frame.Height, TabWidth);
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Gets the number of lines.
|
|
|
+ /// Gets the number of lines.
|
|
|
/// </summary>
|
|
|
public int Lines => model.Count;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Sets or gets the current cursor position.
|
|
|
+ /// Sets or gets the current cursor position.
|
|
|
/// </summary>
|
|
|
public Point CursorPosition {
|
|
|
get => new Point (currentColumn, currentRow);
|
|
@@ -1845,7 +1820,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Loads the contents of the file into the <see cref="TextView"/>.
|
|
|
+ /// Loads the contents of the file into the <see cref="TextView"/>.
|
|
|
/// </summary>
|
|
|
/// <returns><c>true</c>, if file was loaded, <c>false</c> otherwise.</returns>
|
|
|
/// <param name="path">Path to the file to load.</param>
|
|
@@ -1868,7 +1843,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Loads the contents of the stream into the <see cref="TextView"/>.
|
|
|
+ /// Loads the contents of the stream into the <see cref="TextView"/>.
|
|
|
/// </summary>
|
|
|
/// <returns><c>true</c>, if stream was loaded, <c>false</c> otherwise.</returns>
|
|
|
/// <param name="stream">Stream to load the contents from.</param>
|
|
@@ -1881,7 +1856,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Closes the contents of the stream into the <see cref="TextView"/>.
|
|
|
+ /// Closes the contents of the stream into the <see cref="TextView"/>.
|
|
|
/// </summary>
|
|
|
/// <returns><c>true</c>, if stream was closed, <c>false</c> otherwise.</returns>
|
|
|
public bool CloseFile ()
|
|
@@ -1893,7 +1868,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Gets the current cursor row.
|
|
|
+ /// Gets the current cursor row.
|
|
|
/// </summary>
|
|
|
public int CurrentRow => currentRow;
|
|
|
|
|
@@ -1904,7 +1879,7 @@ namespace Terminal.Gui {
|
|
|
public int CurrentColumn => currentColumn;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Positions the cursor on the current row and column
|
|
|
+ /// Positions the cursor on the current row and column
|
|
|
/// </summary>
|
|
|
public override void PositionCursor ()
|
|
|
{
|
|
@@ -1955,7 +1930,7 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Sets the driver to the default color for the control where no text is being rendered. Defaults to <see cref="ColorScheme.Normal"/>.
|
|
|
+ /// Sets the driver to the default color for the control where no text is being rendered. Defaults to <see cref="ColorScheme.Normal"/>.
|
|
|
/// </summary>
|
|
|
protected virtual void SetNormalColor ()
|
|
|
{
|
|
@@ -1964,7 +1939,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idx"/> of the
|
|
|
- /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
+ /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
/// Defaults to <see cref="ColorScheme.Normal"/>.
|
|
|
/// </summary>
|
|
|
/// <param name="line"></param>
|
|
@@ -1976,7 +1951,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idx"/> of the
|
|
|
- /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
+ /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
/// Defaults to <see cref="ColorScheme.Focus"/>.
|
|
|
/// </summary>
|
|
|
/// <param name="line"></param>
|
|
@@ -1988,7 +1963,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idx"/> of the
|
|
|
- /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
+ /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
/// Defaults to <see cref="ColorScheme.Focus"/>.
|
|
|
/// </summary>
|
|
|
/// <param name="line"></param>
|
|
@@ -2006,7 +1981,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idx"/> of the
|
|
|
- /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
+ /// current <paramref name="line"/>. Override to provide custom coloring by calling <see cref="ConsoleDriver.SetAttribute(Attribute)"/>
|
|
|
/// Defaults to <see cref="ColorScheme.HotFocus"/>.
|
|
|
/// </summary>
|
|
|
/// <param name="line"></param>
|
|
@@ -2019,7 +1994,7 @@ namespace Terminal.Gui {
|
|
|
bool isReadOnly = false;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Gets or sets whether the <see cref="TextView"/> is in read-only mode or not
|
|
|
+ /// Gets or sets whether the <see cref="TextView"/> is in read-only mode or not
|
|
|
/// </summary>
|
|
|
/// <value>Boolean value(Default false)</value>
|
|
|
public bool ReadOnly {
|
|
@@ -2772,7 +2747,7 @@ namespace Terminal.Gui {
|
|
|
/// will scroll the <see cref="TextView"/> to display the specified column at the left if <paramref name="isRow"/> is false.
|
|
|
/// </summary>
|
|
|
/// <param name="idx">Row that should be displayed at the top or Column that should be displayed at the left,
|
|
|
- /// if the value is negative it will be reset to zero</param>
|
|
|
+ /// if the value is negative it will be reset to zero</param>
|
|
|
/// <param name="isRow">If true (default) the <paramref name="idx"/> is a row, column otherwise.</param>
|
|
|
public void ScrollTo (int idx, bool isRow = true)
|
|
|
{
|