diff --git a/app/client.imba b/app/client.imba index 7b7070d..988946d 100644 --- a/app/client.imba +++ b/app/client.imba @@ -32,6 +32,7 @@ tag app fatal_error = no bang = no holding_shift = no + editing_link = no get render? do mounted? @@ -225,11 +226,13 @@ tag app link_text def handle_edit link + editing_link = link + state.query = construct_link_text(link) + + def make_edit link, new_link_text def edit_link - let input = window.prompt "Enter the new link name and url:", construct_link_text(link) - return if input is null try - await update_link link, input + await update_link link, new_link_text catch e return err "editing link", e loading = yes @@ -281,12 +284,12 @@ tag app sort_links! def handle_click_delete link + return unless window.confirm "Do you really want to delete {link..display_name}?" handle_delete link def handle_delete link def delete_link - return unless window.confirm "Do you really want to delete {link..display_name}?" try await db.links.delete(link.id) catch e @@ -322,11 +325,31 @@ tag app window.alert "{link.display_name} is now the default bang" def handle_shift_backspace - return unless state.scored_links.length > 0 - handle_edit state.scored_links[selection_index] + if editing_link + await handle_delete editing_link + editing_link = no + state.query = '' + sort_links! + else + return unless state.scored_links.length > 0 + handle_edit state.scored_links[selection_index] def handle_shift_return - handle_add! + if editing_link + try + await update_link editing_link, state.query + editing_link = no + state.query = '' + sort_links! + catch e + err "updating link", e + else + handle_add! + + def handle_esc + editing_link = no + state.query = '' + sort_links! def handle_click_add handle_add! @@ -617,6 +640,7 @@ tag app # placeholder=pretty_date @hotkey('return').capture=handle_return @hotkey('shift+return').capture.if(can_add)=handle_shift_return + @hotkey('esc').capture=handle_esc @hotkey('shift+backspace').capture=handle_shift_backspace @hotkey('down').capture=increment_selection_index @hotkey('up').capture=decrement_selection_index @@ -632,81 +656,105 @@ tag app if config.enable_tips and not config.enable_simplify_ui - <.middle-button> - <.tip[jc:start ta:left fl:1] @click=handle_return> - <.tip-hotkey> "Return" - <.tip-content> "Navigate To Link" - <.tip[jc:center ta:center fl:2 px:15px] - @click=handle_shift_return - > - <.tip-hotkey> "Shift + Return" - <.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]> - "Add New Link" - " " - let sq = state.query.trim!.split /\s+/ - if sq.length >= 2 - let url = sq.pop! - '"' - sq.join ' ' - ' ' - url - '"' - else - '"' - sq.join ' ' - '"' - <.tip[jc:end ta:right fl:1] - @click=handle_shift_backspace - > - <.tip-hotkey> "Shift + Backspace" - <.tip-content> "Edit Link" - - <.links> - if bang or state.scored_links.length < 1 - - <.link-left> - - <.display-name.bang-text> encoded_bang_query - <.link-right[jc:flex-end]> - <.frequency> active_bang.frequency + if editing_link + <.middle-button> + + <.tip[jc:start ta:left fl:1] + @click=handle_esc + > + <.tip-hotkey> "Esc" + <.tip-content> "Cancel Edits" + + <.tip[jc:center ta:center fl:1 px:15px] + @click=handle_shift_return + > + <.tip-hotkey> "Shift + Return" + <.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]> + "Update Link" + + <.tip[jc:end ta:right fl:1] + @click=handle_shift_backspace + > + <.tip-hotkey> "Shift + Backspace" + <.tip-content> "Delete Link" + else - for link, index in state.scored_links - + <.tip[jc:start ta:left fl:1] @click=handle_return> + <.tip-hotkey> "Return" + <.tip-content> "Navigate To Link" + <.tip[jc:center ta:center fl:2 px:15px] + @click=handle_shift_return + > + <.tip-hotkey> "Shift + Return" + <.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]> + "Add New Link" + " " + let sq = state.query.trim!.split /\s+/ + if sq.length >= 2 + let url = sq.pop! + '"' + sq.join ' ' + ' ' + url + '"' + else + '"' + sq.join ' ' + '"' + <.tip[jc:end ta:right fl:1] + @click=handle_shift_backspace + > + <.tip-hotkey> "Shift + Backspace" + <.tip-content> "Edit Link" + + unless editing_link + <.links> + if bang or state.scored_links.length < 1 + <.link-left> - - <.display-name - [c:#FAD4AB]=link.is_bang - > link.display_name - if link.display_name isnt link.name and config.enable_effective_names - <.name> - "(" - link.name - ")" - <.link-right> - <.link-buttons .buttons-disabled=(not config.enable_buttons or config.enable_simplify_ui)> - <.link-button - @click.if(link.is_bang).prevent.stop=handle_click_make_default_bang(link) - [visibility:hidden]=!link.is_bang - > - - <.link-button@click.prevent.stop=handle_click_edit(link)> - - <.link-button@click.prevent.stop=handle_click_delete(link)> - - <.link-button - @click.prevent.stop=handle_click_pin(link) - [visibility:visible c:purple3/50]=(link.is_pinned and (index isnt selection_index or not config.enable_buttons or config.enable_simplify_ui)) - > - - <.frequency> link.frequency + + <.display-name.bang-text> encoded_bang_query + <.link-right[jc:flex-end]> + <.frequency> active_bang.frequency + else + for link, index in state.scored_links + + <.link-left> + + <.display-name + [c:#FAD4AB]=link.is_bang + > link.display_name + if link.display_name isnt link.name and config.enable_effective_names + <.name> + "(" + link.name + ")" + <.link-right> + <.link-buttons .buttons-disabled=(not config.enable_buttons or config.enable_simplify_ui)> + <.link-button + @click.if(link.is_bang).prevent.stop=handle_click_make_default_bang(link) + [visibility:hidden]=!link.is_bang + > + + <.link-button@click.prevent.stop=handle_click_edit(link)> + + <.link-button@click.prevent.stop=handle_click_delete(link)> + + <.link-button + @click.prevent.stop=handle_click_pin(link) + [visibility:visible c:purple3/50]=(link.is_pinned and (index isnt selection_index or not config.enable_buttons or config.enable_simplify_ui)) + > + + <.frequency> link.frequency $main-input.focus! imba.mount