@@ -94,7 +94,7 @@ public List<Result> Query(Query query)
94
94
int count = recentPagesCount ;
95
95
if ( query . FirstSearch . Length > Constants . RecentKeyword . Length && int . TryParse ( query . FirstSearch [ Constants . RecentKeyword . Length ..] , out int userChosenCount ) )
96
96
count = userChosenCount ;
97
-
97
+
98
98
return OneNoteProvider . PageItems . OrderByDescending ( pg => pg . LastModified )
99
99
. Take ( count )
100
100
. Select ( pg =>
@@ -112,11 +112,33 @@ public List<Result> Query(Query query)
112
112
if ( query . FirstSearch . StartsWith ( Constants . StructureKeyword ) )
113
113
return notebookExplorer . Explore ( query ) ;
114
114
115
+ //Check for invalid start of query i.e. symbols
116
+ if ( ! char . IsLetterOrDigit ( query . Search [ 0 ] ) )
117
+ return new List < Result > ( )
118
+ {
119
+ new Result
120
+ {
121
+ Title = "Invalid query" ,
122
+ SubTitle = "The first character of the search must be a letter or a digit" ,
123
+ IcoPath = Constants . WarningLogoPath ,
124
+ }
125
+ } ;
115
126
//Default search
116
- return OneNoteProvider . FindPages ( query . Search )
117
- . Select ( pg => rc . CreatePageResult ( pg , context . API . FuzzySearch ( query . Search , pg . Name ) . MatchData ) )
118
- . ToList ( ) ;
127
+ var searches = OneNoteProvider . FindPages ( query . Search )
128
+ . Select ( pg => rc . CreatePageResult ( pg , context . API . FuzzySearch ( query . Search , pg . Name ) . MatchData ) ) ;
119
129
130
+ if ( searches . Any ( ) )
131
+ return searches . ToList ( ) ;
132
+
133
+ return new List < Result >
134
+ {
135
+ new Result
136
+ {
137
+ Title = "No matches found" ,
138
+ SubTitle = "Try searching something else, or syncing your notebooks." ,
139
+ IcoPath = Constants . LogoIconPath ,
140
+ }
141
+ } ;
120
142
}
121
143
122
144
public List < Result > LoadContextMenus ( Result selectedResult )
@@ -138,35 +160,35 @@ public List<Result> LoadContextMenus(Result selectedResult)
138
160
lastSelectedNotebook = null ;
139
161
return true ;
140
162
} ;
141
- return new List < Result > { result } ;
163
+ return new List < Result > { result } ;
142
164
case IOneNoteExtSection section :
143
165
Result sResult = rc . CreateSectionResult ( section , lastSelectedNotebook ) ;
144
166
sResult . Title = "Open and sync section" ;
145
167
sResult . SubTitle = section . Name ;
146
168
sResult . ContextData = null ;
147
- sResult . Action = c =>
169
+ sResult . Action = c =>
148
170
{
149
- section . Pages . OrderByDescending ( pg => pg . LastModified )
150
- . First ( )
151
- . OpenInOneNote ( ) ;
152
- section . Sync ( ) ;
153
- lastSelectedNotebook = null ;
154
- lastSelectedSection = null ;
155
- return true ;
171
+ section . Pages . OrderByDescending ( pg => pg . LastModified )
172
+ . First ( )
173
+ . OpenInOneNote ( ) ;
174
+ section . Sync ( ) ;
175
+ lastSelectedNotebook = null ;
176
+ lastSelectedSection = null ;
177
+ return true ;
156
178
} ;
157
179
Result nbResult = rc . CreateNotebookResult ( lastSelectedNotebook ) ;
158
180
nbResult . Title = "Open and sync notebook" ;
159
181
nbResult . SubTitle = lastSelectedNotebook . Name ;
160
182
nbResult . Action = c =>
161
183
{
162
- lastSelectedNotebook . Sections . First ( ) . Pages
163
- . OrderByDescending ( pg => pg . LastModified )
164
- . First ( )
165
- . OpenInOneNote ( ) ;
166
- lastSelectedNotebook . Sync ( ) ;
167
- lastSelectedNotebook = null ;
168
- lastSelectedSection = null ;
169
- return true ;
184
+ lastSelectedNotebook . Sections . First ( ) . Pages
185
+ . OrderByDescending ( pg => pg . LastModified )
186
+ . First ( )
187
+ . OpenInOneNote ( ) ;
188
+ lastSelectedNotebook . Sync ( ) ;
189
+ lastSelectedNotebook = null ;
190
+ lastSelectedSection = null ;
191
+ return true ;
170
192
} ;
171
193
return new List < Result > { sResult , nbResult , } ;
172
194
default :
@@ -177,17 +199,17 @@ public List<Result> LoadContextMenus(Result selectedResult)
177
199
private static string GetLastEdited ( TimeSpan diff )
178
200
{
179
201
string lastEdited = "Last editied " ;
180
- if ( PluralCheck ( diff . TotalDays , "day" , ref lastEdited )
181
- || PluralCheck ( diff . TotalHours , "hour" , ref lastEdited )
182
- || PluralCheck ( diff . TotalMinutes , "min" , ref lastEdited )
202
+ if ( PluralCheck ( diff . TotalDays , "day" , ref lastEdited )
203
+ || PluralCheck ( diff . TotalHours , "hour" , ref lastEdited )
204
+ || PluralCheck ( diff . TotalMinutes , "min" , ref lastEdited )
183
205
|| PluralCheck ( diff . TotalSeconds , "sec" , ref lastEdited ) )
184
206
return lastEdited ;
185
207
else
186
208
return lastEdited += "Now." ;
187
209
bool PluralCheck ( double totalTime , string timeType , ref string lastEdited )
188
210
{
189
211
var roundedTime = ( int ) Math . Round ( totalTime ) ;
190
- if ( roundedTime > 0 )
212
+ if ( roundedTime > 0 )
191
213
{
192
214
string plural = roundedTime == 1 ? "" : "s" ;
193
215
lastEdited += $ "{ roundedTime } { timeType } { plural } ago.";
0 commit comments