Skip to content

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

feat: add download image button in editor

ammarahm-edc0a94a212016
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.js
index 5762cf69b..2bfc958a9 100755
--- a/apps/mobile/html/Web.bundle/site/init.js
+++ b/apps/mobile/html/Web.bundle/site/init.js
@@ -235,7 +235,7 @@ function init_tiny(size) {
autoresize_bottom_margin: 120,
table_toolbar:
'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
- imagetools_toolbar: 'rotateleft rotateright flipv fliph | imageopts ',
+ imagetools_toolbar: 'imagedownload | rotateleft rotateright flipv fliph | imageopts ',
placeholder: 'Start writing your note here',
object_resizing: true,
resize: true,
@@ -317,6 +317,23 @@ function init_tiny(size) {
}
});
+ editor.ui.registry.addButton('imagedownload', {
+ icon: 'save',
+ tooltip: 'Download image',
+ onAction: function () {
+ let node = tinymce.activeEditor.selection.getNode();
+ if (node.tagName === 'IMG' && node.dataset && node.dataset.hash) {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'attachment_download',
+ value: node.dataset.hash
+ })
+ );
+ }
+ },
+ onclick: function () {}
+ });
+
editor.ui.registry.addButton('imagepreview', {
icon: 'fullscreen',
tooltip: 'Preview image',
diff --git a/apps/mobile/src/components/ImagePreview/index.js b/apps/mobile/src/components/ImagePreview/index.js
index f6f54f2b6..0021f41ae 100644
--- a/apps/mobile/src/components/ImagePreview/index.js
+++ b/apps/mobile/src/components/ImagePreview/index.js
@@ -47,6 +47,7 @@ const ImagePreview = () => {
enableSwipeDown
useNativeDriver
onSwipeDown={close}
+ saveToLocalByLongPress={false}
renderHeader={() => (
<View
style={{
@@ -77,6 +78,8 @@ const ImagePreview = () => {
}
]}
/>
+
+
</View>
</BaseDialog>
)
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js b/apps/mobile/src/views/Editor/tiny/toolbar/commands.js
index 2039c3185..95cecc2ac 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/commands.js
@@ -83,10 +83,11 @@ export const execCommands = {
imageResize50: () => setImageSize(0.5),
imageResize100: () => setImageSize(1),
imagepreview: `(function() {
- if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {
+ let node = tinymce.activeEditor.selection.getNode()
+ if (node.tagName === 'IMG') {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
-
+
xhr.onload = function () {
var recoveredBlob = xhr.response;
var reader = new FileReader();
@@ -105,7 +106,7 @@ export const execCommands = {
};
xhr.open(
'GET',
- tinymce.activeEditor.selection.getNode().getAttribute('src')
+ node.getAttribute('src')
);
xhr.send();
}