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
28e77be6
Commit
28e77be6
authored
4 years ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
use last users selection as starting point
parent
ab1de121
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!231
Connect funcionality
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wax-prosemirror-components/src/components/findAndReplace/FindComponent.js
+21
-12
21 additions, 12 deletions
...components/src/components/findAndReplace/FindComponent.js
with
21 additions
and
12 deletions
wax-prosemirror-components/src/components/findAndReplace/FindComponent.js
+
21
−
12
View file @
28e77be6
...
@@ -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
(
curren
tSelection
.
from
,
resultsFrom
[
a
ctiveViewId
]);
const
found
=
closest
(
las
tSelection
.
from
,
resultsFrom
[
lastA
ctiveViewId
]);
const
position
=
resultsFrom
[
a
ctiveViewId
].
indexOf
(
found
);
const
position
=
resultsFrom
[
lastA
ctiveViewId
].
indexOf
(
found
);
const
selectionFrom
=
new
TextSelection
(
const
selectionFrom
=
new
TextSelection
(
view
[
a
ctiveViewId
].
state
.
doc
.
resolve
(
view
[
lastA
ctiveViewId
].
state
.
doc
.
resolve
(
results
[
a
ctiveViewId
][
position
].
from
,
results
[
lastA
ctiveViewId
][
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
[
a
ctiveViewId
].
dispatch
(
view
[
lastA
ctiveViewId
].
dispatch
(
view
[
a
ctiveViewId
].
state
.
tr
.
setSelection
(
view
[
lastA
ctiveViewId
].
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
[
a
ctiveViewId
].
state
.
selection
;
const
currentSelection
=
view
[
lastA
ctiveViewId
].
state
.
selection
;
console
.
log
(
results
,
a
ctiveViewId
,
currentSelection
);
console
.
log
(
results
,
lastA
ctiveViewId
,
currentSelection
);
};
};
return
(
return
(
...
...
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