@@ -94,7 +94,7 @@ public List<Result> Query(Query query)
9494 int count = recentPagesCount ;
9595 if ( query . FirstSearch . Length > Constants . RecentKeyword . Length && int . TryParse ( query . FirstSearch [ Constants . RecentKeyword . Length ..] , out int userChosenCount ) )
9696 count = userChosenCount ;
97-
97+
9898 return OneNoteProvider . PageItems . OrderByDescending ( pg => pg . LastModified )
9999 . Take ( count )
100100 . Select ( pg =>
@@ -112,11 +112,33 @@ public List<Result> Query(Query query)
112112 if ( query . FirstSearch . StartsWith ( Constants . StructureKeyword ) )
113113 return notebookExplorer . Explore ( query ) ;
114114
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+ } ;
115126 //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 ) ) ;
119129
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+ } ;
120142 }
121143
122144 public List < Result > LoadContextMenus ( Result selectedResult )
@@ -138,35 +160,35 @@ public List<Result> LoadContextMenus(Result selectedResult)
138160 lastSelectedNotebook = null ;
139161 return true ;
140162 } ;
141- return new List < Result > { result } ;
163+ return new List < Result > { result } ;
142164 case IOneNoteExtSection section :
143165 Result sResult = rc . CreateSectionResult ( section , lastSelectedNotebook ) ;
144166 sResult . Title = "Open and sync section" ;
145167 sResult . SubTitle = section . Name ;
146168 sResult . ContextData = null ;
147- sResult . Action = c =>
169+ sResult . Action = c =>
148170 {
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 ;
156178 } ;
157179 Result nbResult = rc . CreateNotebookResult ( lastSelectedNotebook ) ;
158180 nbResult . Title = "Open and sync notebook" ;
159181 nbResult . SubTitle = lastSelectedNotebook . Name ;
160182 nbResult . Action = c =>
161183 {
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 ;
170192 } ;
171193 return new List < Result > { sResult , nbResult , } ;
172194 default :
@@ -177,17 +199,17 @@ public List<Result> LoadContextMenus(Result selectedResult)
177199 private static string GetLastEdited ( TimeSpan diff )
178200 {
179201 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 )
183205 || PluralCheck ( diff . TotalSeconds , "sec" , ref lastEdited ) )
184206 return lastEdited ;
185207 else
186208 return lastEdited += "Now." ;
187209 bool PluralCheck ( double totalTime , string timeType , ref string lastEdited )
188210 {
189211 var roundedTime = ( int ) Math . Round ( totalTime ) ;
190- if ( roundedTime > 0 )
212+ if ( roundedTime > 0 )
191213 {
192214 string plural = roundedTime == 1 ? "" : "s" ;
193215 lastEdited += $ "{ roundedTime } { timeType } { plural } ago.";
0 commit comments