/
ArabicInputField.cs
157 lines (142 loc) · 3.87 KB
/
ArabicInputField.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ArabicInputField : InputField {
private string o_text = "";
protected override void Append (char input)
{
if (!this.InPlaceEditing ())
{
return;
}
if (this.onValidateInput != null)
{
input = this.onValidateInput (this.text, this.caretPositionInternal, input);
}
else
{
if (this.characterValidation != InputField.CharacterValidation.None)
{
input = this.Validate (this.text, this.caretPositionInternal, input);
}
}
if (input == '\0')
{
return;
}
this.Insert (input);
}
private bool InPlaceEditing ()
{
return !TouchScreenKeyboard.isSupported;
}
private void Insert (char c)
{
string text = c.ToString ();
o_text += "";
this.Delete ();
if (this.characterLimit > 0 && this.text.Length >= this.characterLimit)
{
return;
}
o_text = o_text.Insert (this.m_CaretPosition, text);
this.m_Text = ArabicSupport.ArabicFixer.Fix(o_text, false, true);
this.caretSelectPositionInternal = (this.caretPositionInternal += text.Length );
}
private void Delete ()
{
if (this.caretPositionInternal == this.caretSelectPositionInternal)
{
return;
}
//TODO: Now Buggy if English Letters !!
/*
if (this.caretPositionInternal < this.caretSelectPositionInternal)
{
this.m_Text = this.text.Substring (0, this.caretPositionInternal) + this.text.Substring (this.caretSelectPositionInternal, this.text.Length - this.caretSelectPositionInternal);
this.caretSelectPositionInternal = this.caretPositionInternal;
}
else
{
this.m_Text = this.text.Substring (0, this.caretSelectPositionInternal) + this.text.Substring (this.caretPositionInternal, this.text.Length - this.caretPositionInternal);
this.caretPositionInternal = this.caretSelectPositionInternal;
}
*/
int start;
int end;
if (this.caretPositionInternal < this.caretSelectPositionInternal)
{
start = this.caretSelectPositionInternal;
end = this.caretPositionInternal;
this.caretSelectPositionInternal = this.caretPositionInternal;
}
else
{
start = this.caretPositionInternal;
end = this.caretSelectPositionInternal;
this.caretPositionInternal = this.caretSelectPositionInternal;
}
this.o_text = this.o_text.Substring (0, o_text.Length - start) + this.o_text.Substring (this.o_text.Length - end, this.o_text.Length - (this.o_text.Length - end));
this.m_Text = ArabicSupport.ArabicFixer.Fix(o_text, false, true);
}
private bool hasSelection
{
get
{
return this.caretPositionInternal != this.caretSelectPositionInternal;
}
}
protected InputField.EditState KeyPressed2 (Event evt){
switch (evt.keyCode) {
case KeyCode.Backspace:
if (this.hasSelection)
{
this.Delete ();
}
else
{
if (this.caretPositionInternal > 0)
{
this.o_text = this.o_text.Remove (this.caretPositionInternal - 1, 1);
this.m_Text = ArabicSupport.ArabicFixer.Fix(o_text, false, true);
int num = this.caretPositionInternal - 1;
this.caretPositionInternal = num;
this.caretSelectPositionInternal = num;
}
}
return InputField.EditState.Continue;
}
return InputField.EditState.Continue;
}
private Event m_ProcessingEvent = new Event ();
public override void OnUpdateSelected (UnityEngine.EventSystems.BaseEventData eventData)
{
if (!this.isFocused)
{
return;
}
bool flag = false;
while (Event.PopEvent (this.m_ProcessingEvent))
{
if (this.m_ProcessingEvent.rawType == EventType.KeyDown)
{
flag = true;
InputField.EditState editState;
if(this.m_ProcessingEvent.keyCode == KeyCode.Backspace){
editState = this.KeyPressed2 (this.m_ProcessingEvent);
}else
editState = this.KeyPressed (this.m_ProcessingEvent);
if (editState == InputField.EditState.Finish)
{
this.DeactivateInputField ();
break;
}
}
}
if (flag)
{
this.UpdateLabel ();
}
eventData.Use ();
}
}