glushchenko / fsnotes

Notes manager for macOS/iOS
https://fsnot.es
MIT License
6.18k stars 453 forks source link

Cursor jumps to the beginning of the Note #1683

Closed nburyak closed 5 months ago

nburyak commented 5 months ago

Description

The cursor jumps to the beginning of the Note every time, when the title of the Note gets updated

To Reproduce

  1. Create new Note
  2. Start typing the text Actual Result: Every time, when the title of the Note gets updated, the cursor jumps to the beginning of the Note

https://github.com/glushchenko/fsnotes/assets/2462403/d121acfa-2f93-4060-8774-fad46d6c00d3

Expected behavior

The cursor should never be automatically moved during typing

FSNotes version

Version 6.6.6 (610) - (AppStore version)

macOS/iOS version

macOS 14.2.1 (23C71)

Additional context

No response

glushchenko commented 5 months ago

Can not reproduce it.

Try to change storage path to path without emoji.

nburyak commented 5 months ago

Unfortunately, neither changing the location to default (which was actually set), nor removing the emojis in the path didn‘t help. Let me debug, maybe I‘ll find the rootcause

gingerbeardman commented 5 months ago

Also cannot reproduce. Please share a reproducible set of notes/folders.

You can also create a new user account on the same Mac to check if it happens there. If not, the problem is an app running in your user account.

nburyak commented 5 months ago

I've debugged the code and figured out the following: while typing the text the Note gets reloaded and the cursor changes its position to 0 or previously saved position depending on the restoreCursorPosition value. I assume, this happens every time when the Note is saved to the file.

Here's the stack trace and the exact place of code, which causes cursor jumping during typing:

image

Another observation is restoring the position, which is different from the saved one. And this happens exactly during typing text (as I described above):

func saveCursorPosition() {
    ...
    NSLog(">>> saveCursorPosition:    \(length)")
    ...
}

func restoreCursorPosition() {
    ...
    NSLog(">>> restoreCursorPosition: \(position)")
    ...
}
2024-01-24 19:38:26.438408+0100 FSNotes[19008:5384306] >>> saveCursorPosition:    16
2024-01-24 19:38:26.712355+0100 FSNotes[19008:5384306] >>> saveCursorPosition:    17
2024-01-24 19:38:27.030987+0100 FSNotes[19008:5384306] >>> restoreCursorPosition: 8
nburyak commented 5 months ago

I have a suspicion, the issue is related to the iCloud backup. Once I moved the Notes Storage outside of the iCloud folder, the issue was gone. Obviously, it doesn't help much because I want to sync my notes with the mobile phone. But this narrows down the problem

glushchenko commented 5 months ago

What about this option in the Settings? Did you try to enable it?

image
nburyak commented 5 months ago

What about this option in the Settings? Did you try to enable it?

image

https://github.com/glushchenko/fsnotes/assets/2462403/f53d590e-05b0-4270-a3fd-63cb14144e94

With the Restore cursor position setting ON the cursor jumps a few symbols to the right, which is even worse, than jumping to the beginning of the Note.

I've posted the logs above: the cursor position in the func restoreCursorPosition() isn't same, as the last saved value in func saveCursorPosition(). It's definitely related to the iCloud sync but I can't find out how to fix this.

glushchenko commented 5 months ago

@nburyak please check this experimental build:

FSNotes_6.6.7.zip

nburyak commented 5 months ago

Hi @glushchenko, thanks for the fix. I've just tested it - works much better now and doesn't mess with the text anymore 👍

Although, you may still notice a small glitch: in the word fixed I type the x character, then it disappears and re-appears again. I'd consider it a minor issue.

https://github.com/glushchenko/fsnotes/assets/2462403/45bbebe9-8436-4b4d-857f-5713ffcb4a92

glushchenko commented 5 months ago

OK, another try. Please test it and let me know.

FSNotes_6.6.7.zip

nburyak commented 5 months ago

@glushchenko Thanks for the build - I can confirm, that in the latest version the issue is completely gone ✅

Is this fix planned for any of the upcoming AppStore releases?

glushchenko commented 5 months ago

Is this fix planned for any of the upcoming AppStore releases?

Yes

glushchenko commented 5 months ago

Fixed here:

https://github.com/glushchenko/fsnotes/releases/download/6.6.7/FSNotes_6.6.7.zip