Compare commits

...

2 Commits

  1. 24
      src/api.imba
  2. 9
      src/components/app-home.imba
  3. 20
      src/components/app-links.imba

24
src/api.imba

@ -99,11 +99,6 @@ export default new class api
let i = set_link_selection_index Math.max(-1, state.link_selection_index - 1) let i = set_link_selection_index Math.max(-1, state.link_selection_index - 1)
#link_input.focus! if i == -1 #link_input.focus! if i == -1
def navigate link
await increment_link_frequency link
#home_input.value = ""
new_tab link.url
get math_result get math_result
try try
mexp.eval(state.query) mexp.eval(state.query)
@ -126,6 +121,10 @@ export default new class api
else else
navigate link navigate link
def handle_input
set_link_selection_index 0
sort_links!
get bang get bang
state.active_bang or config.data.default_bang state.active_bang or config.data.default_bang
@ -135,10 +134,18 @@ export default new class api
get encoded_bang_query_nourl get encoded_bang_query_nourl
"{window.encodeURIComponent(state.query)}" "{window.encodeURIComponent(state.query)}"
def new_tab(url)
window.open url,'_blank'
def navigate link, link_url
await increment_link_frequency link
state.query = ""
handle_input!
new_tab link_url || link.url
def handle_bang def handle_bang
return if state.loading return if state.loading
await increment_link_frequency bang navigate bang, encoded_bang_query
new_tab encoded_bang_query
def unset_active_bang def unset_active_bang
state.active_bang = no state.active_bang = no
@ -150,6 +157,3 @@ export default new class api
def help def help
new_tab "https://github.com/familyfriendlymikey/fuzzyhome" new_tab "https://github.com/familyfriendlymikey/fuzzyhome"
def new_tab(url)
window.open url,'_blank'

9
src/components/app-home.imba

@ -4,6 +4,7 @@ tag app-home
$home-input.focus! $home-input.focus!
api.#home_input = $home-input api.#home_input = $home-input
api.#link_input = $link-input-url api.#link_input = $link-input-url
api.#link_title = $link-input-title
def blur def blur
setTimeout(&, 100) do setTimeout(&, 100) do
@ -39,10 +40,6 @@ tag app-home
state.query = '' state.query = ''
api.sort_links! api.sort_links!
def handle_input
api.set_link_selection_index 0
api.sort_links!
<self> <self>
css w:100% d:flex fld:column ofy:hidden gap:20px css w:100% d:flex fld:column ofy:hidden gap:20px
unless state.active_bang unless state.active_bang
@ -57,7 +54,7 @@ tag app-home
bg:$input-bg c:$text-c bg:$input-bg c:$text-c
caret-color:$input-caret-c caret-color:$input-caret-c
<[c:$button-c] @click=delete_link!> "⨯" <[c:$button-c] @click=delete_link!> "⨯"
<input$link-input-title[ml:17px bdr:0 rdr:0] <input$link-input-title[ml:17px bdr:0 rdr:0 w:200px]
disabled=state.loading disabled=state.loading
@blur=blur @blur=blur
placeholder="title" placeholder="title"
@ -96,7 +93,7 @@ tag app-home
<input$home-input <input$home-input
autofocus autofocus
bind=state.query bind=state.query
@input=handle_input @input=api.handle_input
@cut=api.handle_cut @cut=api.handle_cut
disabled=state.loading disabled=state.loading
@blur=blur @blur=blur

20
src/components/app-links.imba

@ -10,7 +10,7 @@ tag app-links
hotkey: 'return' hotkey: 'return'
hotkey_display_name: 'Return' hotkey_display_name: 'Return'
} }
temp.content = api.selected_link.is_bang ? "Use Bang" : "Navigate To Link" temp.content = api.selected_link.is_bang ? "Use Bang" : [api.#link_input, api.#link_title].includes(document.activeElement) ? state.link_selection_index == -1 ? "Add New Link" : "Edit Link" : "Navigate To Link"
result.push temp result.push temp
temp = { temp = {
@ -42,12 +42,18 @@ tag app-links
} }
result.push temp result.push temp
temp = { let content = switch document.activeElement
click_handler: do api.#link_input.focus! when this.api.#link_title then ""
hotkey_display_name: "Shift+Tab" when this.api.#link_input then "Edit title"
content: "Edit Link" else "Edit link"
}
result.push temp if content
temp = {
click_handler: do api.#link_input.focus!
hotkey_display_name: "Shift+Tab"
content
}
result.push temp
result result

Loading…
Cancel
Save