fix merge editor

This commit is contained in:
ammarahm-ed
2020-11-29 12:35:55 +05:00
parent ceeb7a1468
commit 9cfcea0b4e
5 changed files with 43 additions and 23 deletions

View File

@@ -251,10 +251,12 @@ function attachEditorListeners() {
}); });
} }
} }
let infowords = document.getElementById('infowords');
document.getElementById('infowords').innerText = if (infowords) {
document.getElementById('infowords').innerText =
editor.getText().split(' ').length + ' words'; editor.getText().split(' ').length + ' words';
}
if (deltaTimeout) { if (deltaTimeout) {
clearTimeout(deltaTimeout); clearTimeout(deltaTimeout);
deltaTimeout = null; deltaTimeout = null;

View File

@@ -61,7 +61,7 @@
let Font = Quill.import('formats/font'); let Font = Quill.import('formats/font');
Font.whitelist = fontNames; Font.whitelist = fontNames;
Quill.register(Font, true); Quill.register(Font, true);
addLinkMatcher(); addLinkMatcher();
setTheme(); setTheme();
attachEditorListeners(); attachEditorListeners();

View File

@@ -249,8 +249,12 @@ function attachEditorListeners() {
} }
} }
document.getElementById('infowords').innerText = let infowords = document.getElementById('infowords');
if (infowords) {
document.getElementById('infowords').innerText =
editor.getText().split(' ').length + ' words'; editor.getText().split(' ').length + ' words';
}
if (deltaTimeout) { if (deltaTimeout) {
clearTimeout(deltaTimeout); clearTimeout(deltaTimeout);

View File

@@ -10,7 +10,7 @@
width: 100vw; width: 100vw;
white-space: nowrap; white-space: nowrap;
position: fixed; position: fixed;
height: 0px; height: 0px !important;
bottom: 0px; bottom: 0px;
left: 0px; left: 0px;
} }

View File

@@ -37,18 +37,19 @@ function openEditorAnimation(
heightToAnimate, heightToAnimate,
extendedHeight = null, extendedHeight = null,
siblingStatus, siblingStatus,
insets,
) { ) {
let openConfig = { let openConfig = {
duration: 300, duration: 300,
toValue: !siblingStatus toValue: !siblingStatus
? dHeight - (100 + windowInsets) ? dHeight - (100 + insets.top)
: dHeight * 0.5 - (50 + windowInsets / 2), : dHeight * 0.5 - (50 + insets.top / 2),
easing: Easing.inOut(Easing.ease), easing: Easing.inOut(Easing.ease),
}; };
let extendConfig = { let extendConfig = {
duration: 300, duration: 300,
toValue: dHeight * 0.5 - (50 + windowInsets / 2), toValue: dHeight * 0.5 - (50 + insets.top / 2),
easing: Easing.inOut(Easing.ease), easing: Easing.inOut(Easing.ease),
}; };
@@ -58,7 +59,7 @@ function openEditorAnimation(
timing(heightToAnimate, openConfig).start(); timing(heightToAnimate, openConfig).start();
} }
function closeEditorAnimation(heightToAnimate, heightToExtend = null) { function closeEditorAnimation(heightToAnimate, heightToExtend = null, insets) {
let closeConfig = { let closeConfig = {
duration: 300, duration: 300,
toValue: 0, toValue: 0,
@@ -67,11 +68,10 @@ function closeEditorAnimation(heightToAnimate, heightToExtend = null) {
let extendConfig = { let extendConfig = {
duration: 300, duration: 300,
toValue: dHeight - (100 + windowInsets), toValue: dHeight - (100 + insets.top),
easing: Easing.inOut(Easing.ease), easing: Easing.inOut(Easing.ease),
}; };
if (heightToExtend) { if (heightToExtend) {
extendConfig.toValue = dHeight - (100 + windowInsets);
timing(heightToExtend, extendConfig).start(); timing(heightToExtend, extendConfig).start();
} }
@@ -81,7 +81,6 @@ function closeEditorAnimation(heightToAnimate, heightToExtend = null) {
let primaryData = null; let primaryData = null;
let secondaryData = null; let secondaryData = null;
let windowInsets = 0;
const MergeEditor = () => { const MergeEditor = () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors} = state;
@@ -135,8 +134,10 @@ const MergeEditor = () => {
}; };
const onMessageFromPrimaryWebView = (evt) => { const onMessageFromPrimaryWebView = (evt) => {
console.log(evt.nativeEvent.data);
if (evt.nativeEvent.data !== '') { if (evt.nativeEvent.data !== '') {
let data = JSON.parse(evt.nativeEvent.data); let data = JSON.parse(evt.nativeEvent.data);
console.log(data);
if (data.type === 'delta') { if (data.type === 'delta') {
console.log(data.data); console.log(data.data);
primaryData = data.data; primaryData = data.data;
@@ -145,6 +146,7 @@ const MergeEditor = () => {
}; };
const onMessageFromSecondaryWebView = (evt) => { const onMessageFromSecondaryWebView = (evt) => {
console.log(data.data);
if (evt.nativeEvent.data === '') { if (evt.nativeEvent.data === '') {
let data = JSON.parse(evt.nativeEvent.data); let data = JSON.parse(evt.nativeEvent.data);
if (data.type === 'delta') { if (data.type === 'delta') {
@@ -204,20 +206,18 @@ const MergeEditor = () => {
note = item; note = item;
db.content; db.content;
let note = await db.content.raw(note.contentId); let note = await db.content.raw(note.contentId);
windowInsets = insets.top;
switch (note.type) { switch (note.type) {
case 'delta': case 'delta':
primaryData = note; primaryData = note;
secondaryData = note; secondaryData = note;
} }
setVisible(true); setVisible(true);
firstWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2)); firstWebViewHeight.setValue((dHeight / 2) - (50 + insets.top / 2));
secondWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2)); secondWebViewHeight.setValue((dHeight / 2) - (50 + insets.top / 2));
openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true); openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets);
}; };
useEffect(() => { useEffect(() => {
windowInsets = insets.top;
eSubscribeEvent(eApplyChanges, applyChanges); eSubscribeEvent(eApplyChanges, applyChanges);
eSubscribeEvent(eShowMergeDialog, show); eSubscribeEvent(eShowMergeDialog, show);
return () => { return () => {
@@ -229,10 +229,15 @@ const MergeEditor = () => {
const onPressKeepFromPrimaryWebView = () => { const onPressKeepFromPrimaryWebView = () => {
if (keepContentFrom == 'primary') { if (keepContentFrom == 'primary') {
setKeepContentFrom(null); setKeepContentFrom(null);
openEditorAnimation(firstWebViewHeight, secondWebViewHeight); openEditorAnimation(
firstWebViewHeight,
secondWebViewHeight,
false,
insets,
);
} else { } else {
setKeepContentFrom('primary'); setKeepContentFrom('primary');
closeEditorAnimation(firstWebViewHeight, secondWebViewHeight); closeEditorAnimation(firstWebViewHeight, secondWebViewHeight, insets);
} }
}; };
@@ -244,10 +249,15 @@ const MergeEditor = () => {
const onPressKeepFromSecondaryWebView = () => { const onPressKeepFromSecondaryWebView = () => {
if (keepContentFrom == 'secondary') { if (keepContentFrom == 'secondary') {
setKeepContentFrom(null); setKeepContentFrom(null);
openEditorAnimation(secondWebViewHeight, firstWebViewHeight); openEditorAnimation(
secondWebViewHeight,
firstWebViewHeight,
false,
insets,
);
} else { } else {
setKeepContentFrom('secondary'); setKeepContentFrom('secondary');
closeEditorAnimation(secondWebViewHeight, firstWebViewHeight); closeEditorAnimation(secondWebViewHeight, firstWebViewHeight, insets);
} }
}; };
@@ -278,7 +288,7 @@ const MergeEditor = () => {
primaryText = null; primaryText = null;
secondaryText = null; secondaryText = null;
note = null; note = null;
openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true); openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets);
}; };
const params = 'platform=' + Platform.OS; const params = 'platform=' + Platform.OS;
@@ -346,6 +356,7 @@ const MergeEditor = () => {
? secondWebViewHeight ? secondWebViewHeight
: null, : null,
secondary && keepContentFrom !== 'secondary', secondary && keepContentFrom !== 'secondary',
insets,
); );
setPrimary(true); setPrimary(true);
} else { } else {
@@ -354,6 +365,7 @@ const MergeEditor = () => {
secondary && keepContentFrom !== 'secondary' secondary && keepContentFrom !== 'secondary'
? secondWebViewHeight ? secondWebViewHeight
: null, : null,
insets,
); );
setPrimary(false); setPrimary(false);
} }
@@ -473,6 +485,7 @@ const MergeEditor = () => {
? firstWebViewHeight ? firstWebViewHeight
: null, : null,
primary && keepContentFrom !== 'primary', primary && keepContentFrom !== 'primary',
insets,
); );
setSecondary(true); setSecondary(true);
} else { } else {
@@ -481,6 +494,7 @@ const MergeEditor = () => {
primary && keepContentFrom !== 'primary' primary && keepContentFrom !== 'primary'
? firstWebViewHeight ? firstWebViewHeight
: null, : null,
insets,
); );
setSecondary(false); setSecondary(false);
} }