Skip to content
Snippets Groups Projects
Commit 5585e89e authored by chris's avatar chris
Browse files

search all views

parent 1acb794c
No related branches found
No related tags found
1 merge request!190Find and replace
......@@ -105,7 +105,7 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
const searchDocument = () => {
setCounterText('0 of 0');
console.log('search');
const results = helpers.getMatchesByView(
view,
searchValue,
......@@ -123,6 +123,10 @@ const FindComponent = ({ close, expand, setPreviousSearcValue }) => {
close();
};
if (searchRef.current !== document.activeElement) {
console.log('not input');
}
const showExpanded = () => {
expand();
setPreviousSearcValue(searchValue);
......
import { each, eachRight } from 'lodash';
const findMatches = (doc, searchValue) => {
const results = [];
const mergedTextNodes = [];
let index = 0;
doc.descendants((node, pos) => {
if (node.isText) {
if (mergedTextNodes[index]) {
mergedTextNodes[index] = {
text: mergedTextNodes[index].text + node.text,
pos: mergedTextNodes[index].pos,
};
} else {
mergedTextNodes[index] = {
text: node.text,
pos,
};
}
} else {
index += 1;
}
});
mergedTextNodes.forEach(({ text, pos }) => {
const search = RegExp(searchValue, 'gui');
let m;
// eslint-disable-next-line no-cond-assign
while ((m = search.exec(text))) {
if (m[0] === '') {
break;
}
results.push({
from: pos + m.index,
to: pos + m.index + m[0].length,
});
}
});
return results;
};
const findMatchesOnMain = (doc, searchValue) => {
const allNodes = [];
doc.descendants((node, pos) => {
......@@ -96,19 +55,11 @@ const findMatchesOnMain = (doc, searchValue) => {
const getMatchesByView = (views, searchValue, findAndReplacePlugin) => {
let allResults = 0;
each(views, (singleView, viewId) => {
if (viewId === 'main') {
const results = findMatchesOnMain(singleView.state.doc, searchValue);
allResults += results.length;
findAndReplacePlugin.props.setResults(results);
singleView.state.tr.setMeta('search', true);
singleView.dispatch(singleView.state.tr);
} else {
const results = findMatches(singleView.state.doc, searchValue);
allResults += results.length;
findAndReplacePlugin.props.setResults(results);
singleView.state.tr.setMeta('search', true);
singleView.dispatch(singleView.state.tr);
}
const results = findMatches(singleView.state.doc, searchValue);
allResults += results.length;
findAndReplacePlugin.props.setResults(results);
singleView.state.tr.setMeta('search', true);
singleView.dispatch(singleView.state.tr);
return allResults;
});
return allResults;
......
......@@ -13,7 +13,6 @@ export default props => {
return DecorationSet.empty;
},
apply(tr, prev, _, newState) {
console.log('again in apply', allResults);
let createDecoration;
let decorations;
let createdDecorations;
......
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