Skip to content

Commit e1b1f31

Browse files
committed
Electron: #22 Fixes keyboard cursor jumps while typing.
1 parent 5e6a389 commit e1b1f31

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

ElectronClient/app/gui/NoteText.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ class NoteTextComponent extends React.Component {
124124
}, 500);
125125
}
126126

127-
async reloadNote(props) {
127+
async reloadNote(props, options = null) {
128+
if (!options) options = {};
129+
if (!('noReloadIfLocalChanges' in options)) options.noReloadIfLocalChanges = false;
130+
128131
const noteId = props.noteId;
129132
this.lastLoadedNoteId_ = noteId;
130133
const note = noteId ? await Note.load(noteId) : null;
131134
if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading
135+
if (!options.noReloadIfLocalChanges && this.isModified()) return;
132136

133137
// If the note hasn't been changed, exit now
134138
if (this.state.note && note) {
@@ -166,7 +170,7 @@ class NoteTextComponent extends React.Component {
166170
}
167171

168172
if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) {
169-
await this.reloadNote(nextProps);
173+
await this.reloadNote(nextProps, { noReloadIfLocalChanges: true });
170174
}
171175
}
172176

ReactNativeClient/lib/components/shared/note-screen-shared.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ shared.noteExists = async function(noteId) {
1313
shared.saveNoteButton_press = async function(comp) {
1414
let note = Object.assign({}, comp.state.note);
1515

16-
// Note has been deleted while user was modifying it. In that, we
16+
// Note has been deleted while user was modifying it. In that case, we
1717
// just save a new note by clearing the note ID.
1818
if (note.id && !(await shared.noteExists(note.id))) delete note.id;
1919

20-
reg.logger().info('Saving note: ', note);
20+
// reg.logger().info('Saving note: ', note);
2121

2222
if (!note.parent_id) {
2323
let folder = await Folder.defaultFolder();
@@ -46,9 +46,19 @@ shared.saveNoteButton_press = async function(comp) {
4646

4747
const savedNote = await Note.save(diff);
4848

49+
const stateNote = comp.state.note;
4950
// Re-assign any property that might have changed during saving (updated_time, etc.)
5051
note = Object.assign(note, savedNote);
5152

53+
if (stateNote) {
54+
// But we preserve the current title and body because
55+
// the user might have changed them between the time
56+
// saveNoteButton_press was called and the note was
57+
// saved (it's done asynchronously)
58+
note.title = stateNote.title;
59+
note.body = stateNote.body;
60+
}
61+
5262
comp.setState({
5363
lastSavedNote: Object.assign({}, note),
5464
note: note,
@@ -65,7 +75,7 @@ shared.saveOneProperty = async function(comp, name, value) {
6575
// just save a new note by clearing the note ID.
6676
if (note.id && !(await shared.noteExists(note.id))) delete note.id;
6777

68-
reg.logger().info('Saving note property: ', note.id, name, value);
78+
// reg.logger().info('Saving note property: ', note.id, name, value);
6979

7080
if (note.id) {
7181
let toSave = { id: note.id };

0 commit comments

Comments
 (0)