mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
Global clipboard
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using NStack;
|
||||
|
||||
namespace Terminal.Gui {
|
||||
public class Clipboard {
|
||||
public Clipboard ()
|
||||
{
|
||||
}
|
||||
public static ustring Contents { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Terminal.Gui {
|
||||
/// functionality, and mouse support.
|
||||
/// </remarks>
|
||||
public class TextField : View {
|
||||
ustring text, kill;
|
||||
ustring text;
|
||||
int first, point;
|
||||
bool used;
|
||||
|
||||
@@ -125,6 +125,12 @@ namespace Terminal.Gui {
|
||||
set { base.CanFocus = value; }
|
||||
}
|
||||
|
||||
void SetClipboard (ustring text)
|
||||
{
|
||||
if (!Secret)
|
||||
Clipboard.Contents = text;
|
||||
}
|
||||
|
||||
public override bool ProcessKey (KeyEvent kb)
|
||||
{
|
||||
switch (kb.Key) {
|
||||
@@ -174,21 +180,22 @@ namespace Terminal.Gui {
|
||||
break;
|
||||
|
||||
case Key.ControlK: // kill-to-end
|
||||
kill = text.Substring (point);
|
||||
SetClipboard (text.Substring (point));
|
||||
SetText (text [0, point]);
|
||||
Adjust ();
|
||||
break;
|
||||
|
||||
case Key.ControlY: // Control-y, yank
|
||||
if (kill == null)
|
||||
var clip = Clipboard.Contents;
|
||||
if (clip== null)
|
||||
return true;
|
||||
|
||||
if (point == text.Length) {
|
||||
SetText (text + kill);
|
||||
SetText (text + clip);
|
||||
point = text.Length;
|
||||
} else {
|
||||
SetText (text [0, point] + kill + text.Substring (point));
|
||||
point += kill.Length;
|
||||
SetText (text [0, point] + clip + text.Substring (point));
|
||||
point += clip.RuneCount;
|
||||
}
|
||||
Adjust ();
|
||||
break;
|
||||
@@ -207,6 +214,11 @@ namespace Terminal.Gui {
|
||||
Adjust ();
|
||||
break;
|
||||
|
||||
// MISSING:
|
||||
// Alt-D, Alt-backspace
|
||||
// Alt-Y
|
||||
// Delete adding to kill buffer
|
||||
|
||||
default:
|
||||
// Ignore other control characters.
|
||||
if (kb.Key < Key.Space || kb.Key > Key.CharMask)
|
||||
|
||||
Reference in New Issue
Block a user