瀏覽代碼

Don't copy to clipboard if the selection is empty

Michael Ragazzon 4 年之前
父節點
當前提交
f0e7ad239c
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      Source/Core/Elements/WidgetTextInput.cpp

+ 4 - 4
Source/Core/Elements/WidgetTextInput.cpp

@@ -177,7 +177,7 @@ int WidgetTextInput::GetMaxLength() const
 
 
 int WidgetTextInput::GetLength() const
 int WidgetTextInput::GetLength() const
 {
 {
-	String value = GetElement()->GetAttribute< String >("value", "");
+	const String value = GetElement()->GetAttribute< String >("value", "");
 	size_t result = StringUtilities::LengthUTF8(value);
 	size_t result = StringUtilities::LengthUTF8(value);
 	return (int)result;
 	return (int)result;
 }
 }
@@ -388,14 +388,14 @@ void WidgetTextInput::ProcessEvent(Event& event)
 
 
 		case Input::KI_C:
 		case Input::KI_C:
 		{
 		{
-			if (ctrl)
+			if (ctrl && selection_length > 0)
 				CopySelection();
 				CopySelection();
 		}
 		}
 		break;
 		break;
 
 
 		case Input::KI_X:
 		case Input::KI_X:
 		{
 		{
-			if (ctrl)
+			if (ctrl && selection_length > 0)
 			{
 			{
 				CopySelection();
 				CopySelection();
 				DeleteSelection();
 				DeleteSelection();
@@ -566,7 +566,7 @@ bool WidgetTextInput::DeleteCharacters(CursorMovement direction)
 // Copies the selection (if any) to the clipboard.
 // Copies the selection (if any) to the clipboard.
 void WidgetTextInput::CopySelection()
 void WidgetTextInput::CopySelection()
 {
 {
-	const String& value = GetElement()->GetAttribute< String >("value", "");
+	const String value = GetElement()->GetAttribute< String >("value", "");
 	const String snippet = value.substr(std::min(size_t(selection_begin_index), size_t(value.size())), selection_length);
 	const String snippet = value.substr(std::min(size_t(selection_begin_index), size_t(value.size())), selection_length);
 	GetSystemInterface()->SetClipboardText(snippet);
 	GetSystemInterface()->SetClipboardText(snippet);
 }
 }