From 82b2878fac7ac41c106a29ad385b5a0847df373c Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Thu, 5 May 2022 11:16:07 +0200 Subject: [PATCH] qmljseditor: preserve state when reformatting Only editing position was preserved (and incorrect column) when reformatting qml, preserve also scoll position (and correct column position). Fixes: QTCREATORBUG-25507 Change-Id: Ieaec2c5390e437f32b4b97b2bbb47975895f96d8 Reviewed-by: Reviewed-by: Ulf Hermann --- src/plugins/qmljseditor/qmljseditorplugin.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 5d4533230bb..8e6a466e8e0 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -289,10 +289,12 @@ void QmlJSEditorPluginPrivate::reformatFile() IEditor *ed = EditorManager::currentEditor(); if (ed) { + QByteArray state = ed->saveState(); int line = ed->currentLine(); int column = ed->currentColumn(); setNewText(); - ed->gotoLine(line, column); + ed->gotoLine(line, column - 1); + ed->restoreState(state); } else { setNewText(); }