From 8fa4d1b941acd842f0588a079b38bdec78ce2985 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 22 Mar 2018 01:32:04 +0100 Subject: [PATCH] Re-activate search when pressing Enter --- scripts/Actions/Search.ts | 8 ++++---- scripts/AnimeNotifier.ts | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/Actions/Search.ts b/scripts/Actions/Search.ts index 1ddec65f..fc1bda6d 100644 --- a/scripts/Actions/Search.ts +++ b/scripts/Actions/Search.ts @@ -30,18 +30,18 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: Ke return } + // Determine if we're already seeing the search page + let searchPageActivated = (searchPage === arn.app.content.children[0]) + // Check if the search term really changed let term = search.value.trim() - if(term === oldTerm) { + if(term === oldTerm && searchPageActivated) { return } oldTerm = term - // Determine if we're already seeing the search page - let searchPageActivated = (searchPage === arn.app.content.children[0]) - // Reset correctResponseRendered.anime = false correctResponseRendered.character = false diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index d59f5309..4f4e0300 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -12,7 +12,7 @@ import { ServiceWorkerManager } from "./ServiceWorkerManager" import { displayAiringDate, displayDate, displayTime } from "./DateView" import { findAll, delay, canUseWebP, swapElements } from "./Utils" import * as actions from "./Actions" -import { darkTheme, addSpeed, playPreviousTrack } from "./Actions"; +import { darkTheme, addSpeed, playPreviousTrack, search } from "./Actions"; import { playPauseAudio, playNextTrack } from "./Actions/Audio" export class AnimeNotifier { @@ -880,6 +880,13 @@ export class AnimeNotifier { // Ignore hotkeys on input elements switch(activeElement.tagName) { case "INPUT": + // + if(activeElement.id === "search" && e.keyCode === 13) { + search(this, activeElement as HTMLInputElement, e) + } + + return + case "TEXTAREA": return } @@ -887,7 +894,7 @@ export class AnimeNotifier { // Ignore hotkeys on contentEditable elements if(activeElement.getAttribute("contenteditable") === "true") { // Disallow Enter key in contenteditables and make it blur the element instead - if(e.keyCode == 13) { + if(e.keyCode === 13) { if("blur" in activeElement) { activeElement["blur"]() } @@ -900,7 +907,7 @@ export class AnimeNotifier { } // "Ctrl" + "," = Settings - if(e.ctrlKey && e.keyCode == 188) { + if(e.ctrlKey && e.keyCode === 188) { this.app.load("/settings") e.preventDefault() @@ -914,7 +921,7 @@ export class AnimeNotifier { } // "F" = Search - if(e.keyCode == 70) { + if(e.keyCode === 70) { let search = this.app.find("search") as HTMLInputElement search.focus() @@ -926,7 +933,7 @@ export class AnimeNotifier { } // "S" = Toggle sidebar - if(e.keyCode == 83) { + if(e.keyCode === 83) { this.sideBar.toggle() e.preventDefault() @@ -935,7 +942,7 @@ export class AnimeNotifier { } // "+" = Audio speed up - if(e.keyCode == 107 || e.keyCode == 187) { + if(e.keyCode === 107 || e.keyCode === 187) { addSpeed(this, 0.05) e.preventDefault() @@ -944,7 +951,7 @@ export class AnimeNotifier { } // "-" = Audio speed down - if(e.keyCode == 109 || e.keyCode == 189) { + if(e.keyCode === 109 || e.keyCode === 189) { addSpeed(this, -0.05) e.preventDefault() @@ -953,7 +960,7 @@ export class AnimeNotifier { } // "J" = Previous track - if(e.keyCode == 74) { + if(e.keyCode === 74) { playPreviousTrack(this) e.preventDefault() @@ -962,7 +969,7 @@ export class AnimeNotifier { } // "K" = Play/pause - if(e.keyCode == 75) { + if(e.keyCode === 75) { playPauseAudio(this) e.preventDefault() @@ -971,7 +978,7 @@ export class AnimeNotifier { } // "L" = Next track - if(e.keyCode == 76) { + if(e.keyCode === 76) { playNextTrack(this) e.preventDefault()