Открыть боковую панель
Teknokomo
universo-react
Коммиты
c1afdb9b
Не подтверждена
Коммит
c1afdb9b
создал
Мар 05, 2024
по автору
JimmFly
Просмотр файлов
fix(core): unexpected line breaks (#6019)
владелец
ceec54b4
Изменения
1
Скрыть пробелы
Построчно
Рядом
packages/frontend/core/src/components/pure/cmdk/use-highlight.ts
Просмотр файла @
c1afdb9b
import
{
useMemo
}
from
'
react
'
;
function
*
highlightTextFragmentsGenerator
(
text
:
string
,
query
:
string
)
{
const
lowerCaseText
=
text
.
replace
(
/
\r?\n
|
\r
/g
,
''
).
toLowerCase
();
const
cleanedText
=
text
.
replace
(
/
\r?\n
|
\r
|
\t
/g
,
''
);
const
lowerCaseText
=
cleanedText
.
toLowerCase
();
query
=
query
.
toLowerCase
();
let
startIndex
=
lowerCaseText
.
indexOf
(
query
);
if
(
startIndex
!==
-
1
)
{
if
(
startIndex
>
0
)
{
yield
{
text
:
t
ext
.
substring
(
0
,
startIndex
),
highlight
:
false
};
yield
{
text
:
cleanedT
ext
.
substring
(
0
,
startIndex
),
highlight
:
false
};
}
yield
{
text
:
t
ext
.
substring
(
startIndex
,
startIndex
+
query
.
length
),
text
:
cleanedT
ext
.
substring
(
startIndex
,
startIndex
+
query
.
length
),
highlight
:
true
,
};
if
(
startIndex
+
query
.
length
<
t
ext
.
length
)
{
if
(
startIndex
+
query
.
length
<
cleanedT
ext
.
length
)
{
yield
{
text
:
t
ext
.
substring
(
startIndex
+
query
.
length
),
text
:
cleanedT
ext
.
substring
(
startIndex
+
query
.
length
),
highlight
:
false
,
};
}
}
else
{
startIndex
=
0
;
for
(
const
char
of
query
)
{
const
pos
=
t
ext
.
toLowerCase
().
indexOf
(
char
,
startIndex
);
const
pos
=
cleanedT
ext
.
toLowerCase
().
indexOf
(
char
,
startIndex
);
if
(
pos
!==
-
1
)
{
if
(
pos
>
startIndex
)
{
yield
{
text
:
t
ext
.
substring
(
startIndex
,
pos
),
text
:
cleanedT
ext
.
substring
(
startIndex
,
pos
),
highlight
:
false
,
};
}
yield
{
text
:
t
ext
.
substring
(
pos
,
pos
+
1
),
highlight
:
true
};
yield
{
text
:
cleanedT
ext
.
substring
(
pos
,
pos
+
1
),
highlight
:
true
};
startIndex
=
pos
+
1
;
}
}
if
(
startIndex
<
t
ext
.
length
)
{
yield
{
text
:
t
ext
.
substring
(
startIndex
),
highlight
:
false
};
if
(
startIndex
<
cleanedT
ext
.
length
)
{
yield
{
text
:
cleanedT
ext
.
substring
(
startIndex
),
highlight
:
false
};
}
}
}
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать