From 7c27e6502037caf1aee3eb9e30b4e0572ce095a1 Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Wed, 29 Jan 2020 17:06:59 -0500
Subject: added custom narrative types. fixed scrolling ambiguity with
 stackviews.  can create metdata from stackingview

---
 src/client/views/ContextMenu.tsx | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'src/client/views/ContextMenu.tsx')

diff --git a/src/client/views/ContextMenu.tsx b/src/client/views/ContextMenu.tsx
index 937aff0d6..ac803d977 100644
--- a/src/client/views/ContextMenu.tsx
+++ b/src/client/views/ContextMenu.tsx
@@ -77,8 +77,13 @@ export class ContextMenu extends React.Component {
     @action
     clearItems() {
         this._items = [];
+        this._defaultPrefix = "";
+        this._defaultItem = undefined;
     }
 
+    _defaultPrefix: string = "";
+    _defaultItem: ((name: string) => void) | undefined;
+
     findByDescription = (target: string, toLowerCase = false) => {
         return this._items.find(menuItem => {
             let reference = menuItem.description;
@@ -93,6 +98,11 @@ export class ContextMenu extends React.Component {
             this._items.push(item);
         }
     }
+    @action
+    setDefaultItem(prefix: string, item: (name: string) => void) {
+        this._defaultPrefix = prefix;
+        this._defaultItem = item;
+    }
 
     getItems() {
         return this._items;
@@ -248,7 +258,11 @@ export class ContextMenu extends React.Component {
             e.preventDefault();
         } else if (e.key === "Enter" || e.key === "Tab") {
             const item = this.flatItems[this.selectedIndex];
-            item && item.event({ x: this.pageX, y: this.pageY });
+            if (item) {
+                item.event({ x: this.pageX, y: this.pageY });
+            } else if (this._searchString.startsWith(this._defaultPrefix)) {
+                this._defaultItem?.(this._searchString.substring(this._defaultPrefix.length));
+            }
             this.closeMenu();
             e.preventDefault();
         }
-- 
cgit v1.2.3-70-g09d2

