mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Mobile: Fixes #11539: Fix missing "Insert Time" button
This commit is contained in:
parent
9e80e2e072
commit
422a4732f3
@ -754,6 +754,7 @@ packages/app-mobile/components/screens/Note/Note.js
|
||||
packages/app-mobile/components/screens/Note/commands/attachFile.js
|
||||
packages/app-mobile/components/screens/Note/commands/hideKeyboard.js
|
||||
packages/app-mobile/components/screens/Note/commands/index.js
|
||||
packages/app-mobile/components/screens/Note/commands/insertDateTime.js
|
||||
packages/app-mobile/components/screens/Note/commands/setTags.js
|
||||
packages/app-mobile/components/screens/Note/commands/toggleVisiblePanes.js
|
||||
packages/app-mobile/components/screens/Note/types.js
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -730,6 +730,7 @@ packages/app-mobile/components/screens/Note/Note.js
|
||||
packages/app-mobile/components/screens/Note/commands/attachFile.js
|
||||
packages/app-mobile/components/screens/Note/commands/hideKeyboard.js
|
||||
packages/app-mobile/components/screens/Note/commands/index.js
|
||||
packages/app-mobile/components/screens/Note/commands/insertDateTime.js
|
||||
packages/app-mobile/components/screens/Note/commands/setTags.js
|
||||
packages/app-mobile/components/screens/Note/commands/toggleVisiblePanes.js
|
||||
packages/app-mobile/components/screens/Note/types.js
|
||||
|
@ -23,6 +23,8 @@ const builtInCommandNames = [
|
||||
EditorCommandType.IndentLess,
|
||||
EditorCommandType.IndentMore,
|
||||
'-',
|
||||
'insertDateTime',
|
||||
'-',
|
||||
EditorCommandType.EditLink,
|
||||
'setTags',
|
||||
EditorCommandType.ToggleSearch,
|
||||
|
@ -69,6 +69,10 @@ const emptyArray: any[] = [];
|
||||
|
||||
const logger = Logger.create('screens/Note');
|
||||
|
||||
interface InsertTextOptions {
|
||||
newLine?: boolean;
|
||||
}
|
||||
|
||||
interface Props extends BaseProps {
|
||||
provisionalNoteIds: string[];
|
||||
dispatch: Dispatch;
|
||||
@ -721,20 +725,21 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
|
||||
return await saveOriginalImage();
|
||||
}
|
||||
|
||||
private async insertText(text: string) {
|
||||
private async insertText(text: string, { newLine = false }: InsertTextOptions = {}) {
|
||||
const newNote = { ...this.state.note };
|
||||
const separator = newLine ? '\n' : '';
|
||||
|
||||
if (this.state.mode === 'edit') {
|
||||
let newText = '';
|
||||
|
||||
if (this.selection) {
|
||||
newText = `\n${text}\n`;
|
||||
newText = `${separator}${text}${separator}`;
|
||||
const prefix = newNote.body.substring(0, this.selection.start);
|
||||
const suffix = newNote.body.substring(this.selection.end);
|
||||
newNote.body = `${prefix}${newText}${suffix}`;
|
||||
} else {
|
||||
newText = `\n${text}`;
|
||||
newNote.body = `${newNote.body}\n${newText}`;
|
||||
newText = `${separator}${separator}${text}`;
|
||||
newNote.body = `${newNote.body}${newText}`;
|
||||
}
|
||||
|
||||
if (this.useEditorBeta()) {
|
||||
@ -747,7 +752,7 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newNote.body += `\n${text}`;
|
||||
newNote.body += `${separator}${text}`;
|
||||
}
|
||||
|
||||
this.setState({ note: newNote });
|
||||
@ -830,7 +835,7 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
|
||||
resource = await Resource.save(resource, { isNew: true });
|
||||
|
||||
const resourceTag = Resource.markupTag(resource);
|
||||
const newNote = await this.insertText(resourceTag);
|
||||
const newNote = await this.insertText(resourceTag, { newLine: true });
|
||||
|
||||
void this.refreshResource(resource, newNote.body);
|
||||
|
||||
@ -850,7 +855,7 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
|
||||
|
||||
private cameraView_onInsertBarcode = (data: string) => {
|
||||
this.setState({ showCamera: false });
|
||||
void this.insertText(data);
|
||||
void this.insertText(data, { newLine: true });
|
||||
};
|
||||
|
||||
private cameraView_onCancel() {
|
||||
|
@ -1,12 +1,14 @@
|
||||
// AUTO-GENERATED using `gulp buildScriptIndexes`
|
||||
import * as attachFile from './attachFile';
|
||||
import * as hideKeyboard from './hideKeyboard';
|
||||
import * as insertDateTime from './insertDateTime';
|
||||
import * as setTags from './setTags';
|
||||
import * as toggleVisiblePanes from './toggleVisiblePanes';
|
||||
|
||||
const index: any[] = [
|
||||
attachFile,
|
||||
hideKeyboard,
|
||||
insertDateTime,
|
||||
setTags,
|
||||
toggleVisiblePanes,
|
||||
];
|
||||
|
@ -0,0 +1,20 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
import { CommandRuntimeProps } from '../types';
|
||||
import time from '@joplin/lib/time';
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'insertDateTime',
|
||||
label: () => _('Insert time'),
|
||||
iconName: 'material calendar-plus',
|
||||
};
|
||||
|
||||
export const runtime = (props: CommandRuntimeProps): CommandRuntime => {
|
||||
return {
|
||||
execute: async (_context: CommandContext) => {
|
||||
props.insertText(time.formatDateToLocal(new Date()));
|
||||
},
|
||||
|
||||
enabledCondition: '!noteIsReadOnly',
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user