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 do not hide on electron #725

Merged
merged 1 commit into from
Mar 25, 2022
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
12 changes: 4 additions & 8 deletions packages/quick-open/src/browser/quick-open.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const QuickOpenHeader = observer(() => {
[quickTitleBar.fireDidTriggerButton],
);

return quickTitleBar.isAttached ? (
return quickTitleBar.isAttached && titleText ? (
<div className={styles.title_bar}>
<div className={styles.title_bar_button}>
{quickTitleBar.leftButtons.map((button) => (
Expand Down Expand Up @@ -230,7 +230,8 @@ const QuickOpenItemView: React.FC<IQuickOpenItemProps> = observer(({ data, index
onChange={(event) => (data.checked = (event.target as HTMLInputElement).checked)}
/>
)}
<div className={styles.item_label_container} onMouseDown={runQuickOpenItem}>
{/* tabIndex is needed here, pls see https://stackoverflow.com/questions/42764494/blur-event-relatedtarget-returns-null */}
<div tabIndex={0} className={styles.item_label_container} onMouseDown={runQuickOpenItem}>
<div className={styles.item_label}>
{iconClass && <span className={clx(styles.item_icon, iconClass)}></span>}
<HighlightLabel
Expand Down Expand Up @@ -327,12 +328,7 @@ export const QuickOpenView = observer(() => {

const onBlur = React.useCallback(
(event: React.FocusEvent) => {
// 要判断 nativeEvent,不然可能在 React 重绘时导致判断会出错
// 目前遇到的一个 case 是:
// GoToLineQuickOpenHandler:
// 按 enter 后 hide 面板,但不知道为什么这里的 onBlur 也会生效,导致二次触发 onClose
// 这里改成 nativeEvent 后不再有该问题
if (focusInCurrentTarget(event.nativeEvent)) {
if (focusInCurrentTarget(event)) {
// 判断触发事件的元素是否在父元素内,如果在父元素内就不做处理
return;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/quick-open/src/browser/quickInput.inputBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class InputBoxImpl {

open() {
let preLookFor = '';
let triggeredInput = false;

this.quickTitleBar.onDidTriggerButton((e) => {
this.onDidTriggerButtonEmitter.fire((e as unknown as { handler: number }).handler);
});
Expand All @@ -67,9 +69,11 @@ export class InputBoxImpl {
this.options.buttons,
);
}

if (preLookFor !== lookFor) {
this.onDidChangeValueEmitter.fire(lookFor);
preLookFor = lookFor;
triggeredInput = true;
}

const error = this.options.validationMessage;
Expand All @@ -82,6 +86,10 @@ export class InputBoxImpl {
label = error || label;
const itemOptions: QuickOpenItemOptions = {
run: (mode) => {
// 如果用户打开输入框后没有任何输入,不允许 accept
if (!triggeredInput) {
return false;
}
if (!error && mode === Mode.OPEN) {
this.onDidAcceptEmitter.fire(lookFor);
this.quickTitleBar.hide();
Expand All @@ -92,6 +100,7 @@ export class InputBoxImpl {
};

if (label) {
// 用 detail 展示默认提示信息
itemOptions.label = label;
itemOptions.detail = defaultPrompt;
} else {
Expand Down