From 87db9d1957b45299003ee32fa46cbd42d0b88c42 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 28 Dec 2021 19:56:05 +0100 Subject: [PATCH] Fix caret left-right inverse moving in R2L mode issue ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/10334#issuecomment-1002054488 Fix #8553, fix #7678, fix #9730, close #10963 --- PowerEditor/src/Notepad_plus.cpp | 8 ++++- PowerEditor/src/Notepad_plus_Window.cpp | 2 +- PowerEditor/src/NppCommands.cpp | 19 ++++++++++-- .../src/ScintillaComponent/FindReplaceDlg.cpp | 11 +++++-- .../ScintillaComponent/ScintillaEditView.cpp | 31 ++++++++++++++++++- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0798c9132..c1a859715 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -726,9 +726,15 @@ LRESULT Notepad_plus::init(HWND hwnd) loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); - //::SetFocus(_mainEditView.getHSelf()); + _mainEditView.getFocus(); + if (_nativeLangSpeaker.isRTL()) + { + _mainEditView.changeTextDirection(true); + _subEditView.changeTextDirection(true); + } + return TRUE; } diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 1650aa0ed..0f8277f3f 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -101,7 +101,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin _hIconAbsent = ::LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICONABSENT)); _hSelf = ::CreateWindowEx( - WS_EX_ACCEPTFILES | (_notepad_plus_plus_core._nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0), + WS_EX_ACCEPTFILES | (_notepad_plus_plus_core._nativeLangSpeaker.isRTL() ? WS_EX_LAYOUTRTL : 0), _className, TEXT("Notepad++"), (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN), diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index b97bda446..4de7cc96f 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -3471,15 +3471,30 @@ void Notepad_plus::command(int id) case IDM_EDIT_RTL : case IDM_EDIT_LTR : { - _pEditView->changeTextDirection(id == IDM_EDIT_RTL); + bool toRTL = id == IDM_EDIT_RTL; + bool isRTL = _pEditView->isTextDirectionRTL(); + + if ((toRTL && isRTL) || (!toRTL && !isRTL)) + { + if (! ((NppParameters::getInstance()).getNppGUI())._muteSounds) + ::MessageBeep(MB_OK); + break; + } + + _pEditView->changeTextDirection(toRTL); + _pNonEditView->changeTextDirection(toRTL); // Wrap then !wrap to fix problem of mirror characters bool isWraped = _pEditView->isWrap(); _pEditView->wrap(!isWraped); _pEditView->wrap(isWraped); + + _pNonEditView->wrap(!isWraped); + _pNonEditView->wrap(isWraped); + if (_pDocMap) { - _pDocMap->changeTextDirection(id == IDM_EDIT_RTL); + _pDocMap->changeTextDirection(toRTL); } } break; diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 50ff113f1..8f6e5bb0b 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -2704,8 +2704,12 @@ void FindReplaceDlg::findAllIn(InWhat op) generic_string text = _pFinder->getHitsString(_findAllResult); wsprintf(_findAllResultStr, text.c_str()); - bool isRTL = (*_ppEditView)->isTextDirectionRTL(); - _pFinder->_scintView.changeTextDirection(isRTL); + bool toRTL = (*_ppEditView)->isTextDirectionRTL(); + bool isRTL = _pFinder->_scintView.isTextDirectionRTL(); + + if ((toRTL && !isRTL) || (!toRTL && isRTL)) + _pFinder->_scintView.changeTextDirection(toRTL); + if (_findAllResult) { focusOnFinder(); @@ -2752,7 +2756,8 @@ Finder * FindReplaceDlg::createFinder() ::SendMessage(_hParent, NPPM_DMMREGASDCKDLG, 0, reinterpret_cast(&data)); pFinder->_scintView.init(_hInst, pFinder->getHSelf()); - pFinder->_scintView.changeTextDirection(isRTL); + if (isRTL) + pFinder->_scintView.changeTextDirection(true); // Subclass the ScintillaEditView for the Finder (Scintilla doesn't notify all key presses) originalFinderProc = SetWindowLongPtr(pFinder->_scintView.getHSelf(), GWLP_WNDPROC, reinterpret_cast(finderProc)); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 6020d1d63..84132b3bb 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -3658,8 +3658,37 @@ bool ScintillaEditView::isTextDirectionRTL() const void ScintillaEditView::changeTextDirection(bool isRTL) { long exStyle = static_cast(::GetWindowLongPtr(_hSelf, GWL_EXSTYLE)); - exStyle = isRTL ? exStyle | WS_EX_LAYOUTRTL : exStyle&(~WS_EX_LAYOUTRTL); + exStyle = isRTL ? (exStyle | WS_EX_LAYOUTRTL) : (exStyle & (~WS_EX_LAYOUTRTL)); ::SetWindowLongPtr(_hSelf, GWL_EXSTYLE, exStyle); + + if (isRTL) + { + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT, SCI_CHARLEFT); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + (SCMOD_SHIFT << 16), SCI_CHARLEFTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + ((SCMOD_SHIFT + SCMOD_ALT) << 16), SCI_CHARLEFTRECTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + (SCMOD_CTRL << 16), SCI_WORDLEFT); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + ((SCMOD_SHIFT + SCMOD_CTRL) << 16), SCI_WORDLEFTEXTEND); + + execute(SCI_ASSIGNCMDKEY, SCK_LEFT, SCI_CHARRIGHT); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + (SCMOD_SHIFT << 16), SCI_CHARRIGHTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + ((SCMOD_SHIFT + SCMOD_ALT) << 16), SCI_CHARRIGHTRECTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + (SCMOD_CTRL << 16), SCI_WORDRIGHT); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + ((SCMOD_SHIFT + SCMOD_CTRL) << 16), SCI_WORDRIGHTEXTEND); + } + else + { + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT, SCI_CHARRIGHT); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + (SCMOD_SHIFT << 16), SCI_CHARRIGHTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + ((SCMOD_SHIFT + SCMOD_ALT) << 16), SCI_CHARRIGHTRECTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + (SCMOD_CTRL << 16), SCI_WORDRIGHT); + execute(SCI_ASSIGNCMDKEY, SCK_RIGHT + ((SCMOD_SHIFT + SCMOD_CTRL) << 16), SCI_WORDRIGHTEXTEND); + + execute(SCI_ASSIGNCMDKEY, SCK_LEFT, SCI_CHARLEFT); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + (SCMOD_SHIFT << 16), SCI_CHARLEFTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + ((SCMOD_SHIFT + SCMOD_ALT) << 16), SCI_CHARLEFTRECTEXTEND); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + (SCMOD_CTRL << 16), SCI_WORDLEFT); + execute(SCI_ASSIGNCMDKEY, SCK_LEFT + ((SCMOD_SHIFT + SCMOD_CTRL) << 16), SCI_WORDLEFTEXTEND); + } } generic_string ScintillaEditView::getEOLString()