Skip to content

Commit 53fb3f2

Browse files
committed
Fixed searching issue
1 parent d2f6b8a commit 53fb3f2

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

CutCode/Controllers/SearchBarControl.xaml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,18 @@ private void TextChanged(object sender, TextChangedEventArgs e)
207207
exitBtn.Visibility = Visibility.Hidden;
208208
circularBar.Visibility = string.IsNullOrEmpty(searchBox.Text) ? Visibility.Hidden : Visibility.Visible;
209209
activityTimer.IsEnabled = true;
210+
letsType = true;
210211
}
211212
}
212213

213214
private void ClearClicked(object sender, EventArgs e)
214215
{
215216
searchBox.Text = "";
216217
SearchCommand?.Execute("");
218+
letsType = false;
217219
}
218220

219-
221+
private bool letsType = true;
220222
private string OldText = "";
221223
private string SearchedText = "";
222224
private void InActivity(object sender, EventArgs e)
@@ -225,10 +227,13 @@ private void InActivity(object sender, EventArgs e)
225227
{
226228
if (OldText == Text)
227229
{
228-
OldText = "";
229-
SearchedText = Text;
230-
SearchCommand?.Execute(Text);
231-
activityTimer.IsEnabled = false;
230+
if (letsType)
231+
{
232+
OldText = "";
233+
SearchedText = Text;
234+
SearchCommand?.Execute(Text);
235+
activityTimer.IsEnabled = false;
236+
}
232237
}
233238
else
234239
{

CutCode/DataBase/DataBaseManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public ObservableCollection<CodeBoxModel> OrderCode(string order)
212212
if (ind == 0 || ind == 1) ChangeSort(AllOrderKind[ind]);
213213
}
214214

215-
if (ind < 2) AllCodes = lst;
215+
//if (ind < 2) AllCodes = lst;
216216
return lst;
217217
}
218218

@@ -239,7 +239,7 @@ public bool FavModify(CodeBoxModel code)
239239
return true;
240240
}
241241

242-
public ObservableCollection<CodeBoxModel> SearchCode(string text, string from)
242+
public async Task<ObservableCollection<CodeBoxModel>> SearchCode(string text, string from)
243243
{
244244
var currentCode = from == "Home" ? AllCodes : FavCodes;
245245

CutCode/Interfaces/IDataBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IDataBase
1818
bool DelCode(CodeBoxModel code);
1919
ObservableCollection<CodeBoxModel> OrderCode(string order);
2020
bool FavModify(CodeBoxModel code);
21-
ObservableCollection<CodeBoxModel> SearchCode(string text, string from);
21+
Task<ObservableCollection<CodeBoxModel>> SearchCode(string text, string from);
2222

2323
bool isLightTheme { get; set; }
2424
string sortBy { get; set; }

CutCode/ViewModels/FavViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ public bool IsSearched
130130
set => SetAndNotify(ref _IsSearched, value);
131131
}
132132

133-
public void SearchCommand(string text)
133+
public async void SearchCommand(string text)
134134
{
135+
Trace.WriteLine($"this is {text}");
135136
IsSearched = false;
136137
if (text == "")
137138
{
@@ -142,7 +143,7 @@ public void SearchCommand(string text)
142143
{
143144
if(AllCodes.Count > 0)
144145
{
145-
AllCodes = database.SearchCode(text, "Home");
146+
AllCodes = await database.SearchCode(text, "Home");
146147
if (AllCodes.Count == 0) VisChange("Not found :(");
147148
}
148149
}

CutCode/ViewModels/HomeViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void ComboBoxItemSelected(string kind)
197197
}
198198
}
199199

200-
public void SearchCommand(string text)
200+
public async void SearchCommand(string text)
201201
{
202202
IsSearched = false;
203203
if(text == "")
@@ -210,7 +210,7 @@ public void SearchCommand(string text)
210210
{
211211
if (AllCodes.Count > 0)
212212
{
213-
AllCodes = database.SearchCode(text, "Home");
213+
AllCodes = await database.SearchCode(text, "Home");
214214
VisChange("Not found :(");
215215
}
216216
}

0 commit comments

Comments
 (0)