Skip to content

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

fix scroll to selection on focus

ammarahm-ed8a1d56160d78
diff --git a/apps/mobile/android/app/src/main/assets/listeners.js b/apps/mobile/android/app/src/main/assets/listeners.js
index d5f268431..2423633c0 100644
--- a/apps/mobile/android/app/src/main/assets/listeners.js
+++ b/apps/mobile/android/app/src/main/assets/listeners.js
@@ -85,140 +85,7 @@ function attachEditorListeners() {
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
- document.addEventListener('message', (data) => {
- let message = JSON.parse(data.data);
- let type = message.type;
- let value;
- if (message.value && message.type !== 'nomenu') {
- value = message.value;
- } else {
- value = message.value;
- }
- switch (type) {
- case 'reset': {
- editor.history.clear();
- editor.setText('', 'api');
- document.getElementById(titleInput).value = '';
- document.getElementById(titleInput).blur();
- editor.blur();
- document.getElementById(titleInput).blur();
- window.blur();
-
- info = document.querySelector(infoBar);
- info.querySelector('#infodate').innerText = '';
- info.querySelector('#infosaved').innerText = '';
- info.querySelector('#infowords').innerText = '';
- autosize();
- break;
- }
- case 'keyboard':
- var range = editor.getSelection();
- if (range) {
- if (range.length == 0) {
- var bounds = editor.getBounds(range.index, range.index);
-
- setTimeout(() => {
- document
- .querySelector('.app-main')
- .scrollTo({top: bounds.top, behavior: 'smooth'});
- }, 200);
- }
- }
- break;
- case 'blur':
- document.getElementById(titleInput).blur();
- editor.blur();
- window.blur();
- break;
- case 'undo':
- editor.history.undo();
- break;
- case 'redo':
- editor.history.redo();
- break;
- case 'clearHistory':
- editor.history.clear();
- break;
- case 'dateEdited':
- linfo = document.querySelector(infoBar);
- info.querySelector('#infodate').innerText = value;
- break;
- case 'saving':
- info = document.querySelector(infoBar);
- info.querySelector('#infosaved').innerText = value;
- break;
- case 'text':
- editor.setText(value, 'api');
-
- setTimeout(() => {
- info = document.querySelector(infoBar);
- info.querySelector('#infowords').innerText =
- editor.getText().split(' ').length + ' words';
- info.querySelector('#infosaved').innerText = 'Saved';
- }, 100);
-
- break;
- case 'clearEditor':
- editor.setText('', 'api');
- break;
- case 'clearTitle':
- document.getElementById(titleInput).value = '';
- break;
- case 'focusEditor':
- editor.focus();
- break;
- case 'focusTitle':
- document.getElementById(titleInput).focus();
- autosize();
- break;
- case 'nomenu':
- let isenabled = value;
- //let width = window.innerWidth;
- let titleIn = document.getElementById('titlebar');
- if (isenabled) {
- //titleIn.style.width = width;
- titleIn.style['padding-left'] = 12;
- titleIn.style['padding-right'] = window.innerWidth * 0.4;
- } else {
- //titleIn.style.width = width - 120;
- titleIn.style['padding-left'] = 60;
- titleIn.style['padding-right'] = window.innerWidth * 0.4;
- }
- break;
- case 'title':
- document.getElementById(titleInput).value = JSON.parse(data.data).value;
- autosize();
- break;
- case 'theme':
- pageTheme.colors = value;
- setTheme();
- break;
-
- case 'delta':
- const content = value;
- editor.setContents(content, 'api');
-
- setTimeout(() => {
- info = document.querySelector(infoBar);
- info.querySelector('#infowords').innerText =
- editor.getText().split(' ').length + ' words';
- info.querySelector('#infosaved').innerText = 'Saved';
- document.body.scrollTop = 0; // For Safari
- document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
- }, 100);
- autosize();
- break;
- case 'html':
- editor.setContents(editor.clipboard.convert(value, 'api'), 'silent');
- /* setTimeout(() => {
- editor.setSelection(editor.getText().length - 1, 0);
- }, 0); */
- break;
- default:
- break;
- }
- });
function isWhitespace(ch) {
let whiteSpace = false;
@@ -328,17 +195,18 @@ function attachMessageListener() {
}
case 'keyboard':
var range = editor.getSelection();
+
if (range) {
- if (range.length == 0) {
- var bounds = editor.getBounds(range.index, range.index);
+ if (range.length === 0) {
+ let correction = isTablet ? 265 : 110;
setTimeout(() => {
document
- .querySelector('.app-main')
- .scrollTo({top: bounds.top, behavior: 'smooth'});
- }, 200);
+ .querySelector('.app-main')
+ .scrollTo({top: editor.getBounds(editor.getSelection().index).bottom - (window.innerHeight - correction), behavior: "smooth"});
+ }, 200);
}
- }
+ }
break;
case 'blur':
document.getElementById(titleInput).blur();
diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.js
index 2c478ec72..62437ba2e 100644
--- a/apps/mobile/html/Web.bundle/site/listeners.js
+++ b/apps/mobile/html/Web.bundle/site/listeners.js
@@ -85,8 +85,6 @@ function attachEditorListeners() {
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
-
-
function isWhitespace(ch) {
let whiteSpace = false;
if (ch === ' ' || ch === '\t' || ch === '\n') {
@@ -131,8 +129,7 @@ function attachEditorListeners() {
info = document.querySelector(infoBar);
let infowords = info.querySelector('#infowords');
if (infowords) {
- infowords.innerText =
- editor.getText().split(' ').length + ' words';
+ infowords.innerText = editor.getText().split(' ').length + ' words';
}
if (deltaTimeout) {
@@ -166,7 +163,7 @@ function attachEditorListeners() {
function attachMessageListener() {
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
- infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
+ infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
window.addEventListener('message', (data) => {
let message = JSON.parse(data.data);
let type = message.type;
@@ -197,12 +194,16 @@ function attachMessageListener() {
var range = editor.getSelection();
if (range) {
if (range.length == 0) {
- var bounds = editor.getBounds(range.index, range.index);
-
+ let correction = isTablet ? 265 : 110;
setTimeout(() => {
document
.querySelector('.app-main')
- .scrollTo({top: bounds.top, behavior: 'smooth'});
+ .scrollTo({
+ top:
+ editor.getBounds(editor.getSelection().index).bottom -
+ (window.innerHeight - correction),
+ behavior: 'smooth',
+ });
}, 200);
}
}
@@ -236,7 +237,7 @@ function attachMessageListener() {
info = document.querySelector(infoBar);
info.querySelector('#infowords').innerText =
editor.getText().split(' ').length + ' words';
- info.querySelector('#infosaved').innerText = 'Saved';
+ info.querySelector('#infosaved').innerText = 'Saved';
}, 100);
break;
@@ -284,7 +285,7 @@ function attachMessageListener() {
info = document.querySelector(infoBar);
info.querySelector('#infowords').innerText =
editor.getText().split(' ').length + ' words';
- info.querySelector('#infosaved').innerText = 'Saved';
+ info.querySelector('#infosaved').innerText = 'Saved';
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera