Global clipboard

This commit is contained in:
Miguel de Icaza
2018-02-05 23:01:54 -05:00
parent 5e5cc25b8f
commit ed6976ecab
2 changed files with 21 additions and 9 deletions

View File

@@ -1,8 +1,8 @@
using System;
using NStack;
namespace Terminal.Gui {
public class Clipboard {
public Clipboard ()
{
}
public static ustring Contents { get; set; }
}
}

View File

@@ -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)