Version: (using KDE Devel) Installed from: Compiled sources Summary: - API to get the current x/y scrolling position of the view (in pixels) - API to set a new x/y scrolling position of the view (in pixels) - and / or, API to set cursor position without scrolling - probably something for KDE4 Rationale: I wrote a mail about this to kwrite-devel a while ago (http://lists.kde.org/?l=kwrite-devel&m=116109849704307&w=2). Copying the contents to this bug report: In RKWard, we're (mis-)using a KatePart to provide a console emulation with syntax highlighting (R language). One thing we'd like to do in this scenario is to prevent the cursor from ever leaving the bottom-most line. We can catch all KeyUp-presses, but for mouse presses things are a little more complicated. After all, the user should be able to select text anywhere in the console, only the cursor should not move in this case. What I tried to do was to simply make sure the cursor is set back to the last line after each mouse-button release (using setCursorPosition ()). This works in principle, but has the side effect of always scrolling back down to the last line, even if (e.g.) some text was selected near the top of the document. Is there a way to set the cursor position without scrolling the view? Alternatively, is there a way to determine the current scrolling position of a Kate::View, so I can save that position before moving the cursor, and restore it afterwards?
Thomas, if you still need that, it should be done for KDE 5. What functions do you need exaclty? KTextEditor::View::scrollUp(), pageUp(), toTop() or something like that?
Hi Dominik, this is not a high priority, but yes, this would still be nice to have. Basically, the use case that I have, goes like this: QPoint saved_pos = KTextEditor::View::currentScrollPosition(); // do something which may affect scrolling position, implicitly KTextEditor::View::setScrollPosition(saved_pos); This is assuming pixel based positions. However, thinking about it, scrolling could also be based on the cursor position (at the top-left corner of the viewport). This would be almost as good for my use-case, and would conceivably come in handy in many other situations, as well. I.e.: /** Return the cursor position at the top left of the view. */ KTextEditor::Cursor KTextEditor::View::currentScrollPosition(); /** Scroll the view so that pos is visible at the top left corner of the view, without changing the active cursor position. @note: If the given position is near the bottom / right of the document, the actual scrolling position may be adjusted to the top / left. However, it is guaranteed that the given cursor position will be inside the visible range, after scrolling. */ KTextEditor::View::setScrollPosition(const KTextEditor::Cursor &pos);
How to interpret columns in the position is clear for fixed fonts, but not for non-fixed fonts. If it's only about lines, simple ints for the lines would be enough. If you build Kate according to http://www.kate-editor.org/get-it/, you can run your RKWard with ./run.sh rkward (or the correct app name), and the new Kate Part will be loaded. This way, you can very easily provide a patch that works for you, if you want.
Created attachment 63849 [details] Untested patch At this moment, kate git does not compile for me due to an unrelated problem. Therefore, the patch I'm attaching is entirely untested. But if my guesses aren't entirely wrong, then it's actually quite simple, since KateViewInternal already provides this functionality. Pulling KateViewInternal::makeVisible() into the public API (perhaps as KTextEditor::View::ensurePositionVisible()) might also be worth while.
In KF5 we can very easy add that functions, if they really do the job, can somebody test that?
From the initial posting, I guess this is related to BUG: 399014 BUG: 306745 or better, it may fixed by the Patch https://phabricator.kde.org/D17857
Frankly, I'm not sure, I understand that PR. However, to clarify, my (somewhat esoteric) usecase: 1) User selects something near the top of the document, implicitly changing cursor position. 2) I need to set the cursor back to the very end of the document (not editing anything, though). I would like to have a way to accomplish step 2 *without* apparent scrolling, i.e. the view should remain scrolled where ever it was scrolled to by the user. It should not jump to make last line visible.
OK. Then I may misunderstood something. You mentioned "using setCursorPosition()" and I had a change noted there https://phabricator.kde.org/D17857#425268 Not sure that this effect your wish. Can you try it? Since 2006 there may have many thing changed. Perhaps is something new in stock to solve you problem(?)
Since the request is about "low-level" api, please have a look at the class "KateScrollBarRestorer" in the patch here: https://invent.kde.org/utilities/kate/-/merge_requests/556