Bug 459366 - KWrite remembers cursor position when closing the file and opening it again
Summary: KWrite remembers cursor position when closing the file and opening it again
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: kwrite (show other bugs)
Version: 22.08.1
Platform: Other FreeBSD
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-19 06:23 UTC by Gleb Popov
Modified: 2022-11-03 19:24 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gleb Popov 2022-09-19 06:23:01 UTC
SUMMARY
Starting with 22.08 KWrite started to remember cursor position and now opens files not from the beginning, but on the last remembered line.

STEPS TO REPRODUCE
1. Open a text file, which wasn't opened before.
2. Move the cursor somewhere in the middle by using mouse or arrow keys or PgUp/PgDn keys.
3. Close the application with Ctrl+Q or Alt+F4.
4. Open the same file again.

OBSERVED RESULT
The file gets opened at the last cursor position.

EXPECTED RESULT
The file opens from the beginning.

SOFTWARE/OS VERSIONS
KDE Frameworks Version: 5.97

ADDITIONAL INFORMATION
The bug doesn't manifest itself when the file is scrolled with mouse wheel but the cursor stays still.
The bug also doesn't show up if the file is closed with Close action (Ctrl+W)
Comment 1 Gleb Popov 2022-09-21 14:00:58 UTC
Another interesting finding. The bug manifests itself until I open some other file. That means that following scenario works fine.

1. Open a text file
2. Move the cursor
3. Close it
4. Open a different file
5. Close it too
6. Open the first one. The cursor is reset to the beginning of the file.

What's more interesting, omitting step 5 brings the bug back.
Comment 2 Unknown 2022-10-16 11:20:37 UTC
That's likely because of https://kate-editor.org/post/2022/2022-03-31-kate-ate-kwrite/

And, it seems, there is no way to prevent the "eaten" KWrite from remembering the cursor position. Now, Kate does have an option for that (Session -> Session Elements -> Include window configuration), but it also affects things like window size and position.

There should be a separate option for the cursor, methinks.
Comment 3 Gleb Popov 2022-10-17 08:26:50 UTC
(In reply to Hasshu from comment #2)
> That's likely because of
> https://kate-editor.org/post/2022/2022-03-31-kate-ate-kwrite/
> 
> And, it seems, there is no way to prevent the "eaten" KWrite from
> remembering the cursor position. Now, Kate does have an option for that
> (Session -> Session Elements -> Include window configuration), but it also
> affects things like window size and position.
> 
> There should be a separate option for the cursor, methinks.

"Session -> Session Elements -> Include window configuration" doesn't affect my problem. Even with this option disabled KWrite remembers cursor position.

Interestingly, the blog post you mention says that KWrite does not have sessions at all. Doesn't that mean that Kate's session settings should have no effect on KWrite?
Comment 4 Unknown 2022-10-17 14:25:21 UTC
(In reply to Gleb Popov from comment #3)
> "Session -> Session Elements -> Include window configuration" doesn't affect
> my problem. Even with this option disabled KWrite remembers cursor position.
> 
> Interestingly, the blog post you mention says that KWrite does not have
> sessions at all. Doesn't that mean that Kate's session settings should have
> no effect on KWrite?

It seems that my choice of words was a bit confusing. To rephrase: KWrite has become more similar to Kate, which includes remembering cursor position, and there appears to be no way to disable that (at all); such behavior can be disabled within Kate (for Kate only) via an option, but that would disable some other things as well. As such, I believe that both Kate and KWrite should have a dedicated option to never remember cursor position.
Comment 5 Matt Whitlock 2022-10-29 09:19:23 UTC
I'd request that restoration of the cursor position be a *variable* that can be configured per file mode. I can see it being useful for some filetypes, but it is extra annoying when I use KWrite as my $GIT_EDITOR and I start typing a Git commit message, only to discover that my cursor started up somewhere down in the comment block below the blank first line.

An alternative/additional suggestion would be to restore the cursor position upon load *only if* the file modification time matches what it was when the cursor position was saved. If the file had been modified in the interim, then the saved cursor position likely is garbage and should be disregarded.
Comment 6 Gleb Popov 2022-10-29 09:38:02 UTC
(In reply to Matt Whitlock from comment #5)
> ... it is extra annoying when I use KWrite as my $GIT_EDITOR and I start typing a Git commit message, only to discover that my cursor started up somewhere down in the comment block below the blank first line.

+1, I messed up an interactive rebase in the same way.
Comment 7 Christoph Cullmann 2022-10-29 17:33:20 UTC
Git commit aa1808649eaddf52ec309d4873c324b0dd48a810 by Christoph Cullmann.
Committed on 29/10/2022 at 17:32.
Pushed by cullmann into branch 'master'.

avoid that KWrite stores/restores view config

the setting is not there in the config dialog by design
the default value was not well choosen
just skip this for KWrite

M  +2    -2    apps/lib/session/katesessionmanager.cpp

https://invent.kde.org/utilities/kate/commit/aa1808649eaddf52ec309d4873c324b0dd48a810
Comment 8 Christoph Cullmann 2022-10-29 17:34:22 UTC
You are right, the idea was that this doesn't happen, but I failed to see that the default is just wrong for KWrite.
Comment 9 Unknown 2022-10-31 19:26:05 UTC
(In reply to Christoph Cullmann from comment #8)
> You are right, the idea was that this doesn't happen, but I failed to see
> that the default is just wrong for KWrite.

Thanks for the update!
Comment 10 Christoph Cullmann 2022-11-03 19:24:31 UTC
Git commit 5dac26e2b7747aab9a97a4eb516a83990d2122ed by Christoph Cullmann.
Committed on 03/11/2022 at 19:24.
Pushed by cullmann into branch 'master'.

skip only store/save of view manager internals for KWrite
Related: bug 461355

M  +10   -4    apps/lib/kateviewmanager.cpp

https://invent.kde.org/utilities/kate/commit/5dac26e2b7747aab9a97a4eb516a83990d2122ed