@@ -19,6 +19,7 @@ ULuaMultiLineEditableTextBox::ULuaMultiLineEditableTextBox()
19
19
20
20
bIsReadonly = false ;
21
21
bHandleTab = true ;
22
+ bHandleArrows = true ;
22
23
23
24
CodeStyle = FTextBlockStyle ()
24
25
.SetFont (WidgetStyle.Font )
@@ -70,13 +71,86 @@ FReply ULuaMultiLineEditableTextBox::OnKeyChar(const FGeometry& InGeometry, cons
70
71
71
72
FReply ULuaMultiLineEditableTextBox::OnKeyDown (const FGeometry& InGeometry, const FKeyEvent& InKeyEvent)
72
73
{
73
- if (bHandleTab && InKeyEvent.GetKeyCode () == 9 )
74
+ FKey Key = InKeyEvent.GetKey ();
75
+ if (bHandleTab && Key == EKeys::Tab)
74
76
{
75
77
return FReply::Handled ();
76
78
}
79
+
80
+ if (bHandleArrows)
81
+ {
82
+ if (Key == EKeys::Up)
83
+ {
84
+ MoveCursorUp ();
85
+ return FReply::Handled ();
86
+ }
87
+
88
+ if (Key == EKeys::Down)
89
+ {
90
+ MoveCursorDown ();
91
+ return FReply::Handled ();
92
+ }
93
+
94
+ if (Key == EKeys::Right)
95
+ {
96
+ MoveCursorRight ();
97
+ return FReply::Handled ();
98
+ }
99
+
100
+ if (Key == EKeys::Left)
101
+ {
102
+ MoveCursorLeft ();
103
+ return FReply::Handled ();
104
+ }
105
+ }
106
+
77
107
return EditableTextBoxPtr->SMultiLineEditableTextBox ::OnKeyDown (InGeometry, InKeyEvent);
78
108
}
79
109
110
+ void ULuaMultiLineEditableTextBox::OnCursorMoved (const FTextLocation& Location)
111
+ {
112
+ CursorLocation = Location;
113
+ }
114
+
115
+ int32 ULuaMultiLineEditableTextBox::GetCursorLine () const
116
+ {
117
+ return CursorLocation.GetLineIndex ();
118
+ }
119
+
120
+ int32 ULuaMultiLineEditableTextBox::GetCursorColumn () const
121
+ {
122
+ return CursorLocation.GetOffset ();
123
+ }
124
+
125
+ void ULuaMultiLineEditableTextBox::CursorGoTo (int32 Line, int32 Column)
126
+ {
127
+ if (Line < 0 )
128
+ Line = 0 ;
129
+ if (Column < 0 )
130
+ Column = 0 ;
131
+ return EditableTextBoxPtr->GoTo (FTextLocation (Line, Column));
132
+ }
133
+
134
+ void ULuaMultiLineEditableTextBox::MoveCursorUp ()
135
+ {
136
+ return CursorGoTo (CursorLocation.GetLineIndex () - 1 , 0 );
137
+ }
138
+
139
+ void ULuaMultiLineEditableTextBox::MoveCursorDown ()
140
+ {
141
+ return CursorGoTo (CursorLocation.GetLineIndex () + 1 , 0 );
142
+ }
143
+
144
+ void ULuaMultiLineEditableTextBox::MoveCursorRight ()
145
+ {
146
+ return CursorGoTo (CursorLocation.GetLineIndex (), CursorLocation.GetOffset () + 1 );
147
+ }
148
+
149
+ void ULuaMultiLineEditableTextBox::MoveCursorLeft ()
150
+ {
151
+ return CursorGoTo (CursorLocation.GetLineIndex (), CursorLocation.GetOffset () - 1 );
152
+ }
153
+
80
154
void ULuaMultiLineEditableTextBox::SynchronizeProperties ()
81
155
{
82
156
Super::SynchronizeProperties ();
@@ -110,6 +184,8 @@ TSharedRef<SWidget> ULuaMultiLineEditableTextBox::RebuildWidget()
110
184
.OnKeyCharHandler_UObject (this , &ULuaMultiLineEditableTextBox::OnKeyChar)
111
185
.OnKeyDownHandler_UObject (this , &ULuaMultiLineEditableTextBox::OnKeyDown)
112
186
.IsReadOnly (bIsReadonly)
187
+ .AllowContextMenu (false )
188
+ .OnCursorMoved_UObject (this , &ULuaMultiLineEditableTextBox::OnCursorMoved)
113
189
.Style (&WidgetStyle);
114
190
115
191
return EditableTextBoxPtr.ToSharedRef ();
0 commit comments