mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix some more grammer
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
401db6ee54
commit
4879d62533
@ -19,25 +19,28 @@ export class SearchStore {
|
|||||||
* @param query Search query from input
|
* @param query Search query from input
|
||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
onSearch(text: string[], query = this.searchQuery) {
|
onSearch(text: string[], query = this.searchQuery): void {
|
||||||
this.searchQuery = query;
|
this.searchQuery = query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
this.reset();
|
return this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.occurrences = this.findOccurrences(text, query);
|
||||||
|
|
||||||
|
if (!this.occurrences.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.occurrences = this.findOccurrences(text, query);
|
|
||||||
if (!this.occurrences.length) return;
|
|
||||||
|
|
||||||
// If new highlighted keyword in exact same place as previous one, then no changing in active overlay
|
// If new highlighted keyword in exact same place as previous one, then no changing in active overlay
|
||||||
if (this.occurrences[this.activeOverlayIndex] !== undefined) return;
|
if (this.occurrences[this.activeOverlayIndex] === undefined) {
|
||||||
this.activeOverlayIndex = this.getNextOverlay(true);
|
this.activeOverlayIndex = this.getNextOverlay(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does searching within text array, create a list of search keyword occurrences.
|
* Does searching within text array, create a list of search keyword occurrences.
|
||||||
* Each keyword "occurrence" is saved as index of the the line where keyword founded
|
* Each keyword "occurrence" is saved as index of the the line where keyword was found
|
||||||
* @param text An array of any textual data (logs, for example)
|
* @param text An array of any textual data (logs, for example)
|
||||||
* @param query Search query from input
|
* @param query Search query from input
|
||||||
* @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
* @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
||||||
@ -59,9 +62,9 @@ export class SearchStore {
|
|||||||
/**
|
/**
|
||||||
* Getting next overlay index within the occurrences array
|
* Getting next overlay index within the occurrences array
|
||||||
* @param loopOver Allows to jump from last element to first
|
* @param loopOver Allows to jump from last element to first
|
||||||
* @returns {number} next overlay index
|
* @returns next overlay index
|
||||||
*/
|
*/
|
||||||
getNextOverlay(loopOver = false) {
|
getNextOverlay(loopOver = false): number {
|
||||||
const next = this.activeOverlayIndex + 1;
|
const next = this.activeOverlayIndex + 1;
|
||||||
|
|
||||||
if (next > this.occurrences.length - 1) {
|
if (next > this.occurrences.length - 1) {
|
||||||
@ -87,18 +90,18 @@ export class SearchStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
setNextOverlayActive() {
|
setNextOverlayActive(): void {
|
||||||
this.activeOverlayIndex = this.getNextOverlay(true);
|
this.activeOverlayIndex = this.getNextOverlay(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
setPrevOverlayActive() {
|
setPrevOverlayActive(): void {
|
||||||
this.activeOverlayIndex = this.getPrevOverlay(true);
|
this.activeOverlayIndex = this.getPrevOverlay(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets line index of where active overlay is located
|
* Gets line index of where active overlay is located
|
||||||
* @returns {number} A line index within the text/logs array
|
* @returns A line index within the text/logs array
|
||||||
*/
|
*/
|
||||||
@computed get activeOverlayLine(): number {
|
@computed get activeOverlayLine(): number {
|
||||||
return this.occurrences[this.activeOverlayIndex];
|
return this.occurrences[this.activeOverlayIndex];
|
||||||
@ -118,7 +121,7 @@ export class SearchStore {
|
|||||||
* @param occurrence Number of the overlay within one line
|
* @param occurrence Number of the overlay within one line
|
||||||
*/
|
*/
|
||||||
@autobind()
|
@autobind()
|
||||||
isActiveOverlay(line: number, occurrence: number) {
|
isActiveOverlay(line: number, occurrence: number): boolean {
|
||||||
const firstLineIndex = this.occurrences.findIndex(item => item === line);
|
const firstLineIndex = this.occurrences.findIndex(item => item === line);
|
||||||
|
|
||||||
return firstLineIndex + occurrence === this.activeOverlayIndex;
|
return firstLineIndex + occurrence === this.activeOverlayIndex;
|
||||||
@ -128,12 +131,12 @@ export class SearchStore {
|
|||||||
* An utility methods escaping user string to safely pass it into new Regex(variable)
|
* An utility methods escaping user string to safely pass it into new Regex(variable)
|
||||||
* @param value Unescaped string
|
* @param value Unescaped string
|
||||||
*/
|
*/
|
||||||
escapeRegex(value: string) {
|
escapeRegex(value: string): string {
|
||||||
return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
|
return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
reset() {
|
reset(): void {
|
||||||
this.searchQuery = "";
|
this.searchQuery = "";
|
||||||
this.activeOverlayIndex = -1;
|
this.activeOverlayIndex = -1;
|
||||||
this.occurrences = [];
|
this.occurrences = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user