Skip to content

Commit

Permalink
Fix textbox cut command (#458)
Browse files Browse the repository at this point in the history
* Fix MenuFlyoutItem

Disable the cut command for readonly textbox.

* Added post-processing for text cut command.

* Evaluates the RichEditBox.IsReadOnly state second.

* Modified the order of conditional expressions.
  • Loading branch information
niyari authored Mar 26, 2022
1 parent f156131 commit 3e8b744
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/dev/impl/DevToys/UI/Controls/CustomTextBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ public CustomTextBox()

private bool CanExecuteCutCommand()
{
return RichEditBox != null && RichEditBox.TextDocument.Selection.Length != 0 && IsEnabled && RichEditBox.TextDocument.CanCopy();
return IsEnabled
&& !IsReadOnly
&& RichEditBox != null
&& RichEditBox.TextDocument.Selection.Length != 0
&& RichEditBox.TextDocument.CanCopy();
}

private void ExecuteCutCommand()
Expand Down Expand Up @@ -203,7 +207,10 @@ private void ExecutePasteCommand()

private bool CanExecuteDeleteCommand()
{
return RichEditBox != null && RichEditBox.TextDocument.Selection.Length != 0 && IsEnabled && !IsReadOnly;
return IsEnabled
&& !IsReadOnly
&& RichEditBox != null
&& RichEditBox.TextDocument.Selection.Length != 0;
}

private void ExecuteDeleteCommand()
Expand Down Expand Up @@ -649,6 +656,7 @@ private void TextBox_CopyingToClipboard(TextBox sender, TextControlCopyingToClip
private void TextBox_CuttingToClipboard(TextBox sender, TextControlCuttingToClipboardEventArgs args)
{
CopyTextBoxSelectionToClipboard();
sender.SelectedText = string.Empty;
args.Handled = true;
}

Expand All @@ -666,6 +674,7 @@ private void RichEditBox_CopyingToClipboard(RichEditBox sender, TextControlCopyi
private void RichEditBox_CuttingToClipboard(RichEditBox sender, TextControlCuttingToClipboardEventArgs args)
{
CopyRichEditBoxSelectionToClipboard();
sender.TextDocument.Selection.Text = string.Empty;
args.Handled = true;
}

Expand Down

0 comments on commit 3e8b744

Please sign in to comment.