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
Merge requests
!231
Connect funcionality
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Connect funcionality
connect-funcionality
into
master
Overview
0
Commits
43
Pipelines
0
Changes
44
Merged
Christos
requested to merge
connect-funcionality
into
master
4 years ago
Overview
0
Commits
43
Pipelines
0
Changes
7
Expand
0
0
Merge request reports
Compare
version 14
version 34
e554b0c7
4 years ago
version 33
c19a1a7d
4 years ago
version 32
b159bdd6
4 years ago
version 31
36b800fd
4 years ago
version 30
fcec6474
4 years ago
version 29
26879ae3
4 years ago
version 28
b6a9e7b6
4 years ago
version 27
cd3421b0
4 years ago
version 26
bd9e417b
4 years ago
version 25
da29dfb6
4 years ago
version 24
be10091e
4 years ago
version 23
33cd7340
4 years ago
version 22
6a6ab4fb
4 years ago
version 21
66e31d74
4 years ago
version 20
af0477f0
4 years ago
version 19
ecbb329f
4 years ago
version 18
648119f1
4 years ago
version 17
8792dd32
4 years ago
version 16
ca64e7a9
4 years ago
version 15
5f3c1535
4 years ago
version 14
8b2b8ea3
4 years ago
version 13
18abfe35
4 years ago
version 12
b30c275d
4 years ago
version 11
1a7ff3f8
4 years ago
version 10
577a5128
4 years ago
version 9
001a7ab8
4 years ago
version 8
fe3c7768
4 years ago
version 7
0dd1dd2e
4 years ago
version 6
02fdc87c
4 years ago
version 5
19af193e
4 years ago
version 4
ebcbb08c
4 years ago
version 3
e48aedbe
4 years ago
version 2
97b719c5
4 years ago
version 1
01876cc7
4 years ago
master (base)
and
version 17
latest version
6cc69128
43 commits,
4 years ago
version 34
e554b0c7
42 commits,
4 years ago
version 33
c19a1a7d
41 commits,
4 years ago
version 32
b159bdd6
40 commits,
4 years ago
version 31
36b800fd
39 commits,
4 years ago
version 30
fcec6474
38 commits,
4 years ago
version 29
26879ae3
37 commits,
4 years ago
version 28
b6a9e7b6
36 commits,
4 years ago
version 27
cd3421b0
36 commits,
4 years ago
version 26
bd9e417b
35 commits,
4 years ago
version 25
da29dfb6
34 commits,
4 years ago
version 24
be10091e
33 commits,
4 years ago
version 23
33cd7340
31 commits,
4 years ago
version 22
6a6ab4fb
30 commits,
4 years ago
version 21
66e31d74
28 commits,
4 years ago
version 20
af0477f0
27 commits,
4 years ago
version 19
ecbb329f
24 commits,
4 years ago
version 18
648119f1
23 commits,
4 years ago
version 17
8792dd32
22 commits,
4 years ago
version 16
ca64e7a9
21 commits,
4 years ago
version 15
5f3c1535
20 commits,
4 years ago
version 14
8b2b8ea3
18 commits,
4 years ago
version 13
18abfe35
17 commits,
4 years ago
version 12
b30c275d
15 commits,
4 years ago
version 11
1a7ff3f8
13 commits,
4 years ago
version 10
577a5128
11 commits,
4 years ago
version 9
001a7ab8
9 commits,
4 years ago
version 8
fe3c7768
8 commits,
4 years ago
version 7
0dd1dd2e
7 commits,
4 years ago
version 6
02fdc87c
6 commits,
4 years ago
version 5
19af193e
5 commits,
4 years ago
version 4
ebcbb08c
4 commits,
4 years ago
version 3
e48aedbe
3 commits,
4 years ago
version 2
97b719c5
2 commits,
4 years ago
version 1
01876cc7
1 commit,
4 years ago
Show latest version
7 files
+
157
−
101
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
wax-prosemirror-components/src/components/findAndReplace/FindComponent.js
+
48
−
93
Options
@@ -7,7 +7,6 @@ import React, {
useCallback
,
useEffect
,
}
from
'
react
'
;
import
{
TextSelection
}
from
'
prosemirror-state
'
;
import
{
debounce
,
each
,
eachRight
}
from
'
lodash
'
;
import
styled
from
'
styled-components
'
;
import
{
grid
}
from
'
@pubsweet/ui-toolkit
'
;
@@ -169,118 +168,74 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
searchRef
.
current
.
focus
();
};
const
getAllResultsByView
=
()
=>
{
const
allResults
=
{};
each
(
view
,
(
singleView
,
viewId
)
=>
{
if
(
!
allResults
[
viewId
])
{
allResults
[
viewId
]
=
helpers
.
findMatches
(
singleView
.
state
.
doc
,
searchValue
,
matchCaseSearch
,
);
}
});
return
allResults
;
};
const
closest
=
(
selectionFrom
,
results
,
greater
=
true
)
=>
{
return
results
.
reduce
((
a
,
b
)
=>
{
const
greaterSmaller
=
greater
?
a
>
b
:
a
<
b
;
const
aDiff
=
Math
.
abs
(
a
-
selectionFrom
);
const
bDiff
=
Math
.
abs
(
b
-
selectionFrom
);
if
(
aDiff
===
bDiff
)
{
return
greaterSmaller
?
a
:
b
;
}
return
bDiff
<
aDiff
?
b
:
a
;
});
};
const
findNext
=
()
=>
{
view
[
lastActiveViewId
].
focus
();
const
results
=
getAllResultsByView
();
const
resultsFrom
=
{};
each
(
results
,
(
result
,
viewId
)
=>
{
result
.
forEach
(
res
=>
{
if
(
!
resultsFrom
[
viewId
])
{
resultsFrom
[
viewId
]
=
[
res
.
from
];
}
else
{
resultsFrom
[
viewId
].
push
(
res
.
from
);
}
});
});
const
found
=
closest
(
lastSelection
.
from
,
resultsFrom
[
lastActiveViewId
]);
let
position
=
resultsFrom
[
lastActiveViewId
].
indexOf
(
found
);
if
(
lastSelection
.
from
>=
found
)
position
+=
1
;
const
selectionFrom
=
new
TextSelection
(
view
[
lastActiveViewId
].
state
.
doc
.
resolve
(
results
[
lastActiveViewId
][
position
].
from
,
),
const
results
=
helpers
.
getAllResultsByView
(
view
,
searchValue
,
matchCaseSearch
,
);
const
resultsFrom
=
helpers
.
getResultsFrom
(
results
);
const
notesIds
=
helpers
.
getNotesIds
(
view
.
main
);
const
selectionTo
=
new
TextSelection
(
view
[
lastActiveViewId
].
state
.
doc
.
resolve
(
results
[
lastActiveViewId
][
position
].
to
,
),
const
found
=
helpers
.
getClosestMatch
(
lastSelection
.
from
,
resultsFrom
[
lastActiveViewId
],
);
const
position
=
resultsFrom
[
lastActiveViewId
].
indexOf
(
found
);
view
[
lastActiveViewId
].
dispatch
(
view
[
lastActiveViewId
].
state
.
tr
.
setSelection
(
TextSelection
.
between
(
selectionFrom
.
$anchor
,
selectionTo
.
$head
),
),
);
/* User selection lesser than found */
if
(
lastSelection
.
from
<
found
)
{
helpers
.
moveToMatch
(
view
,
lastActiveViewId
,
results
,
position
);
}
view
[
lastActiveViewId
].
dispatch
(
view
[
lastActiveViewId
].
state
.
tr
.
scrollIntoView
(),
);
/* User selection greater than found move to next if not already at the end of results for the view */
if
(
lastSelection
.
from
>=
found
&&
position
<
resultsFrom
[
lastActiveViewId
].
length
-
1
)
{
helpers
.
moveToMatch
(
view
,
lastActiveViewId
,
results
,
position
+
1
);
}
/* Last result of the specific view. Move to next view */
if
(
lastSelection
.
from
===
found
&&
position
===
resultsFrom
[
lastActiveViewId
].
length
-
1
)
{
/* End of results in notes move to main if results exist */
if
(
notesIds
.
indexOf
(
lastActiveViewId
)
===
notesIds
.
length
-
1
&&
results
.
main
.
length
>
0
)
helpers
.
moveToMatch
(
view
,
'
main
'
,
results
,
0
);
}
};
const
findPrevious
=
()
=>
{
view
[
lastActiveViewId
].
focus
();
const
results
=
getAllResultsByView
();
const
resultsFrom
=
{};
each
(
results
,
(
result
,
viewId
)
=>
{
result
.
forEach
(
res
=>
{
if
(
!
resultsFrom
[
viewId
])
{
resultsFrom
[
viewId
]
=
[
res
.
from
];
}
else
{
resultsFrom
[
viewId
].
push
(
res
.
from
);
}
});
});
const
results
=
helpers
.
getAllResultsByView
(
view
,
searchValue
,
matchCaseSearch
,
);
const
resultsFrom
=
helpers
.
getResultsFrom
(
results
);
const
notesIds
=
helpers
.
getNotesIds
(
view
.
main
);
const
found
=
c
losest
(
const
found
=
helpers
.
getC
losest
Match
(
lastSelection
.
from
,
resultsFrom
[
lastActiveViewId
],
false
,
);
let
position
=
resultsFrom
[
lastActiveViewId
].
indexOf
(
found
);
if
(
lastSelection
.
from
<=
found
)
position
-=
1
;
const
selectionFrom
=
new
TextSelection
(
view
[
lastActiveViewId
].
state
.
doc
.
resolve
(
results
[
lastActiveViewId
][
position
].
from
,
),
);
const
selectionTo
=
new
TextSelection
(
view
[
lastActiveViewId
].
state
.
doc
.
resolve
(
results
[
lastActiveViewId
][
position
].
to
,
),
);
if
(
lastSelection
.
from
<=
found
&&
position
!==
0
)
position
-=
1
;
view
[
lastActiveViewId
].
dispatch
(
view
[
lastActiveViewId
].
state
.
tr
.
setSelection
(
TextSelection
.
between
(
selectionFrom
.
$anchor
,
selectionTo
.
$head
),
),
);
if
(
lastSelection
.
from
===
found
&&
position
===
0
)
{
view
.
main
.
focus
();
console
.
log
(
'
first in view
'
);
}
view
[
lastActiveViewId
].
dispatch
(
view
[
lastActiveViewId
].
state
.
tr
.
scrollIntoView
(),
);
helpers
.
moveToMatch
(
view
,
lastActiveViewId
,
results
,
position
);
};
return
(