mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Electron: #22 Fixes keyboard cursor jumps while typing.
This commit is contained in:
parent
5e6a389f97
commit
e1b1f31cf1
@ -124,11 +124,15 @@ class NoteTextComponent extends React.Component {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
async reloadNote(props) {
|
||||
async reloadNote(props, options = null) {
|
||||
if (!options) options = {};
|
||||
if (!('noReloadIfLocalChanges' in options)) options.noReloadIfLocalChanges = false;
|
||||
|
||||
const noteId = props.noteId;
|
||||
this.lastLoadedNoteId_ = noteId;
|
||||
const note = noteId ? await Note.load(noteId) : null;
|
||||
if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading
|
||||
if (!options.noReloadIfLocalChanges && this.isModified()) return;
|
||||
|
||||
// If the note hasn't been changed, exit now
|
||||
if (this.state.note && note) {
|
||||
@ -166,7 +170,7 @@ class NoteTextComponent extends React.Component {
|
||||
}
|
||||
|
||||
if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) {
|
||||
await this.reloadNote(nextProps);
|
||||
await this.reloadNote(nextProps, { noReloadIfLocalChanges: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,11 +13,11 @@ shared.noteExists = async function(noteId) {
|
||||
shared.saveNoteButton_press = async function(comp) {
|
||||
let note = Object.assign({}, comp.state.note);
|
||||
|
||||
// Note has been deleted while user was modifying it. In that, we
|
||||
// Note has been deleted while user was modifying it. In that case, we
|
||||
// just save a new note by clearing the note ID.
|
||||
if (note.id && !(await shared.noteExists(note.id))) delete note.id;
|
||||
|
||||
reg.logger().info('Saving note: ', note);
|
||||
// reg.logger().info('Saving note: ', note);
|
||||
|
||||
if (!note.parent_id) {
|
||||
let folder = await Folder.defaultFolder();
|
||||
@ -46,9 +46,19 @@ shared.saveNoteButton_press = async function(comp) {
|
||||
|
||||
const savedNote = await Note.save(diff);
|
||||
|
||||
const stateNote = comp.state.note;
|
||||
// Re-assign any property that might have changed during saving (updated_time, etc.)
|
||||
note = Object.assign(note, savedNote);
|
||||
|
||||
if (stateNote) {
|
||||
// But we preserve the current title and body because
|
||||
// the user might have changed them between the time
|
||||
// saveNoteButton_press was called and the note was
|
||||
// saved (it's done asynchronously)
|
||||
note.title = stateNote.title;
|
||||
note.body = stateNote.body;
|
||||
}
|
||||
|
||||
comp.setState({
|
||||
lastSavedNote: Object.assign({}, note),
|
||||
note: note,
|
||||
@ -65,7 +75,7 @@ shared.saveOneProperty = async function(comp, name, value) {
|
||||
// just save a new note by clearing the note ID.
|
||||
if (note.id && !(await shared.noteExists(note.id))) delete note.id;
|
||||
|
||||
reg.logger().info('Saving note property: ', note.id, name, value);
|
||||
// reg.logger().info('Saving note property: ', note.id, name, value);
|
||||
|
||||
if (note.id) {
|
||||
let toSave = { id: note.id };
|
||||
|
Loading…
Reference in New Issue
Block a user