diff --git a/wax-prosemirror-components/src/components/findAndReplace/FindComponent.js b/wax-prosemirror-components/src/components/findAndReplace/FindComponent.js index 638dcc677e7909202925963bafc87c13cc3d094a..8a1f1a8ca829f8d08e7c96f2afe24151b22251e7 100644 --- a/wax-prosemirror-components/src/components/findAndReplace/FindComponent.js +++ b/wax-prosemirror-components/src/components/findAndReplace/FindComponent.js @@ -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); diff --git a/wax-prosemirror-components/src/components/findAndReplace/helpers.js b/wax-prosemirror-components/src/components/findAndReplace/helpers.js index 46eb1b2a8b1dd7258fc8b2fbd18e45b32c305a48..7d2b732812341c1beabaff87eb63b7fbc42902d8 100644 --- a/wax-prosemirror-components/src/components/findAndReplace/helpers.js +++ b/wax-prosemirror-components/src/components/findAndReplace/helpers.js @@ -1,47 +1,6 @@ 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; diff --git a/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js b/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js index 1033f1da6570bfcd87cbc74cae1d7b6433406f48..95b122f03080e3e465e10ae6a23c93c3b288c945 100644 --- a/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js +++ b/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js @@ -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;