diff options
author | Isabelle Taylor <taylori@google.com> | 2019-05-20 09:11:14 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-05-20 09:11:14 +0000 |
commit | 7676d01d0f8b33e41aef6c0aed8b1b4486c1d6ae (patch) | |
tree | 2961d9ff7613627950d2b41bdf2a091d3dda6dcf | |
parent | 866576d9901991656dad980fafed49af38ec254e (diff) | |
parent | e2428b1f30fb003249f9a4bd3cf3339c0f777770 (diff) | |
download | perfetto-7676d01d0f8b33e41aef6c0aed8b1b4486c1d6ae.tar.gz |
Merge "perfetto-ui: Remove search"
-rw-r--r-- | ui/src/frontend/topbar.ts | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/ui/src/frontend/topbar.ts b/ui/src/frontend/topbar.ts index c7e2d5234..d40da7541 100644 --- a/ui/src/frontend/topbar.ts +++ b/ui/src/frontend/topbar.ts @@ -27,9 +27,21 @@ let numResults = 0; let mode: 'search'|'command' = 'search'; let omniboxValue = ''; -function clearOmniboxResults() { +function enterCommandMode() { + if (mode === 'search') { + mode = 'command'; + globals.rafScheduler.scheduleFullRedraw(); + } +} + +function clearOmniboxResults(e: Event) { globals.queryResults.delete(QUERY_ID); globals.dispatch(Actions.deleteQuery({queryId: QUERY_ID})); + const txt = (e.target as HTMLInputElement); + if (txt.value.length <= 0) { + mode = 'search'; + globals.rafScheduler.scheduleFullRedraw(); + } } function onKeyDown(e: Event) { @@ -44,23 +56,6 @@ function onKeyDown(e: Event) { } const txt = (e.target as HTMLInputElement); omniboxValue = txt.value; - if (key === ':' && txt.value === '') { - mode = 'command'; - globals.rafScheduler.scheduleFullRedraw(); - e.preventDefault(); - return; - } - if (key === 'Escape' && mode === 'command') { - txt.value = ''; - mode = 'search'; - globals.rafScheduler.scheduleFullRedraw(); - return; - } - if (key === 'Backspace' && txt.value.length === 0 && mode === 'command') { - mode = 'search'; - globals.rafScheduler.scheduleFullRedraw(); - return; - } } function onKeyUp(e: Event) { @@ -77,26 +72,26 @@ function onKeyUp(e: Event) { return; } if (txt.value.length <= 0 || key === 'Escape') { - clearOmniboxResults(); + globals.queryResults.delete(QUERY_ID); + globals.dispatch(Actions.deleteQuery({queryId: QUERY_ID})); + mode = 'search'; + txt.value = ''; + omniboxValue = txt.value; + txt.blur(); globals.rafScheduler.scheduleFullRedraw(); return; } - if (mode === 'search') { - const name = txt.value.replace(/'/g, '\\\'').replace(/[*]/g, '%'); - const query = `select str from strings where str like '%${name}%' limit 10`; - globals.dispatch( - Actions.executeQuery({engineId: '0', queryId: QUERY_ID, query})); - } if (mode === 'command' && key === 'Enter') { globals.dispatch(Actions.executeQuery( {engineId: '0', queryId: 'command', query: txt.value})); } } - class Omnibox implements m.ClassComponent { oncreate(vnode: m.VnodeDOM) { const txt = vnode.dom.querySelector('input') as HTMLInputElement; + txt.addEventListener('focus', enterCommandMode); + txt.addEventListener('click', enterCommandMode); txt.addEventListener('blur', clearOmniboxResults); txt.addEventListener('keydown', onKeyDown); txt.addEventListener('keyup', onKeyUp); @@ -130,8 +125,8 @@ class Omnibox implements m.ClassComponent { } } const placeholder = { - search: 'Search or type : to enter command mode', - command: 'e.g., select * from sched left join thread using(utid) limit 10' + search: 'Click to enter command mode', + command: 'e.g. select * from sched left join thread using(utid) limit 10' }; const commandMode = mode === 'command'; |