From f027e9271dc64aab3532fdf580741511600b3324 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Mon, 9 Nov 2020 14:38:23 -0500 Subject: [PATCH] Disallow Goto dlg offset option from moving to position inside multibyte char or between CR and LF Fix #9101, fix #9125, close #9129 --- PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp index 6770c3c0..ec0735cb 100644 --- a/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp @@ -62,11 +62,19 @@ INT_PTR CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) } else { - auto sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, line); + int posToGoto = 0; + if (line > 0) + { + // make sure not jumping into the middle of a multibyte character + // or into the middle of a CR/LF pair for Windows files + auto before = (*_ppEditView)->execute(SCI_POSITIONBEFORE, line); + posToGoto = static_cast((*_ppEditView)->execute(SCI_POSITIONAFTER, before)); + } + auto sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, posToGoto); (*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line); - (*_ppEditView)->execute(SCI_GOTOPOS, line); + (*_ppEditView)->execute(SCI_GOTOPOS, posToGoto); } - } + } SCNotification notification = {}; notification.nmhdr.code = SCN_PAINTED;