add search with editor selection

This commit is contained in:
ammarahm-ed
2021-12-23 14:51:11 +05:00
parent 2460f9029e
commit d0144f2a47
3 changed files with 19 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -604,7 +604,7 @@ function getNodeBg(element) {
}
let selectionTimer = null;
function selectchange() {
function selectchange(requestvalue) {
clearTimeout(selectionTimer);
selectionTimer = null;
selectionTimer = setTimeout(function () {
@@ -631,9 +631,13 @@ function selectchange() {
currentFormats.current = {
index: range.startOffset,
length: range.endOffset - range.startOffset
length: range.endOffset - range.startOffset,
};
if (requestvalue) {
currentFormats.current.value = editor.selection.getContent()
}
currentFormats.fontsize = editor.selection.getNode().style.fontSize;
if (currentFormats.fontsize === '') {
@@ -684,5 +688,5 @@ function selectchange() {
}
currentFormats.node = editor.selection.getNode().nodeName;
reactNativeEventHandler('selectionchange', currentFormats);
}, 50);
},requestvalue ? 0 : 50);
}

View File

@@ -6,6 +6,7 @@ import {useTracked} from '../../../../provider';
import {useSettingStore} from '../../../../provider/stores';
import {showTooltip, TOOLTIP_POSITIONS} from '../../../../utils';
import {SIZE} from '../../../../utils/SizeUtils';
import { sleep } from '../../../../utils/TimeUtils';
import {EditorWebView} from '../../Functions';
import tiny from '../tiny';
import {endSearch} from './commands';
@@ -28,9 +29,18 @@ const SearcReplace = () => {
replace: null
});
useEffect(() => {
async function searchWithSelection() {
tiny.call(EditorWebView,`selectchange(true)`);
await sleep(100);
values.current.find = properties.selection?.current?.value;
findRef.current?.setNativeProps({
text:values.current.find
})
find();
}
useEffect(() => {
searchWithSelection();
setTimeout(() => {
findRef.current?.focus();
}, 300);