Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: quick open hightlight label whitespace #2265

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { strings } from '@opensumi/ide-core-common';

const { escape } = strings;

const labelWithIcons = (str: string) => parseLabel(escape(str)).reduce((pre: string | LabelPart, cur: LabelPart) => {
const labelWithIcons = (str: string, iconClassName?: string) =>
parseLabel(escape(str)).reduce((pre: string | LabelPart, cur: LabelPart) => {
if (!(typeof cur === 'string') && LabelIcon.is(cur)) {
return pre + `<span class='${getExternalIcon(cur.name)}'></span>`;
return pre + `<span class='${getExternalIcon(cur.name)} ${iconClassName || ''}'></span>`;
}
return pre + cur;
}, '');
Expand All @@ -18,6 +19,7 @@ export interface HighlightLabelProp {
highlights?: Highlight[];
className?: string;
labelClassName?: string;
labelIconClassName?: string;
hightLightClassName?: string;
OutElementType?: string;
}
Expand All @@ -27,6 +29,7 @@ export const HighlightLabel: React.FC<HighlightLabelProp> = ({
highlights = [],
className = '',
labelClassName = '',
labelIconClassName = '',
hightLightClassName = '',
OutElementType = 'span',
}) => {
Expand All @@ -40,17 +43,17 @@ export const HighlightLabel: React.FC<HighlightLabelProp> = ({
}
if (pos < highlight.start) {
const substring = text.substring(pos, highlight.start);
children.push(`<span class='${labelClassName}'>${labelWithIcons(substring)}</span>`);
children.push(`<span class='${labelClassName}'>${labelWithIcons(substring, labelIconClassName)}</span>`);
pos = highlight.end;
}
const substring = text.substring(highlight.start, highlight.end);
children.push(`<span class='${hightLightClassName}'>${labelWithIcons(substring)}</span>`);
children.push(`<span class='${hightLightClassName}'>${labelWithIcons(substring, labelIconClassName)}</span>`);
pos = highlight.end;
}

if (pos < text.length) {
const substring = text.substring(pos);
children.push(`<span class='${labelClassName}'>${labelWithIcons(substring)}</span>`);
children.push(`<span class='${labelClassName}'>${labelWithIcons(substring, labelIconClassName)}</span>`);
}
return children.join('');
}, [text, highlights]);
Expand Down
3 changes: 2 additions & 1 deletion packages/quick-open/src/browser/quick-open.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ const QuickOpenItemView: React.FC<IQuickOpenItemProps> = observer(({ data, index
{iconClass && <span className={clx(styles.item_icon, iconClass)}></span>}
<HighlightLabel
className={styles.item_label_name}
labelClassName={styles.label_icon_container}
hightLightClassName={clx(styles.item_label_highlight)}
text={label}
highlights={labelHighlights}
Expand All @@ -266,6 +265,7 @@ const QuickOpenItemView: React.FC<IQuickOpenItemProps> = observer(({ data, index
<HighlightLabel
className={styles.item_label_description}
labelClassName={clx(styles.label_icon_container, styles.item_label_description_label)}
labelIconClassName={styles.label_has_icon}
hightLightClassName={clx(styles.item_label_description_highlight)}
text={description}
highlights={descriptionHighlights}
Expand All @@ -277,6 +277,7 @@ const QuickOpenItemView: React.FC<IQuickOpenItemProps> = observer(({ data, index
OutElementType='div'
className={styles.item_label_detail}
labelClassName={clx(styles.label_icon_container, styles.item_label_description_label)}
labelIconClassName={styles.label_has_icon}
hightLightClassName={clx(styles.item_label_description_highlight)}
text={detail}
highlights={detailHighlights}
Expand Down
11 changes: 9 additions & 2 deletions packages/quick-open/src/browser/styles.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

.item_icon {
align-self: center;
margin-right: 8px;
margin-right: 6px;
}

.item_label_highlight {
Expand All @@ -110,8 +110,11 @@

.item_label_name,
.item_label_description,
.item_label_detail {
.item_label_detail,
.item_label_description_label,
.item_label_description_highlight {
display: flex;
white-space: pre;
}

.item_label_description_label {
Expand Down Expand Up @@ -157,6 +160,10 @@
align-items: center;
}

.label_has_icon {
vertical-align: middle;
}

.input {
display: flex;
margin: 4px 10px;
Expand Down