mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-25 16:09:42 +01:00
fix: clear decorations on search close
This commit is contained in:
@@ -140,10 +140,15 @@ export var SearchReplace = Extension.create({
|
||||
return true;
|
||||
};
|
||||
},
|
||||
endSearch: function () { return function () {
|
||||
_this.storage.isSearching = false;
|
||||
return true;
|
||||
}; },
|
||||
endSearch: function () {
|
||||
return function (_a) {
|
||||
var state = _a.state, dispatch = _a.dispatch;
|
||||
_this.storage.isSearching = false;
|
||||
_this.storage.searchTerm = "";
|
||||
updateView(state, dispatch);
|
||||
return true;
|
||||
};
|
||||
},
|
||||
search: function (term, options) {
|
||||
return function (_a) {
|
||||
var state = _a.state, dispatch = _a.dispatch;
|
||||
|
||||
@@ -40,7 +40,7 @@ export function SearchReplaceFloatingMenu(props) {
|
||||
var _c = __read(useState(false), 2), matchWholeWord = _c[0], setMatchWholeWord = _c[1];
|
||||
var _d = __read(useState(false), 2), enableRegex = _d[0], setEnableRegex = _d[1];
|
||||
var replaceText = useRef("");
|
||||
var searchText = useRef("");
|
||||
var searchInputRef = useRef();
|
||||
var search = useCallback(function (term) {
|
||||
editor.commands.search(term, {
|
||||
matchCase: matchCase,
|
||||
@@ -49,11 +49,21 @@ export function SearchReplaceFloatingMenu(props) {
|
||||
});
|
||||
}, [matchCase, enableRegex, matchWholeWord]);
|
||||
useEffect(function () {
|
||||
search(searchText.current);
|
||||
if (!searchInputRef.current)
|
||||
return;
|
||||
search(searchInputRef.current.value);
|
||||
}, [search, matchCase, matchWholeWord, enableRegex]);
|
||||
useEffect(function () {
|
||||
if (isSearching && selectedText)
|
||||
if (isSearching && selectedText) {
|
||||
if (searchInputRef.current) {
|
||||
var input_1 = searchInputRef.current;
|
||||
setTimeout(function () {
|
||||
input_1.value = selectedText;
|
||||
input_1.focus();
|
||||
}, 0);
|
||||
}
|
||||
search(selectedText);
|
||||
}
|
||||
}, [isSearching, selectedText, search]);
|
||||
if (!isSearching)
|
||||
return null;
|
||||
@@ -70,9 +80,8 @@ export function SearchReplaceFloatingMenu(props) {
|
||||
mr: 1,
|
||||
width: 200,
|
||||
alignItems: "center",
|
||||
} }, { children: [_jsx(Input, { defaultValue: selectedText, autoFocus: true, sx: { p: 1 }, placeholder: "Find", onChange: function (e) {
|
||||
searchText.current = e.target.value;
|
||||
search(searchText.current);
|
||||
} }, { children: [_jsx(Input, { defaultValue: selectedText, ref: searchInputRef, autoFocus: true, sx: { p: 1 }, placeholder: "Find", onChange: function (e) {
|
||||
search(e.target.value);
|
||||
} }), _jsxs(Flex, __assign({ sx: {
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
|
||||
@@ -174,10 +174,14 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
|
||||
}
|
||||
return true;
|
||||
},
|
||||
endSearch: () => () => {
|
||||
this.storage.isSearching = false;
|
||||
return true;
|
||||
},
|
||||
endSearch:
|
||||
() =>
|
||||
({ state, dispatch }) => {
|
||||
this.storage.isSearching = false;
|
||||
this.storage.searchTerm = "";
|
||||
updateView(state, dispatch);
|
||||
return true;
|
||||
},
|
||||
search:
|
||||
(term, options?: SearchSettings) =>
|
||||
({ state, dispatch }) => {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function SearchReplaceFloatingMenu(props: FloatingMenuProps) {
|
||||
const [matchWholeWord, setMatchWholeWord] = useState(false);
|
||||
const [enableRegex, setEnableRegex] = useState(false);
|
||||
const replaceText = useRef("");
|
||||
const searchText = useRef("");
|
||||
const searchInputRef = useRef<HTMLInputElement>();
|
||||
|
||||
const search = useCallback(
|
||||
(term: string) => {
|
||||
@@ -30,11 +30,21 @@ export function SearchReplaceFloatingMenu(props: FloatingMenuProps) {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
search(searchText.current);
|
||||
if (!searchInputRef.current) return;
|
||||
search(searchInputRef.current.value);
|
||||
}, [search, matchCase, matchWholeWord, enableRegex]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSearching && selectedText) search(selectedText);
|
||||
if (isSearching && selectedText) {
|
||||
if (searchInputRef.current) {
|
||||
const input = searchInputRef.current;
|
||||
setTimeout(() => {
|
||||
input.value = selectedText;
|
||||
input.focus();
|
||||
}, 0);
|
||||
}
|
||||
search(selectedText);
|
||||
}
|
||||
}, [isSearching, selectedText, search]);
|
||||
|
||||
if (!isSearching) return null;
|
||||
@@ -67,12 +77,12 @@ export function SearchReplaceFloatingMenu(props: FloatingMenuProps) {
|
||||
>
|
||||
<Input
|
||||
defaultValue={selectedText}
|
||||
ref={searchInputRef}
|
||||
autoFocus
|
||||
sx={{ p: 1 }}
|
||||
placeholder="Find"
|
||||
onChange={(e) => {
|
||||
searchText.current = e.target.value;
|
||||
search(searchText.current);
|
||||
search(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<Flex
|
||||
|
||||
Reference in New Issue
Block a user