fix(electron): optimize find in page in electron (2) (#9901)

1. find in page should have higher z-index than other modals
2. fix focused texts are not automatically being used as the default input value for searching
This commit is contained in:
pengx17
2025-01-27 07:58:16 +00:00
parent ffbec1633e
commit 4b549e0484
4 changed files with 14 additions and 16 deletions

View File

@@ -9,12 +9,12 @@ import { useCallback, useEffect } from 'react';
export function useRegisterFindInPageCommands() { export function useRegisterFindInPageCommands() {
const findInPage = useServiceOptional(FindInPageService)?.findInPage; const findInPage = useServiceOptional(FindInPageService)?.findInPage;
const toggleVisible = useCallback(() => { const showFindInPage = useCallback(() => {
// get the selected text in page // get the selected text in page
const selection = window.getSelection(); const selection = window.getSelection();
const selectedText = selection?.toString(); const selectedText = selection?.toString();
findInPage?.toggleVisible(selectedText); findInPage?.findInPage(selectedText);
}, [findInPage]); }, [findInPage]);
useEffect(() => { useEffect(() => {
@@ -33,8 +33,7 @@ export function useRegisterFindInPageCommands() {
label: '', label: '',
run() { run() {
track.$.cmdk.general.findInPage(); track.$.cmdk.general.findInPage();
showFindInPage();
toggleVisible();
}, },
}) })
); );
@@ -42,5 +41,5 @@ export function useRegisterFindInPageCommands() {
return () => { return () => {
unsubs.forEach(unsub => unsub()); unsubs.forEach(unsub => unsub());
}; };
}, [toggleVisible]); }, [findInPage, showFindInPage]);
} }

View File

@@ -46,7 +46,7 @@ export const contentContainer = style({
justifyContent: 'space-between', justifyContent: 'space-between',
border: `0.5px solid ${cssVar('borderColor')}`, border: `0.5px solid ${cssVar('borderColor')}`,
padding: '8px 12px 8px 8px', padding: '8px 12px 8px 8px',
zIndex: cssVar('zIndexModal'), zIndex: `calc(${cssVar('zIndexModal')} + 1)`,
willChange: 'transform, opacity', willChange: 'transform, opacity',
selectors: { selectors: {
'&[data-state=entered], &[data-state=entering]': { '&[data-state=entered], &[data-state=entering]': {

View File

@@ -19,7 +19,7 @@ import {
useRef, useRef,
useState, useState,
} from 'react'; } from 'react';
import { useTransition } from 'react-transition-state'; import { useTransitionState } from 'react-transition-state';
import * as styles from './find-in-page-popup.css'; import * as styles from './find-in-page-popup.css';
@@ -93,13 +93,14 @@ export const FindInPagePopup = () => {
const [scrollLeft, setScrollLeft] = useState(0); const [scrollLeft, setScrollLeft] = useState(0);
const [composing, setComposing] = useState(false); const [composing, setComposing] = useState(false);
const [{ status }, toggle] = useTransition({ const [{ status }, toggle] = useTransitionState({
timeout: animationTimeout, timeout: animationTimeout,
}); });
useEffect(() => { useEffect(() => {
toggle(visible); toggle(visible);
}, [visible]); setValue(findInPage.searchText$.value || '');
}, [findInPage.searchText$.value, toggle, visible]);
const handleValueChange = useCallback( const handleValueChange = useCallback(
(value: string) => { (value: string) => {
@@ -203,14 +204,10 @@ export const FindInPagePopup = () => {
data-state={status} data-state={status}
sideOffset={5} sideOffset={5}
side="left" side="left"
onFocusOutside={e => { onInteractOutside={e => {
// do not close the popup when focus outside (like focus in the editor) // do not close the popup when focus outside (like focus in the editor)
e.preventDefault(); e.preventDefault();
}} }}
onPointerDownOutside={e => {
// do not close the popup when clicking outside (like clicking at the sidebar)
e.preventDefault();
}}
> >
<div <div
className={clsx(styles.inputContainer, { className={clsx(styles.inputContainer, {

View File

@@ -75,9 +75,11 @@ export class FindInPage extends Entity {
// TODO(@Peng): hide on navigation // TODO(@Peng): hide on navigation
} }
findInPage(searchText: string) { findInPage(searchText?: string) {
this.onChangeVisible(true); this.onChangeVisible(true);
this.searchText$.next(searchText); if (searchText !== undefined) {
this.searchText$.next(searchText);
}
} }
onChangeVisible(visible: boolean) { onChangeVisible(visible: boolean) {