Skip to content
Open
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
4,803 changes: 0 additions & 4,803 deletions Terminal.Gui/Views/TextInput/TextView.cs

This file was deleted.

151 changes: 151 additions & 0 deletions Terminal.Gui/Views/TextInput/TextView/TextView.Clipboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
namespace Terminal.Gui.Views;

public partial class TextView
{
private void SetClipboard (string text)
{
if (text is { })
{
Clipboard.Contents = text;
}
}
/// <summary>Copy the selected text to the clipboard contents.</summary>
public void Copy ()
{
SetWrapModel ();

if (IsSelecting)
{
_copiedText = GetRegion (out _copiedCellsList);
SetClipboard (_copiedText);
_copyWithoutSelection = false;
}
else
{
List<Cell> currentLine = GetCurrentLine ();
_copiedCellsList.Add (currentLine);
_copiedText = Cell.ToString (currentLine);
SetClipboard (_copiedText);
_copyWithoutSelection = true;
}

UpdateWrapModel ();
DoNeededAction ();
}

/// <summary>Cut the selected text to the clipboard contents.</summary>
public void Cut ()
{
SetWrapModel ();
_copiedText = GetRegion (out _copiedCellsList);
SetClipboard (_copiedText);

if (!_isReadOnly)
{
ClearRegion ();

_historyText.Add (
[new (GetCurrentLine ())],
CursorPosition,
TextEditingLineStatus.Replaced
);
}

UpdateWrapModel ();
IsSelecting = false;
DoNeededAction ();
OnContentsChanged ();
}

/// <summary>Paste the clipboard contents into the current selected position.</summary>
public void Paste ()
{
if (_isReadOnly)
{
return;
}

SetWrapModel ();
string? contents = Clipboard.Contents;

if (_copyWithoutSelection && contents!.FirstOrDefault (x => x is '\n' or '\r') == 0)
{
List<Cell> runeList = contents is null ? [] : Cell.ToCellList (contents);
List<Cell> currentLine = GetCurrentLine ();

_historyText.Add ([new (currentLine)], CursorPosition);

List<List<Cell>> addedLine = [new (currentLine), runeList];

_historyText.Add (
[.. addedLine],
CursorPosition,
TextEditingLineStatus.Added
);

_model.AddLine (CurrentRow, runeList);
CurrentRow++;

_historyText.Add (
[new (GetCurrentLine ())],
CursorPosition,
TextEditingLineStatus.Replaced
);

SetNeedsDraw ();
OnContentsChanged ();
}
else
{
if (IsSelecting)
{
ClearRegion ();
}

_copyWithoutSelection = false;
InsertAllText (contents!, true);

if (IsSelecting)
{
_historyText.ReplaceLast (
[new (GetCurrentLine ())],
CursorPosition,
TextEditingLineStatus.Original
);
}

SetNeedsDraw ();
}

UpdateWrapModel ();
IsSelecting = false;
DoNeededAction ();
}

private void ProcessCopy ()
{
ResetColumnTrack ();
Copy ();
}

private void ProcessCut ()
{
ResetColumnTrack ();
Cut ();
}

private void ProcessPaste ()
{
ResetColumnTrack ();

if (_isReadOnly)
{
return;
}

Paste ();
}


private void AppendClipboard (string text) { Clipboard.Contents += text; }
}
46 changes: 46 additions & 0 deletions Terminal.Gui/Views/TextInput/TextView/TextView.ContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Globalization;

namespace Terminal.Gui.Views;

/// <summary>Context menu functionality</summary>
public partial class TextView
{
private PopoverMenu CreateContextMenu ()
{
PopoverMenu menu = new (
new List<View>
{
new MenuItem (this, Command.SelectAll, Strings.ctxSelectAll),
new MenuItem (this, Command.DeleteAll, Strings.ctxDeleteAll),
new MenuItem (this, Command.Copy, Strings.ctxCopy),
new MenuItem (this, Command.Cut, Strings.ctxCut),
new MenuItem (this, Command.Paste, Strings.ctxPaste),
new MenuItem (this, Command.Undo, Strings.ctxUndo),
new MenuItem (this, Command.Redo, Strings.ctxRedo)
});

menu.KeyChanged += ContextMenu_KeyChanged;

return menu;
}

private void ShowContextMenu (Point? mousePosition)
{
if (!Equals (_currentCulture, Thread.CurrentThread.CurrentUICulture))
{
_currentCulture = Thread.CurrentThread.CurrentUICulture;
}

if (mousePosition is null)
{
mousePosition = ViewportToScreen (new Point (CursorPosition.X, CursorPosition.Y));
}

ContextMenu?.MakeVisible (mousePosition);
}

private void ContextMenu_KeyChanged (object? sender, KeyChangedEventArgs e)
{
KeyBindings.Replace (e.OldKey, e.NewKey);
}
}
Loading
Loading