mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
add back handler in editor
This commit is contained in:
@@ -51,9 +51,9 @@ class Commands {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
async doAsync(job: string) {
|
||||
async doAsync<T>(job: string) {
|
||||
if (!this.ref) return false;
|
||||
return await call(this.ref, fn(job));
|
||||
return call(this.ref, fn(job)) as Promise<T>;
|
||||
}
|
||||
|
||||
focus = async () => {
|
||||
@@ -132,22 +132,28 @@ statusBar.current.set({date:"",saved:""});
|
||||
};
|
||||
|
||||
insertAttachment = async (attachment: Attachment) => {
|
||||
this.doAsync(`editor && editor.commands.insertAttachment(${JSON.stringify(attachment)})`);
|
||||
await this.doAsync(`editor && editor.commands.insertAttachment(${JSON.stringify(attachment)})`);
|
||||
};
|
||||
|
||||
setAttachmentProgress = async (attachmentProgress: AttachmentProgress) => {
|
||||
this.doAsync(
|
||||
await this.doAsync(
|
||||
`editor && editor.commands.setAttachmentProgress(${JSON.stringify(attachmentProgress)})`
|
||||
);
|
||||
};
|
||||
|
||||
insertImage = async (image: ImageAttributes) => {
|
||||
console.log('image data', image);
|
||||
this.doAsync(`editor && editor.commands.insertImage(${JSON.stringify(image)})`);
|
||||
await this.doAsync(`editor && editor.commands.insertImage(${JSON.stringify(image)})`);
|
||||
};
|
||||
|
||||
updateImage = async (image: ImageAttributes) => {
|
||||
this.doAsync(`editor && editor.commands.updateImage(${JSON.stringify(image)})`);
|
||||
await this.doAsync(`editor && editor.commands.updateImage(${JSON.stringify(image)})`);
|
||||
};
|
||||
|
||||
handleBack = async () => {
|
||||
return this.doAsync<boolean>(
|
||||
`response = window.dispatchEvent(new Event("handleBackPress",{cancelable:true}));`
|
||||
);
|
||||
};
|
||||
//todo add replace image function
|
||||
}
|
||||
|
||||
@@ -130,6 +130,11 @@ export const useEditorEvents = (editor: useEditorType) => {
|
||||
}, [currentEditingNote, fullscreen, isPremium, readonly, editor.sessionId, editor.loading]);
|
||||
|
||||
const onBackPress = useCallback(async () => {
|
||||
const editorHandledBack = await editor.commands.handleBack();
|
||||
if (editorHandledBack) {
|
||||
logger.info('editor handled back event');
|
||||
return;
|
||||
}
|
||||
setTimeout(async () => {
|
||||
if (deviceMode !== 'mobile' && fullscreen) {
|
||||
if (fullscreen) {
|
||||
|
||||
Reference in New Issue
Block a user