Skip to content

Commit

Permalink
qmdiEditor: set cursor position on deferred loading
Browse files Browse the repository at this point in the history
When introducing the defered loading in
5fda45e (see #17), the cursor position
was lost. Reintroduce it.

Fixes #17
  • Loading branch information
diegoiast committed Jan 21, 2025
1 parent de43351 commit 3948847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/widgets/qmdieditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ void qmdiEditor::hideTimer_timeout() {
}
}

void qmdiEditor::goTo(int x, int y) {
if (documentHasBeenLoaded) {
textEditor->goTo(x, y);
} else {
requestedPosition.setX(x);
requestedPosition.setY(y);
}
}

void qmdiEditor::focusInEvent(QFocusEvent *event) {

QWidget::focusInEvent(event);
Expand Down Expand Up @@ -975,6 +984,7 @@ void qmdiEditor::loadContent() {
auto textStream = QTextStream(&file);
textStream.seek(0);
textEditor->setPlainText(textStream.readAll());
textEditor->goTo(requestedPosition.x(), requestedPosition.y());

QFileInfo fileInfo(file);
file.close();
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/qmdieditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class qmdiEditor : public QWidget, public qmdiClient {
bool autoPreview = true;

// No longer inheriting Qutepart, instead use "static inheritance"
inline void goTo(int x, int y) { textEditor->goTo(x, y); }
void goTo(int x, int y);
inline void setLineWrapMode(QPlainTextEdit::LineWrapMode mode) {
textEditor->setLineWrapMode(mode);
}
Expand Down Expand Up @@ -177,6 +177,7 @@ class qmdiEditor : public QWidget, public qmdiClient {
bool fileModifications = true;
QTimer *loadingTimer = nullptr;
bool documentHasBeenLoaded = true;
QPoint requestedPosition;

QString fileName;
QMenu *bookmarksMenu;
Expand Down

0 comments on commit 3948847

Please sign in to comment.