Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Commits
5d1ad8d2
Commit
5d1ad8d2
authored
4 years ago
by
Christos
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-find' into 'master'
fix-find See merge request
!280
parents
d9f7249c
df6b9d54
No related branches found
No related tags found
1 merge request
!280
fix-find
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wax-prosemirror-components/src/components/findAndReplace/FindComponent.js
+48
-14
48 additions, 14 deletions
...components/src/components/findAndReplace/FindComponent.js
with
48 additions
and
14 deletions
wax-prosemirror-components/src/components/findAndReplace/FindComponent.js
+
48
−
14
View file @
5d1ad8d2
...
...
@@ -100,6 +100,38 @@ const Svg = styled.svg.attrs(() => ({
width: 24px;
`
;
const
useDebounce
=
(
value
,
delay
)
=>
{
// State and setters for debounced value
const
[
debouncedValue
,
setDebouncedValue
]
=
useState
(
value
);
useEffect
(
()
=>
{
// Set debouncedValue to value (passed in) after the specified delay
const
handler
=
setTimeout
(()
=>
{
setDebouncedValue
(
value
);
},
delay
);
// Return a cleanup function that will be called every time ...
// ... useEffect is re-called. useEffect will only be re-called ...
// ... if value changes (see the inputs array below).
// This is how we prevent debouncedValue from changing if value is ...
// ... changed within the delay period. Timeout gets cleared and restarted.
// To put it in context, if the user is typing within our app's ...
// ... search box, we don't want the debouncedValue to update until ...
// ... they've stopped typing for more than 500ms.
return
()
=>
{
clearTimeout
(
handler
);
};
},
// Only re-call effect if value changes
// You could also add the "delay" var to inputs array if you ...
// ... need to be able to change that dynamically.
[
value
],
);
return
debouncedValue
;
};
const
FindComponent
=
({
close
,
expand
,
...
...
@@ -119,32 +151,29 @@ const FindComponent = ({
const
allStates
=
[];
const
debouncedSearchTerm
=
useDebounce
(
searchValue
,
300
);
each
(
view
,
(
singleView
,
viewId
)
=>
{
allStates
.
push
(
singleView
.
state
);
});
const
delayedSearch
=
useCallback
(
debounce
(()
=>
searchDocument
(),
300
),
[
searchValue
,
matchCaseSearch
,
activeViewId
],
);
// const delayedSearch = useCallback(searchDocument(), [
// (debouncedSearchTerm, matchCaseSearch, activeViewId),
// ]);
const
onChange
=
()
=>
{
setSearchValue
(
searchRef
.
current
.
value
);
};
useEffect
(()
=>
{
delayedSearch
();
let
counter
=
0
;
counter
=
helpers
.
getMatchesByView
(
view
,
searchValue
,
matchCaseSearch
);
setCounterSearches
(
counter
);
searchDocument
();
if
(
isFirstRun
)
{
setTimeout
(()
=>
{
searchRef
.
current
.
focus
();
setFirstRun
(
false
);
});
}
},
[
searchValue
,
delay
edSearch
,
matchCaseSearch
,
JSON
.
stringify
(
allStates
)]);
},
[
debounc
edSearch
Term
,
matchCaseSearch
,
JSON
.
stringify
(
allStates
)]);
const
setCounterSearches
=
counter
=>
{
if
(
counter
===
0
)
return
setCounterText
(
'
0 of 0
'
);
...
...
@@ -195,11 +224,16 @@ const FindComponent = ({
};
const
searchDocument
=
()
=>
{
findAndReplacePlugin
.
props
.
setSearchText
(
searchValue
);
let
counter
=
0
;
if
(
searchValue
===
''
)
{
findAndReplacePlugin
.
props
.
setSearchText
(
''
);
}
else
{
findAndReplacePlugin
.
props
.
setSearchText
(
searchValue
);
}
findAndReplacePlugin
.
props
.
setSearchMatchCase
(
matchCaseSearch
);
// let
counter =
0
;
// counter = helpers.getMatchesByView(view, searchValue, matchCaseSearch);
//
setCounterSearches(counter);
counter
=
helpers
.
getMatchesByView
(
view
,
searchValue
,
matchCaseSearch
)
;
setCounterSearches
(
counter
);
if
(
searchRef
.
current
===
document
.
activeElement
)
{
eachRight
(
view
,
(
singleView
,
viewId
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment