Skip to content
Snippets Groups Projects
Commit 28e77be6 authored by chris's avatar chris
Browse files

use last users selection as starting point

parent ab1de121
No related branches found
No related tags found
1 merge request!231Connect funcionality
...@@ -96,8 +96,10 @@ const Svg = styled.svg.attrs(() => ({ ...@@ -96,8 +96,10 @@ const Svg = styled.svg.attrs(() => ({
const FindComponent = ({ close, expand, setPreviousSearcValue }) => { const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
const { app, view, activeViewId } = useContext(WaxContext); const { app, view, activeViewId } = useContext(WaxContext);
const searchRef = useRef(null); const searchRef = useRef(null);
const [lastActiveViewId, setlastActiveViewId] = useState();
const [lastSelection, setLastSelection] = useState();
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const [counterText, setCounterText] = useState('0 of 0'); const [counterText, setCounterText] = useState('0 of 0');
const [matchCaseSearch, setMatchCaseSearch] = useState(false); const [matchCaseSearch, setMatchCaseSearch] = useState(false);
...@@ -120,6 +122,10 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => { ...@@ -120,6 +122,10 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
}; };
useEffect(() => { useEffect(() => {
if (view[activeViewId].state.selection.from !== 0) {
setLastSelection(view[activeViewId].state.selection);
setlastActiveViewId(activeViewId);
}
delayedSearch(); delayedSearch();
if (isFirstRun) { if (isFirstRun) {
setTimeout(() => { setTimeout(() => {
...@@ -192,7 +198,6 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => { ...@@ -192,7 +198,6 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
const findNext = () => { const findNext = () => {
const results = getAllResultsByView(); const results = getAllResultsByView();
const currentSelection = view[activeViewId].state.selection;
const resultsFrom = {}; const resultsFrom = {};
each(results, (result, viewId) => { each(results, (result, viewId) => {
...@@ -205,32 +210,36 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => { ...@@ -205,32 +210,36 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
}); });
}); });
const found = closest(currentSelection.from, resultsFrom[activeViewId]); const found = closest(lastSelection.from, resultsFrom[lastActiveViewId]);
const position = resultsFrom[activeViewId].indexOf(found); const position = resultsFrom[lastActiveViewId].indexOf(found);
const selectionFrom = new TextSelection( const selectionFrom = new TextSelection(
view[activeViewId].state.doc.resolve( view[lastActiveViewId].state.doc.resolve(
results[activeViewId][position].from, results[lastActiveViewId][position].from,
), ),
); );
const selectionTo = new TextSelection( const selectionTo = new TextSelection(
view[activeViewId].state.doc.resolve(results[activeViewId][position].to), view[lastActiveViewId].state.doc.resolve(
results[lastActiveViewId][position].to,
),
); );
view[activeViewId].dispatch( view[lastActiveViewId].dispatch(
view[activeViewId].state.tr.setSelection( view[lastActiveViewId].state.tr.setSelection(
TextSelection.between(selectionFrom.$anchor, selectionTo.$head), TextSelection.between(selectionFrom.$anchor, selectionTo.$head),
), ),
); );
view[activeViewId].dispatch(view[activeViewId].state.tr.scrollIntoView()); view[lastActiveViewId].dispatch(
view[lastActiveViewId].state.tr.scrollIntoView(),
);
}; };
const findPrevious = () => { const findPrevious = () => {
const results = getAllResultsByView(); const results = getAllResultsByView();
const currentSelection = view[activeViewId].state.selection; const currentSelection = view[lastActiveViewId].state.selection;
console.log(results, activeViewId, currentSelection); console.log(results, lastActiveViewId, currentSelection);
}; };
return ( return (
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment