Open acrothoi2 opened 7 years ago
So this requires a note, which is long enough for the window to need scrolling. Cursor would be somewhere at the beginning, then user scrolls down (so the cursor is off-screen), right-clicks on the misspelled word and replaces it. At that point the viewport (i.e. the currently shown part of the note) refreshes and it jumps back to the cursor position.
After looking into this, I don't think we can fix it in a way that it stops "jumping" there. That effect is merely a consequence of gtkspell deleting a misspelled word and the inserting a new one - and it does it directly on the GTK TextBuffer object:
gtk_text_buffer_begin_user_action (spell->priv->buffer);
gtk_text_buffer_delete (spell->priv->buffer, &start, &end);
gtk_text_buffer_insert (spell->priv->buffer, &start, newword, -1);
gtk_text_buffer_end_user_action (spell->priv->buffer);
And that AFAIU just causes the TextBuffer refresh, which - as the cursor position did not change - makes it show the cursor.
Moreover, they don't move the cursor intentionally:
/* when the user right-clicks on a word, they want to check that word.
* here, we do NOT move the cursor to the location of the clicked-upon word
* since that prevents the use of edit functions on the context menu. */
We probably could try to do the opposite - i.e. change the active cursor position and set it to the corrected word (the beginning or the end of it). Then at least the cursor will be right there where the last text operation has happened and there will be no viewport jumping. The only thing is that I don't see any technical way of telling that it was a gtkspell-induced text change and not the usual edit - because of the abovementioned mechanism used by gtkspell. There are no "replacement just happend" events or anything like this.
All in all I think the only thing we could realistically do here is to move the cursor to any right-click location, which also has its drawbacks. Let me know what you think, @acrothoi2 and if anyone else has any ideas - please feel free to chime in.
hmmm ... it seems like the bug is in gtk, if i'm understanding you correctly?
i tested to see if this issue exists in another gtk applicaiton (other than tomboy (gtk2) and gnote (gtk3)) -- I tried in Mate Desktop's Pluma text editor (gtk3), and it does not have this issue (and the cursor position doesn't get changed (at least not permanently)). it may be worth looking into what the difference is, or if they're implementing their own workaround?
Well, the case is that's not a bug per se, it's very much "works as designed" for both the gtkspell and GTK+ TextBuffer, just that this specific flow with combination of both causes this effect, which may be unexpected. You haven't mentioned gnote in this particular issue's initial description, but your last comment suggests this does not happen there, right? I'll take a look at Pluma, thanks for the suggestion.
the issue exists in gnote as well as tomboy -- I was pointing this out to clarify that this is not specific to a particular version of gtk (Pluma is gtk3, like gnote, but unlike tomboy).
Understood, thanks for clarification, that's valuable information.
when you correct spelling by right-clicking on a word with the red squiggly line underneath it, the correction takes effect as it should, however, tomboy gets scrolled to the cursor position (which isn't necessarily on the same line, since you only need to right-click to correct spelling, whereas left click changes cursor position).
to reproduce: have a word mispelled somewhere down a ways in the note. now scroll up to the top of the note and put your cursor on a line up there. now scroll down to the misspelling, and (without changing your cursor position by left clicking anywhere) right-click on the misspelling and select the correct spelling. at this point you get scrolled all the way back up, which is a bit disorienting and inconvenient.