1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Resolves #2669: When attaching a file insert it at the current cursor position (#3189)

* When attaching an image/resource insert it at the current cursor position

* Correct argument order

* Address code review comments

* Another code review comment

Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
Roman Musin 2020-05-20 17:46:01 +01:00 committed by GitHub
parent 58396ea5ce
commit 9f7eeb0510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,6 +72,8 @@ class NoteScreenComponent extends BaseScreenComponent {
HACK_webviewLoadingState: 0,
};
this.selection = null;
this.markdownEditorRef = React.createRef(); // For focusing the Markdown editor
this.doFocusUpdate_ = false;
@ -291,6 +293,8 @@ class NoteScreenComponent extends BaseScreenComponent {
}
async UNSAFE_componentWillMount() {
this.selection = null;
BackButtonService.addHandler(this.backHandler);
NavService.addHandler(this.navHandler);
@ -556,7 +560,15 @@ class NoteScreenComponent extends BaseScreenComponent {
const resourceTag = Resource.markdownTag(resource);
const newNote = Object.assign({}, this.state.note);
if (this.state.mode == 'edit' && !Setting.value('editor.beta') && !!this.selection) {
const prefix = newNote.body.substring(0, this.selection.start);
const suffix = newNote.body.substring(this.selection.end);
newNote.body = `${prefix}\n${resourceTag}\n${suffix}`;
} else {
newNote.body += `\n${resourceTag}`;
}
this.setState({ note: newNote });
this.refreshResource(resource, newNote.body);
@ -979,7 +991,22 @@ class NoteScreenComponent extends BaseScreenComponent {
// a plain TextInput for now.
// See https://github.com/laurent22/joplin/issues/3041
(
<TextInput autoCapitalize="sentences" style={this.styles().bodyTextInput} ref="noteBodyTextField" multiline={true} value={note.body} onChangeText={(text) => this.body_changeText(text)} blurOnSubmit={false} selectionColor={theme.textSelectionColor} keyboardAppearance={theme.keyboardAppearance} placeholder={_('Add body')} placeholderTextColor={theme.colorFaded} />
<TextInput
autoCapitalize="sentences"
style={this.styles().bodyTextInput}
ref="noteBodyTextField"
multiline={true}
value={note.body}
onChangeText={(text) => this.body_changeText(text)}
onSelectionChange={({ nativeEvent: { selection } }) => {
this.selection = selection;
}}
blurOnSubmit={false}
selectionColor={theme.textSelectionColor}
keyboardAppearance={theme.keyboardAppearance}
placeholder={_('Add body')}
placeholderTextColor={theme.colorFaded}
/>
);
}