Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

improve search & replace

ammarahm-eda2be6cf421f1
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.js
index 27a208930..0a8848fae 100755
--- a/apps/mobile/html/Web.bundle/site/init.js
+++ b/apps/mobile/html/Web.bundle/site/init.js
@@ -604,7 +604,7 @@ function getNodeBg(element) {
}
let selectionTimer = null;
-function selectchange(requestvalue) {
+function selectchange() {
clearTimeout(selectionTimer);
selectionTimer = null;
selectionTimer = setTimeout(function () {
@@ -634,10 +634,6 @@ function selectchange(requestvalue) {
length: range.endOffset - range.startOffset,
};
- if (requestvalue) {
- currentFormats.current.value = editor.selection.getContent()
- }
-
currentFormats.fontsize = editor.selection.getNode().style.fontSize;
if (currentFormats.fontsize === '') {
@@ -688,5 +684,5 @@ function selectchange(requestvalue) {
}
currentFormats.node = editor.selection.getNode().nodeName;
reactNativeEventHandler('selectionchange', currentFormats);
- },requestvalue ? 0 : 50);
+ },50);
}
diff --git a/apps/mobile/src/provider/interfaces.ts b/apps/mobile/src/provider/interfaces.ts
index b425e95b4..f20b741bf 100644
--- a/apps/mobile/src/provider/interfaces.ts
+++ b/apps/mobile/src/provider/interfaces.ts
@@ -117,7 +117,8 @@ export interface EditorStore extends State {
sessionId:string | null,
setSessionId:(sessionId:string | null) => void,
searchReplace:boolean,
- setSearchReplace:(searchReplace:boolean) => void
+ setSearchReplace:(searchReplace:boolean) => void,
+ searchSelection:string | null
}
diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.ts
index d4c0389a6..0bc16a253 100644
--- a/apps/mobile/src/provider/stores.ts
+++ b/apps/mobile/src/provider/stores.ts
@@ -24,6 +24,7 @@ import {
import {groupArray} from 'notes-core/utils/grouping';
import {EditorWebView, post} from '../views/Editor/Functions';
import tiny from '../views/Editor/tiny/tiny';
+import {eSubscribeEvent, eUnSubscribeEvent} from '../services/EventManager';
export const useNoteStore = create<NoteStore>((set, get) => ({
notes: [],
@@ -164,10 +165,10 @@ interface AttachmentStore {
hash: string;
recieved: number;
type: 'upload' | 'download';
- } | null
- }
+ } | null;
+ };
encryptionProgress: number;
- setEncryptionProgress: (encryptionProgress:number) => void;
+ setEncryptionProgress: (encryptionProgress: number) => void;
remove: (hash: string) => void;
setProgress: (
sent: number,
@@ -244,7 +245,7 @@ export const useSettingStore = create<SettingStore>((set, get) => ({
notesListMode: 'normal',
devMode: false,
notifNotes: false,
- pitchBlack:false
+ pitchBlack: false
},
fullscreen: false,
deviceMode: 'mobile',
@@ -280,13 +281,33 @@ export const useMenuStore = create<MenuStore>((set, get) => ({
export const useEditorStore = create<EditorStore>((set, get) => ({
currentEditingNote: null,
setCurrentlyEditingNote: note => set({currentEditingNote: note}),
- sessionId:null,
- setSessionId:(sessionId) => {
- console.log(sessionId,'session id');
+ sessionId: null,
+ setSessionId: sessionId => {
+ console.log(sessionId, 'session id');
set({sessionId});
},
- searchReplace:false,
- setSearchReplace:(searchReplace) => set({searchReplace})
+ searchReplace: false,
+ searchSelection: null,
+ setSearchReplace: searchReplace => {
+ set({searchReplace});
+ if (!searchReplace) {
+ set({searchSelection: null});
+ return;
+ }
+ let func = (value: string) => {
+ set({searchSelection: value});
+ eUnSubscribeEvent('selectionvalue', func);
+ };
+ eSubscribeEvent('selectionvalue', func);
+ tiny.call(
+ EditorWebView,
+ `(function() {
+ if (editor) {
+ reactNativeEventHandler('selectionvalue',editor.selection.getContent());
+ }
+ })();`
+ );
+ }
}));
export const useSearchStore = create<SearchStore>((set, get) => ({
@@ -377,7 +398,7 @@ export const useMessageStore = create<MessageStore>((set, get) => ({
announcements = [];
}
} catch (e) {
- console.log("ERROR",e);
+ console.log('ERROR', e);
set({announcements: []});
} finally {
let all = await getFiltered(announcements);
@@ -423,7 +444,7 @@ export function clearAllStores() {
export const allowedPlatforms = ['all', 'mobile', Platform.OS];
-async function shouldShowAnnouncement(announcement:Announcement) {
+async function shouldShowAnnouncement(announcement: Announcement) {
if (!announcement) return false;
let removed = (await MMKV.getStringAsync(announcement.id)) === 'removed';
if (removed) return false;
@@ -454,7 +475,10 @@ async function shouldShowAnnouncement(announcement:Announcement) {
case 'unverified':
return !PremiumService.getUser()?.isEmailVerified;
case 'proExpired':
- return subStatus === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED || subStatus === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED;
+ return (
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED ||
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
+ );
case 'any':
default:
return true;
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index 682f0c872..628569b48 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -5,6 +5,7 @@ import {
InteractionManager,
Keyboard,
Platform,
+ Vibration,
View
} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
@@ -339,8 +340,8 @@ const EditorHeader = () => {
}}
top={50}
onPress={async () => {
- EditorWebView.current?.reload();
- return;
+ EditorWebView.current?.reload();
+ return;
if (editing.isFocused) {
safeKeyboardDismiss();
editing.isFocused = true;
@@ -358,13 +359,15 @@ const EditorHeader = () => {
type={searchReplace ? 'grayBg' : 'transparent'}
top={50}
buttom={10}
- onPress={() => {
+ onLongPress={() => {
if (searchReplace) {
endSearch();
- } else {
- useEditorStore.getState().setSearchReplace(true);
+ Vibration.vibrate(5, false);
}
}}
+ onPress={() => {
+ useEditorStore.getState().setSearchReplace(true);
+ }}
/>
{currentlyEditingNote && (
@@ -379,16 +382,15 @@ const EditorHeader = () => {
/>
)}
-
- <ActionIcon
- name="attachment"
- color={colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- onPress={picker.pick}
- />
+ <ActionIcon
+ name="attachment"
+ color={colors.pri}
+ customStyle={{
+ marginLeft: 5
+ }}
+ top={50}
+ onPress={picker.pick}
+ />
{deviceMode !== 'mobile' && !fullscreen ? (
<ActionIcon
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index e79a0fb90..1f3af905d 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -452,6 +452,10 @@ export const _onMessage = async evt => {
}
switch (message.type) {
+ case 'selectionvalue':
+ eSendEvent('selectionvalue',message.value);
+ console.log(message.value);
+ break;
case 'history':
eSendEvent('historyEvent', message.value);
break;
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js b/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
index 743e58e32..fb29d2968 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
@@ -3,10 +3,14 @@ import {View} from 'react-native';
import {Button} from '../../../../components/Button';
import Input from '../../../../components/Input';
import {useTracked} from '../../../../provider';
-import {useSettingStore} from '../../../../provider/stores';
+import {useEditorStore, useSettingStore} from '../../../../provider/stores';
+import {
+ eSubscribeEvent,
+ eUnSubscribeEvent
+} from '../../../../services/EventManager';
import {showTooltip, TOOLTIP_POSITIONS} from '../../../../utils';
import {SIZE} from '../../../../utils/SizeUtils';
-import { sleep } from '../../../../utils/TimeUtils';
+import {sleep} from '../../../../utils/TimeUtils';
import {EditorWebView} from '../../Functions';
import tiny from '../tiny';
import {endSearch} from './commands';
@@ -19,6 +23,7 @@ const SearcReplace = () => {
const [enableReplace, setEnableReplace] = useState(false);
const [menu, setMenu] = useState(false);
const deviceMode = useSettingStore(state => state.deviceMode);
+ const searchSelection = useEditorStore(state => state.searchSelection);
const findRef = useRef();
const [config, setConfig] = useState({
matchCase: false,
@@ -30,17 +35,18 @@ const SearcReplace = () => {
});
async function searchWithSelection() {
- tiny.call(EditorWebView,`selectchange(true)`);
- await sleep(100);
- values.current.find = properties.selection?.current?.value;
+ values.current.find = searchSelection;
findRef.current?.setNativeProps({
- text:values.current.find
- })
+ text: searchSelection
+ });
find();
}
useEffect(() => {
searchWithSelection();
+ }, [searchSelection]);
+
+ useEffect(() => {
setTimeout(() => {
findRef.current?.focus();
}, 300);