Skip to content

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

feat: add auto focus editor

ammarahm-ed4f282c71fa40
diff --git a/apps/mobile/android/app/src/main/assets/texteditor.html b/apps/mobile/android/app/src/main/assets/texteditor.html
index e4347cf56..8965cbf5d 100644
--- a/apps/mobile/android/app/src/main/assets/texteditor.html
+++ b/apps/mobile/android/app/src/main/assets/texteditor.html
@@ -1332,11 +1332,24 @@ const setTheme = function() {
// Receber mensagens do RN
document.addEventListener('message', data => {
+
+
+ if (data.data === "clear") {
+
+ editor.setText('')
+
+ }else if (data.data === "focusEditor") {
+
+ editor.focus();
+ } else if (data.data === 'focusTitle') {
- if (JSON.parse(data.data).type === "nomenu") {
+ document.getElementById('titleInput').focus();
+ }else if (JSON.parse(data.data).type === "nomenu") {
let isenabled = JSON.parse(data.data).value;
let width = window.innerWidth;
let titleIn = document.getElementById('titleInput');
+
+
if (isenabled) {
@@ -1355,6 +1368,7 @@ document.addEventListener('message', data => {
}
else if (JSON.parse(data.data).type === "title") {
document.getElementById('titleInput').value = JSON.parse(data.data).value
+
} else if (data.data.substr(0,9) === '{"night":') {
pageTheme.colors = JSON.parse(data.data);
@@ -1362,15 +1376,34 @@ document.addEventListener('message', data => {
return;
} else if (data.data[0] === '{') {
+
const content = JSON.parse(data.data);
+
editor.setContents(content,'silent');
+
+ setTimeout(() => {
+ editor.focus();
+ editor.setSelection(editor.getText().length -1,0);
+ },0)
+
} else if (data.data[0] === '<') {
editor.setContents(
editor.clipboard.convert(data.data, 'silent'),
'silent'
);
- }else {
+ setTimeout(() => {
+ editor.focus();
+ editor.setSelection(editor.getText().length -1,0);
+ },0)
+
+
+
+ } else {
editor.setText(data.data, 'silent')
+ setTimeout(() => {
+ editor.focus();
+ editor.setSelection(editor.getText().length -1,0);
+ },0)
}
});
@@ -1421,7 +1454,7 @@ editor.on('text-change', function(delta, oldDelta, source) {
});
-
+
document.querySelectorAll('.ql-picker').forEach(e => {
e.addEventListener('mousedown',function(e) {
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index c32f2bd63..040954066 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -82,13 +82,17 @@ const Editor = ({navigation, noMenu}) => {
note = {};
saveCounter = 0;
- post('{}');
+ post('clear');
post(
JSON.stringify({
type: 'title',
value: null,
}),
);
+
+ wait(2000).then(() => {
+ post('focusTitle');
+ });
};
const onChange = data => {
@@ -160,6 +164,10 @@ const Editor = ({navigation, noMenu}) => {
};
const onWebViewLoad = () => {
+ EditorWebView.requestFocus();
+
+ console.log('requesting focus');
+
if (noMenu) {
post(
JSON.stringify({
@@ -181,6 +189,10 @@ const Editor = ({navigation, noMenu}) => {
updateEditor();
} else if (note && note.dateCreated) {
updateEditor();
+ } else {
+ wait(2000).then(() => {
+ post('focusTitle');
+ });
}
post(JSON.stringify(colors));
@@ -190,18 +202,36 @@ const Editor = ({navigation, noMenu}) => {
}, 1000);
};
+ const wait = timeout =>
+ new Promise((resolve, reject) => {
+ if (!timeout || typeof timeout !== 'number') reject();
+ setTimeout(() => {
+ resolve();
+ }, timeout);
+ });
+
const updateEditor = () => {
title = note.title;
timestamp = note.dateCreated;
content = note.content;
saveCounter = 0;
- post(JSON.stringify(note.content.delta));
- post(
- JSON.stringify({
- type: 'title',
- value: note.title,
- }),
- );
+
+ if (title !== null || title === '') {
+ post(
+ JSON.stringify({
+ type: 'title',
+ value: note.title,
+ }),
+ );
+ } else {
+ post('focusTitle');
+ post('clear');
+ }
+ if (note.content.text === '' || note.content.delta === null) {
+ post('clear');
+ } else {
+ post(JSON.stringify(note.content.delta));
+ }
};
const params = 'platform=' + Platform.OS;
@@ -381,8 +411,8 @@ const Editor = ({navigation, noMenu}) => {
Platform.OS === 'ios'
? sourceUri
: {
- uri: 'file:///android_asset/texteditor.html',
- baseUrl: 'file:///android_asset/',
+ uri: 'http://192.168.10.7:8080/texteditor.html',
+ baseUrl: 'http://192.168.10.7:8080/',
}
}
style={{
diff --git a/apps/mobile/src/views/Login/index.js b/apps/mobile/src/views/Login/index.js
index b4d9aa24e..e98856c40 100644
--- a/apps/mobile/src/views/Login/index.js
+++ b/apps/mobile/src/views/Login/index.js
@@ -1,20 +1,18 @@
import React, {createRef, useEffect} from 'react';
import {
+ BackHandler,
DeviceEventEmitter,
SafeAreaView,
Text,
TouchableOpacity,
View,
- BackHandler,
} from 'react-native';
import {TextInput} from 'react-native-gesture-handler';
-import {NavigationEvents} from 'react-navigation';
+import {useIsFocused} from 'react-navigation-hooks';
import {DDS} from '../../../App';
import {opacity, pv, SIZE, WEIGHT} from '../../common/common';
import {Header} from '../../components/header';
import {useTracked} from '../../provider';
-import NavigationService from '../../services/NavigationService';
-import {useIsFocused} from 'react-navigation-hooks';
export const Login = ({navigation}) => {
const [state, dispatch] = useTracked();