From 6bedb6990961f38a75ec8b74d7d4c847a910361c Mon Sep 17 00:00:00 2001
From: itdominator <1itdominator@gmail.com>
Date: Sun, 23 Nov 2025 00:49:44 -0600
Subject: [PATCH] Improved search-replace component logic by disabing buttons
when no query; displaying found/not found status; displaying too long query;
adding ctrl-up and down key bindig on query field to god prev-next instance
found
---
list.m3u8 | 0
.../search-replace.component.html | 50 +++++++++++++--
.../search-replace.component.ts | 64 +++++++++++--------
3 files changed, 82 insertions(+), 32 deletions(-)
create mode 100644 list.m3u8
diff --git a/list.m3u8 b/list.m3u8
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/editor/search-replace/search-replace.component.html b/src/app/editor/search-replace/search-replace.component.html
index 4b15e67..8010a30 100644
--- a/src/app/editor/search-replace/search-replace.component.html
+++ b/src/app/editor/search-replace/search-replace.component.html
@@ -1,7 +1,21 @@
- Find in Current File
+ @if (isQueryLong) {
+
+ Query exceeds 80 characters...
+
+ } @else if (isQueryNotFound) {
+
+ Query not found...
+
+ } @else if (query && !isQueryLong && !isQueryNotFound) {
+ Found in current file:
+ {{totalCount}}
+
+ } @else {
+ Find in Current File:
+ }
@@ -45,15 +59,27 @@
id="find-entry"
class="form-control"
type="search"
- (keyup)="searchForString()"
+ (focus)="searchForString()"
+ (keyup)="findEntryKeyUpHandler($event)"
+ (input)="searchForString()"
placeholder="Find in current file..."
aria-label="Find in current file..."
/>
- Find
- Find All
+ Find
+
+ Find All
+
@@ -68,15 +94,25 @@
id="replace-entry"
class="form-control"
type="search"
- (keyup)="replaceEntry($event)"
+ (keyup.enter)="replaceEntry($event)"
title="Replace in current file..."
placeholder="Replace in current file..."
/>
- Replace
- Replace All
+ Replace
+
+ Replace All
+
diff --git a/src/app/editor/search-replace/search-replace.component.ts b/src/app/editor/search-replace/search-replace.component.ts
index 4d9867d..34571e4 100644
--- a/src/app/editor/search-replace/search-replace.component.ts
+++ b/src/app/editor/search-replace/search-replace.component.ts
@@ -36,15 +36,19 @@ export class SearchReplaceComponent {
@ViewChild('findEntryElm') findEntryElm!: ElementRef;
@ViewChild('replaceEntryElm') replaceEntryElm!: ElementRef;
+ @Input() query: string = "";
+ @Input() findOptions: string = "";
+ @Input() isQueryLong: boolean = false;
+ @Input() isQueryNotFound: boolean = false;
+ @Input() totalCount: number = 0;
+
private editor!: any;
- @Input() findOptions: string = "";
private useWholeWordSearch: boolean = false;
private searchOnlyInSelection: boolean = false;
private useCaseSensitive: boolean = false;
private useRegex: boolean = false;
private selection: string = "";
- private query: string = "";
private toStr: string = "";
private isBackwards: boolean = false;
private isWrap: boolean = true;
@@ -179,17 +183,25 @@ export class SearchReplaceComponent {
this.findOptions = findOptionsStr;
}
+ public findPreviousEntry() {
+ this.editor.findPrevious();
+ }
public findNextEntry() {
this.editor.findNext();
}
+ public findEntryKeyUpHandler(event: KeyboardEvent) {
+ if (!event.ctrlKey || !this.query) return;
+
+ if (event.key === "ArrowUp") this.findPreviousEntry();
+ if (event.key === "ArrowDown") this.findNextEntry();
+ }
+
public findAllEntries() {
this.query = this.findEntryElm.nativeElement.value;
- if (!this.query) return;
-
- let totalCount = this.editor.findAll(this.query, {
+ this.totalCount = this.editor.findAll(this.query, {
backwards: this.isBackwards,
wrap: this.isWrap,
caseSensitive: this.useCaseSensitive,
@@ -197,25 +209,19 @@ export class SearchReplaceComponent {
regExp: this.useRegex,
range: this.searchOnlyInSelection
});
+
+ if (this.totalCount === 0) this.isQueryNotFound = true;
}
- public findPreviousEntry() {
- this.editor.findPrevious();
- }
-
- public replaceEntry(event: any) {
- if (event instanceof KeyboardEvent) {
- if (event.key !== "Enter") {
- return;
- }
- }
+ public replaceEntry(event: KeyboardEvent) {
+ if (this.isQueryLong || this.isQueryNotFound) return;
let fromStr = this.findEntryElm.nativeElement.value;
let toStr = this.replaceEntryElm.nativeElement.value;
if (!fromStr) return;
- let totalCount = this.editor.replace(toStr, fromStr, {
+ this.editor.replace(toStr, fromStr, {
backwards: this.isBackwards,
wrap: this.isWrap,
caseSensitive: this.useCaseSensitive,
@@ -229,12 +235,14 @@ export class SearchReplaceComponent {
}
public replaceAll() {
+ if (this.isQueryLong || this.isQueryNotFound) return;
+
let fromStr = this.findEntryElm.nativeElement.value;
let toStr = this.replaceEntryElm.nativeElement.value;
if (!fromStr) return;
- let totalCount = this.editor.replaceAll(toStr, fromStr, {
+ this.editor.replaceAll(toStr, fromStr, {
backwards: this.isBackwards,
wrap: this.isWrap,
caseSensitive: this.useCaseSensitive,
@@ -242,23 +250,27 @@ export class SearchReplaceComponent {
regExp: this.useRegex,
range: this.searchOnlyInSelection
});
+
+ this.isQueryNotFound = true;
}
public searchForString() {
- if (event instanceof KeyboardEvent) {
- if (event.key !== "Enter") {
- return;
- }
- }
+ if (this.searchTimeoutId) { clearTimeout(this.searchTimeoutId); }
this.query = this.findEntryElm.nativeElement.value;
- if (!this.query) return;
+ if (!this.query) {
+ this.isQueryLong = false;
+ this.isQueryNotFound = false;
- if (this.searchTimeoutId) { clearTimeout(this.searchTimeoutId); }
+ return;
+ }
+
+ this.isQueryLong = (this.query.length > 80);
+ if (this.isQueryLong) return;
this.searchTimeoutId = setTimeout(() => {
- let totalCount = this.editor.find(this.query, {
+ this.totalCount = this.editor.findAll(this.query, {
backwards: this.isBackwards,
wrap: this.isWrap,
caseSensitive: this.useCaseSensitive,
@@ -266,6 +278,8 @@ export class SearchReplaceComponent {
regExp: this.useRegex,
range: this.searchOnlyInSelection
});
+
+ this.isQueryNotFound = (this.totalCount === 0);
}, this.searchTimeout);
}