diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-31 12:20:31 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-31 12:20:31 +0100 |
| commit | 6f2069f51fd45b0bd15a1e6531e8089af921c29c (patch) | |
| tree | 017d8662cce7f646ec9aea3a16719addbea70043 /Samples/common/src/SampleBaseForEditor.cs | |
| parent | 24bfc35fcb088ff6e8597c9c7e6b9a020dde228c (diff) | |
cut, copy, paste
Diffstat (limited to 'Samples/common/src/SampleBaseForEditor.cs')
| -rw-r--r-- | Samples/common/src/SampleBaseForEditor.cs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Samples/common/src/SampleBaseForEditor.cs b/Samples/common/src/SampleBaseForEditor.cs index 92d0634c..b207eea3 100644 --- a/Samples/common/src/SampleBaseForEditor.cs +++ b/Samples/common/src/SampleBaseForEditor.cs @@ -27,12 +27,11 @@ namespace Samples if (string.IsNullOrEmpty (CurrentDir)) CurrentDir = Path.Combine (Directory.GetCurrentDirectory (), "Interfaces"); - } protected const string _defaultFileName = "unnamed.txt"; protected string source = "", origSource; - protected TextBox editor; + protected Editor editor; bool debugLogRecording; @@ -148,7 +147,10 @@ namespace Samples protected TextSpan selection; protected string SelectedText => selection.IsEmpty ? "" : Source.AsSpan (selection.Start, selection.Length).ToString (); - + public void onEditorSelectionChanged(Object sender, TextSelectionChangeEventArgs e) { + selection = e.Selection; + CMDCut.CanExecute = CMDCopy.CanExecute = !selection.IsEmpty; + } protected void undo () { if (undoStack.TryPop (out TextChange tch)) { redoStack.Push (tch.Inverse (source)); @@ -182,6 +184,7 @@ namespace Samples } protected void copy () { Clipboard = SelectedText; + CMDPaste.CanExecute = !string.IsNullOrEmpty (Clipboard); } protected void paste () { applyChange (new TextChange (selection.Start, selection.Length, Clipboard)); @@ -276,6 +279,10 @@ namespace Samples disableTextChangedEvent = true; Source = tmp.ToString (); disableTextChangedEvent = false; + editor.SelectionStart = null; + editor.SetCursorPosition (change.Start + change.ChangedText.Length); + + forceTextCursor = true; } protected void applyChange (TextChange change) { undoStack.Push (change.Inverse (source)); @@ -316,12 +323,6 @@ namespace Samples return; applyChange (e.Change); } - - protected void onSelectedTextChanged (object sender, EventArgs e) { - selection = (sender as Label).Selection; - Console.WriteLine($"selection:{selection.Start} length:{selection.Length}"); - CMDCut.CanExecute = CMDCopy.CanExecute = !selection.IsEmpty; - } protected void textView_KeyDown (object sender, Crow.KeyEventArgs e) { if (Ctrl) { if (e.Key == Glfw.Key.W) { |