mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix spelling
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1b0f56f417
commit
401db6ee54
@ -29,28 +29,28 @@ describe("search store tests", () => {
|
|||||||
expect(searchStore.occurrences).toEqual([]);
|
expect(searchStore.occurrences).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("find 3 occurences across 3 lines", () => {
|
it("find 3 occurrences across 3 lines", () => {
|
||||||
searchStore.onSearch(logs, "172");
|
searchStore.onSearch(logs, "172");
|
||||||
expect(searchStore.occurrences).toEqual([0, 1, 2]);
|
expect(searchStore.occurrences).toEqual([0, 1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("find occurences within 1 line (case-insensitive)", () => {
|
it("find occurrences within 1 line (case-insensitive)", () => {
|
||||||
searchStore.onSearch(logs, "Starting");
|
searchStore.onSearch(logs, "Starting");
|
||||||
expect(searchStore.occurrences).toEqual([2, 2]);
|
expect(searchStore.occurrences).toEqual([2, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets overlay index equal to first occurence", () => {
|
it("sets overlay index equal to first occurrence", () => {
|
||||||
searchStore.onSearch(logs, "Replica");
|
searchStore.onSearch(logs, "Replica");
|
||||||
expect(searchStore.activeOverlayIndex).toBe(0);
|
expect(searchStore.activeOverlayIndex).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("set overlay index to next occurence", () => {
|
it("set overlay index to next occurrence", () => {
|
||||||
searchStore.onSearch(logs, "172");
|
searchStore.onSearch(logs, "172");
|
||||||
searchStore.setNextOverlayActive();
|
searchStore.setNextOverlayActive();
|
||||||
expect(searchStore.activeOverlayIndex).toBe(1);
|
expect(searchStore.activeOverlayIndex).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets overlay to last occurence", () => {
|
it("sets overlay to last occurrence", () => {
|
||||||
searchStore.onSearch(logs, "172");
|
searchStore.onSearch(logs, "172");
|
||||||
searchStore.setPrevOverlayActive();
|
searchStore.setPrevOverlayActive();
|
||||||
expect(searchStore.activeOverlayIndex).toBe(2);
|
expect(searchStore.activeOverlayIndex).toBe(2);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { autobind } from "../renderer/utils";
|
|||||||
export class SearchStore {
|
export class SearchStore {
|
||||||
@observable searchQuery = ""; // Text in the search input
|
@observable searchQuery = ""; // Text in the search input
|
||||||
@observable occurrences: number[] = []; // Array with line numbers, eg [0, 0, 10, 21, 21, 40...]
|
@observable occurrences: number[] = []; // Array with line numbers, eg [0, 0, 10, 21, 21, 40...]
|
||||||
@observable activeOverlayIndex = -1; // Index withing the occurences array. Showing where is activeOverlay currently located
|
@observable activeOverlayIndex = -1; // Index within the occurrences array. Showing where is activeOverlay currently located
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
reaction(() => dockStore.selectedTabId, () => {
|
reaction(() => dockStore.selectedTabId, () => {
|
||||||
@ -27,7 +27,7 @@ export class SearchStore {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.occurrences = this.findOccurences(text, query);
|
this.occurrences = this.findOccurrences(text, query);
|
||||||
if (!this.occurrences.length) return;
|
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
|
||||||
@ -36,28 +36,28 @@ export class SearchStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does searching within text array, create a list of search keyword occurences.
|
* Does searching within text array, create a list of search keyword occurrences.
|
||||||
* Each keyword "occurency" is saved as index of the the line where keyword founded
|
* Each keyword "occurrence" is saved as index of the the line where keyword founded
|
||||||
* @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} Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
* @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
||||||
*/
|
*/
|
||||||
findOccurences(text: string[], query: string) {
|
findOccurrences(text: string[], query: string): Array<number> {
|
||||||
if (!text) return [];
|
if (!text) return [];
|
||||||
const occurences: number[] = [];
|
const occurrences: number[] = [];
|
||||||
|
|
||||||
text.forEach((line, index) => {
|
text.forEach((line, index) => {
|
||||||
const regex = new RegExp(this.escapeRegex(query), "gi");
|
const regex = new RegExp(this.escapeRegex(query), "gi");
|
||||||
const matches = [...line.matchAll(regex)];
|
const matches = [...line.matchAll(regex)];
|
||||||
|
|
||||||
matches.forEach(() => occurences.push(index));
|
matches.forEach(() => occurrences.push(index));
|
||||||
});
|
});
|
||||||
|
|
||||||
return occurences;
|
return occurrences;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getting next overlay index within the occurences 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 {number} next overlay index
|
||||||
*/
|
*/
|
||||||
@ -72,11 +72,11 @@ export class SearchStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getting previous overlay index within the occurences array of occurences
|
* Getting previous overlay index within the occurrences array of occurrences
|
||||||
* @param loopOver Allows to jump from first element to last one
|
* @param loopOver Allows to jump from first element to last one
|
||||||
* @returns {number} prev overlay index
|
* @returns previous overlay index
|
||||||
*/
|
*/
|
||||||
getPrevOverlay(loopOver = false) {
|
getPrevOverlay(loopOver = false): number {
|
||||||
const prev = this.activeOverlayIndex - 1;
|
const prev = this.activeOverlayIndex - 1;
|
||||||
|
|
||||||
if (prev < 0) {
|
if (prev < 0) {
|
||||||
@ -115,13 +115,13 @@ export class SearchStore {
|
|||||||
/**
|
/**
|
||||||
* Checks if overlay is active (to highlight it with orange background usually)
|
* Checks if overlay is active (to highlight it with orange background usually)
|
||||||
* @param line Index of the line where overlay is located
|
* @param line Index of the line where overlay is located
|
||||||
* @param occurence Number of the overlay within one line
|
* @param occurrence Number of the overlay within one line
|
||||||
*/
|
*/
|
||||||
@autobind()
|
@autobind()
|
||||||
isActiveOverlay(line: number, occurence: number) {
|
isActiveOverlay(line: number, occurrence: number) {
|
||||||
const firstLineIndex = this.occurrences.findIndex(item => item === line);
|
const firstLineIndex = this.occurrences.findIndex(item => item === line);
|
||||||
|
|
||||||
return firstLineIndex + occurence === this.activeOverlayIndex;
|
return firstLineIndex + occurrence === this.activeOverlayIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user