mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-03 14:37:47 +00:00
CSS tweaks
This commit is contained in:
parent
d034ce71c3
commit
12ce2e6ed9
@ -12,12 +12,14 @@ import { unsafeHTML } from "lit-html/directives/unsafe-html";
|
|||||||
* @return {number} Score representing how well the word matches the filter. Return of 0 means no match.
|
* @return {number} Score representing how well the word matches the filter. Return of 0 means no match.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const fuzzySequentialMatch = (
|
type FuzzySequentialMatcher = (
|
||||||
filter: string,
|
filter: string,
|
||||||
item: ScorableTextItem
|
item: ScorableTextItem
|
||||||
) => {
|
) => ScorableTextItem | undefined;
|
||||||
|
|
||||||
|
export const fuzzySequentialMatch: FuzzySequentialMatcher = (filter, item) => {
|
||||||
let topScore = Number.NEGATIVE_INFINITY;
|
let topScore = Number.NEGATIVE_INFINITY;
|
||||||
const decoratedWords: TemplateResult[][] = [];
|
const decoratedStrings: TemplateResult[][] = [];
|
||||||
|
|
||||||
for (const word of item.strings) {
|
for (const word of item.strings) {
|
||||||
const scores = fuzzyScore(
|
const scores = fuzzyScore(
|
||||||
@ -30,7 +32,7 @@ export const fuzzySequentialMatch = (
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
decoratedWords.push(decorateMatch(word, scores));
|
decoratedStrings.push(decorateMatch(word, scores));
|
||||||
|
|
||||||
if (!scores) {
|
if (!scores) {
|
||||||
continue;
|
continue;
|
||||||
@ -53,7 +55,7 @@ export const fuzzySequentialMatch = (
|
|||||||
return {
|
return {
|
||||||
score: topScore,
|
score: topScore,
|
||||||
strings: item.strings,
|
strings: item.strings,
|
||||||
decoratedWords,
|
decoratedStrings,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ export const fuzzySequentialMatch = (
|
|||||||
export interface ScorableTextItem {
|
export interface ScorableTextItem {
|
||||||
score?: number;
|
score?: number;
|
||||||
strings: string[];
|
strings: string[];
|
||||||
decoratedWords?: TemplateResult[][];
|
decoratedStrings?: TemplateResult[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
type FuzzyFilterSort = <T extends ScorableTextItem>(
|
type FuzzyFilterSort = <T extends ScorableTextItem>(
|
||||||
@ -87,7 +89,7 @@ export const fuzzyFilterSort: FuzzyFilterSort = (filter, items) => {
|
|||||||
const match = fuzzySequentialMatch(filter, item);
|
const match = fuzzySequentialMatch(filter, item);
|
||||||
|
|
||||||
item.score = match?.score;
|
item.score = match?.score;
|
||||||
item.decoratedWords = match?.decoratedWords;
|
item.decoratedStrings = match?.decoratedStrings;
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
})
|
})
|
||||||
|
@ -258,7 +258,7 @@ export class QuickBar extends LitElement {
|
|||||||
class="entity"
|
class="entity"
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
></ha-icon>`}
|
></ha-icon>`}
|
||||||
<span
|
<span class="item-text primary"
|
||||||
>${item.decoratedWords
|
>${item.decoratedWords
|
||||||
? item.decoratedWords[0]
|
? item.decoratedWords[0]
|
||||||
: item.primaryText}</span
|
: item.primaryText}</span
|
||||||
@ -689,7 +689,9 @@ export class QuickBar extends LitElement {
|
|||||||
color: #0051ff;
|
color: #0051ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
span.command-text span.highlight-letter {
|
span.command-text span.highlight-letter,
|
||||||
|
span.item-text.secondary span.highlight-letter,
|
||||||
|
span.item-text.primary span.highlight-letter {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #0098ff;
|
color: #0098ff;
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,35 @@ import {
|
|||||||
ScorableTextItem,
|
ScorableTextItem,
|
||||||
} from "../../../src/common/string/filter/sequence-matching";
|
} from "../../../src/common/string/filter/sequence-matching";
|
||||||
|
|
||||||
|
type CreateExpectation = (
|
||||||
|
pattern: string,
|
||||||
|
score: ScorableTextItem["score"],
|
||||||
|
strings?: ScorableTextItem["strings"],
|
||||||
|
decoratedStrings?: ScorableTextItem["decoratedStrings"]
|
||||||
|
) => {
|
||||||
|
pattern: string;
|
||||||
|
expected: ScorableTextItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createExpectation: CreateExpectation = (
|
||||||
|
pattern,
|
||||||
|
score,
|
||||||
|
strings = [],
|
||||||
|
decoratedStrings = []
|
||||||
|
) => ({
|
||||||
|
pattern,
|
||||||
|
expected: {
|
||||||
|
score,
|
||||||
|
strings,
|
||||||
|
decoratedStrings,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
describe("fuzzySequentialMatch", () => {
|
describe("fuzzySequentialMatch", () => {
|
||||||
const item: ScorableTextItem = {
|
const item: ScorableTextItem = {
|
||||||
strings: ["automation.ticker", "Stocks"],
|
strings: ["automation.ticker", "Stocks"],
|
||||||
};
|
};
|
||||||
|
|
||||||
const createExpectation: (
|
|
||||||
pattern,
|
|
||||||
expected
|
|
||||||
) => {
|
|
||||||
pattern: string;
|
|
||||||
expected: string | number | undefined;
|
|
||||||
} = (pattern, expected) => ({
|
|
||||||
pattern,
|
|
||||||
expected,
|
|
||||||
});
|
|
||||||
|
|
||||||
const shouldMatchEntity = [
|
const shouldMatchEntity = [
|
||||||
createExpectation("automation.ticker", 131),
|
createExpectation("automation.ticker", 131),
|
||||||
createExpectation("automation.ticke", 121),
|
createExpectation("automation.ticke", 121),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user