From 343ee5d2fc2c98a5a2f1a431a96769119080b959 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Fri, 24 Jun 2022 16:58:58 +1000
Subject: Use Ctrl-f to open search bar, and Ctrl-Shift-f to switch search-mode

---
 src/App.vue | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 5505b8b..22b1df3 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -760,11 +760,21 @@ export default defineComponent({
 		onKeyUp(evt: KeyboardEvent){
 			if (evt.key == 'Escape'){
 				this.resetMode();
-			} else if (evt.key == 'F' && evt.ctrlKey){ // On ctrl-shift-f
-				if (!this.searchOpen){
-					this.onSearchIconClick();
-				} else {
-					(this.$refs.searchModal as InstanceType<typeof SearchModal>).focusInput();
+			} else if (evt.key == 'f' && evt.ctrlKey){
+				// If no non-search modal is open, open/focus search bar
+				if (this.infoModalNodeName == null && !this.helpOpen && !this.settingsOpen){
+					evt.preventDefault();
+					if (!this.searchOpen){
+						this.onSearchIconClick();
+					} else {
+						(this.$refs.searchModal as InstanceType<typeof SearchModal>).focusInput();
+					}
+				}
+			} else if (evt.key == 'F' && evt.ctrlKey){
+				// If search bar is open, swap search mode
+				if (this.searchOpen){
+					this.uiOpts.jumpToSearchedNode = !this.uiOpts.jumpToSearchedNode;
+					this.onSettingsChg([], ['jumpToSearchedNode']);
 				}
 			}
 		},
@@ -886,12 +896,12 @@ export default defineComponent({
 	},
 	created(){
 		window.addEventListener('resize', this.onResize);
-		window.addEventListener('keyup', this.onKeyUp);
+		window.addEventListener('keydown', this.onKeyUp);
 		this.initTreeFromServer();
 	},
 	unmounted(){
 		window.removeEventListener('resize', this.onResize);
-		window.removeEventListener('keyup', this.onKeyUp);
+		window.removeEventListener('keydown', this.onKeyUp);
 	},
 	components: {
 		Tile, AncestryBar,
-- 
cgit v1.2.3

