@@ -26,7 +26,7 @@ import { ContextKeyExpr, IContextKey, IContextKeyService } from 'vs/platform/con
26
26
import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
27
27
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
28
28
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
29
- import { INotificationService } from 'vs/platform/notification/common/notification' ;
29
+ import { INotificationService , Severity } from 'vs/platform/notification/common/notification' ;
30
30
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput' ;
31
31
import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
32
32
import { IThemeService , themeColorFromId } from 'vs/platform/theme/common/themeService' ;
@@ -759,22 +759,46 @@ export class MoveToMatchFindAction extends EditorAction {
759
759
760
760
public run ( accessor : ServicesAccessor , editor : ICodeEditor , args : any ) : void | Promise < void > {
761
761
const controller = CommonFindController . get ( editor ) ;
762
-
763
762
if ( ! controller ) {
764
763
return ;
765
764
}
766
765
766
+ const matchesCount = controller . getState ( ) . matchesCount ;
767
+ if ( matchesCount < 1 ) {
768
+ const notificationService = accessor . get ( INotificationService ) ;
769
+ notificationService . notify ( {
770
+ severity : Severity . Warning ,
771
+ message : nls . localize ( 'findMatchAction.noResults' , "No matches. Try searching for something else." )
772
+ } ) ;
773
+ return ;
774
+ }
775
+
767
776
const quickInputService = accessor . get ( IQuickInputService ) ;
768
777
const inputBox = quickInputService . createInputBox ( ) ;
769
- inputBox . placeholder = nls . localize ( 'findMatchAction.inputPlaceHolder' , "Type a number to go to a specific match (between 1 and {0})" , controller . getState ( ) . matchesCount ) ;
778
+ inputBox . placeholder = nls . localize ( 'findMatchAction.inputPlaceHolder' , "Type a number to go to a specific match (between 1 and {0})" , matchesCount ) ;
770
779
771
- const updatePickerAndEditor = ( value : string ) => {
780
+ const toFindMatchIndex = ( value : string ) : number | undefined => {
772
781
const index = parseInt ( value ) ;
782
+ if ( isNaN ( index ) ) {
783
+ return undefined ;
784
+ }
785
+
786
+ const matchCount = controller . getState ( ) . matchesCount ;
787
+ if ( index > 0 && index <= matchCount ) {
788
+ return index - 1 ; // zero based
789
+ } else if ( index < 0 && index >= - matchCount ) {
790
+ return matchCount + index ;
791
+ }
773
792
774
- if ( ! isNaN ( index ) && index > 0 && index <= controller . getState ( ) . matchesCount ) {
793
+ return undefined ;
794
+ } ;
795
+
796
+ const updatePickerAndEditor = ( value : string ) => {
797
+ const index = toFindMatchIndex ( value ) ;
798
+ if ( typeof index === 'number' ) {
775
799
// valid
776
800
inputBox . validationMessage = undefined ;
777
- controller . goToMatch ( index - 1 ) ;
801
+ controller . goToMatch ( index ) ;
778
802
const currentMatch = controller . getState ( ) . currentMatch ;
779
803
if ( currentMatch ) {
780
804
this . addDecorations ( editor , currentMatch ) ;
@@ -789,9 +813,9 @@ export class MoveToMatchFindAction extends EditorAction {
789
813
} ) ;
790
814
791
815
inputBox . onDidAccept ( ( ) => {
792
- const index = parseInt ( inputBox . value ) ;
793
- if ( ! isNaN ( index ) && index > 0 && index <= controller . getState ( ) . matchesCount ) {
794
- controller . goToMatch ( index - 1 ) ;
816
+ const index = toFindMatchIndex ( inputBox . value ) ;
817
+ if ( typeof index === 'number' ) {
818
+ controller . goToMatch ( index ) ;
795
819
inputBox . hide ( ) ;
796
820
} else {
797
821
inputBox . validationMessage = nls . localize ( 'findMatchAction.inputValidationMessage' , "Please type a number between 1 and {0}" , controller . getState ( ) . matchesCount ) ;
0 commit comments