From f524dfaf067c9f654ec07752b0e3813189c27e82 Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 17 Feb 2017 00:35:28 +0100 Subject: [PATCH] Fix add char into word char list bug New word characters are applied only on the current document, not on the other documents or new opened document. --- PowerEditor/src/Notepad_plus.cpp | 84 ++++--------------- PowerEditor/src/Notepad_plus.h | 9 +- PowerEditor/src/NppBigSwitch.cpp | 7 +- PowerEditor/src/Parameters.h | 1 - .../ScitillaComponent/ScintillaEditView.cpp | 64 +++++++++++++- .../src/ScitillaComponent/ScintillaEditView.h | 7 ++ 6 files changed, 88 insertions(+), 84 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e1d088af..c50ea09f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -715,8 +715,6 @@ LRESULT Notepad_plus::init(HWND hwnd) _dockingManager.setActiveTab(cti._cont, cti._activeTab); } - retrieveDefaultWordChars(nppGUI._defaultWordChars); - //Load initial docs into doctab loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); @@ -2686,38 +2684,40 @@ BOOL Notepad_plus::processIncrFindAccel(MSG *msg) const return ::TranslateAccelerator(_incrementFindDlg.getHSelf(), _accelerator.getIncrFindAccTable(), msg); } -void Notepad_plus::setLanguage(LangType langType) { +void Notepad_plus::setLanguage(LangType langType) +{ //Add logic to prevent changing a language when a document is shared between two views //If so, release one document bool reset = false; Document prev = 0; - if (bothActive()) { - if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) { + if (bothActive()) + { + if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) + { reset = true; _subEditView.saveCurrentPos(); prev = _subEditView.execute(SCI_GETDOCPOINTER); _subEditView.execute(SCI_SETDOCPOINTER, 0, 0); } } - if (reset) { + + if (reset) + { _mainEditView.getCurrentBuffer()->setLangType(langType); - } else { - /* - int mode = _pEditView->execute(SCI_GETMODEVENTMASK, 0, 0); - _pEditView->execute(SCI_SETMODEVENTMASK, 0, 0); - _pEditView->getCurrentBuffer()->setLangType(langType); - _pEditView->execute(SCI_SETMODEVENTMASK, mode, 0); - */ + } + else + { _pEditView->getCurrentBuffer()->setLangType(langType); } - if (reset) { + if (reset) + { _subEditView.execute(SCI_SETDOCPOINTER, 0, prev); _subEditView.restoreCurrentPos(); } }; -enum LangType Notepad_plus::menuID2LangType(int cmdID) +LangType Notepad_plus::menuID2LangType(int cmdID) { switch (cmdID) { @@ -6724,57 +6724,3 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment) //return retVal; } -void Notepad_plus::retrieveDefaultWordChars(string & charList) -{ - auto defaultCharListLen = _mainEditView.execute(SCI_GETWORDCHARS); - char *defaultCharList = new char[defaultCharListLen + 1]; - _mainEditView.execute(SCI_GETWORDCHARS, 0, reinterpret_cast(defaultCharList)); - charList = defaultCharList; - delete[] defaultCharList; -} - -void Notepad_plus::restoreDefaultWordChars() -{ - NppParameters *pNppParam = NppParameters::getInstance(); - const NppGUI & nppGUI = pNppParam->getNppGUI(); - _mainEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(nppGUI._defaultWordChars.c_str())); - _subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(nppGUI._defaultWordChars.c_str())); -} - -void Notepad_plus::addCustomWordChars() -{ - NppParameters *pNppParam = NppParameters::getInstance(); - const NppGUI & nppGUI = pNppParam->getNppGUI(); - - if (nppGUI._customWordChars.empty()) - return; - - string chars2addStr; - for (size_t i = 0; i < nppGUI._customWordChars.length(); ++i) - { - bool found = false; - char char2check = nppGUI._customWordChars[i]; - for (size_t j = 0; j < nppGUI._defaultWordChars.length(); ++j) - { - char wordChar = nppGUI._defaultWordChars[j]; - if (char2check == wordChar) - { - found = true; - break; - } - } - if (not found) - { - chars2addStr.push_back(char2check); - } - } - - if (not chars2addStr.empty()) - { - string newCharList = nppGUI._defaultWordChars; - newCharList += chars2addStr; - - _mainEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(newCharList.c_str())); - _subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(newCharList.c_str())); - } -} diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 47d46d42..42b23a3e 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -437,11 +437,10 @@ private: void setLangStatus(LangType langType); void setDisplayFormat(EolType f); - int getCmdIDFromEncoding(int encoding) const; void setUniModeText(); void checkLangsMenu(int id) const ; void setLanguage(LangType langType); - enum LangType menuID2LangType(int cmdID); + LangType menuID2LangType(int cmdID); BOOL processIncrFindAccel(MSG *msg) const; BOOL processFindAccel(MSG *msg) const; @@ -533,7 +532,6 @@ private: void doSynScorll(HWND hW); void setWorkingDir(const TCHAR *dir); bool str2Cliboard(const generic_string & str2cpy); - bool bin2Cliboard(const UCHAR *uchar2cpy, size_t length); bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible); int getLangFromMenuName(const TCHAR * langName); @@ -541,7 +539,6 @@ private: generic_string exts2Filters(generic_string exts) const; int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1); - void markSelectedTextInc(bool enable); Style * getStyleFromName(const TCHAR *styleName); bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func void drawTabbarColoursFromStylerArray(); @@ -570,10 +567,6 @@ private: static bool deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID); static bool selectBack(ScintillaEditView *pCurrentView, BufferID targetBufID); - void retrieveDefaultWordChars(std::string & charList); - void addCustomWordChars(); - void restoreDefaultWordChars(); - static int getRandomNumber(int rangeMax = -1) { int randomNumber = rand(); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 4410479e..a7f8d21c 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1393,11 +1393,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_INTERNAL_SETWORDCHARS: { - const NppGUI & nppGUI = pNppParam->getNppGUI(); - if (nppGUI._isWordCharDefault) - restoreDefaultWordChars(); - else - addCustomWordChars(); + _mainEditView.setWordChars(); + _subEditView.setWordChars(); return TRUE; } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index cdc18e1a..68bdaf9e 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -761,7 +761,6 @@ struct NppGUI final bool _backSlashIsEscapeCharacterForSql = true; bool _isWordCharDefault = true; - std::string _defaultWordChars; std::string _customWordChars; // 0 : do nothing diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index a528d35f..46c61dc6 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -56,6 +56,8 @@ const int ScintillaEditView::_SC_MARGE_FOLDER = 2; //const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3; WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL; +string ScintillaEditView::_defaultCharList = ""; + /* SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree ------------------------------------------------------------------------------------------------------------- @@ -283,6 +285,14 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) _callWindowProc = CallWindowProc; _scintillaDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(scintillaStatic_Proc))); + if (_defaultCharList.empty()) + { + auto defaultCharListLen = execute(SCI_GETWORDCHARS); + char *defaultCharList = new char[defaultCharListLen + 1]; + execute(SCI_GETWORDCHARS, 0, reinterpret_cast(defaultCharList)); + _defaultCharList = defaultCharList; + delete[] defaultCharList; + } //Get the startup document and make a buffer for it so it can be accessed like a file attachDefaultDoc(); } @@ -1182,6 +1192,57 @@ void ScintillaEditView::makeStyle(LangType language, const TCHAR **keywordArray) } } +void ScintillaEditView::restoreDefaultWordChars() +{ + execute(SCI_SETWORDCHARS, 0, reinterpret_cast(_defaultCharList.c_str())); +} + +void ScintillaEditView::addCustomWordChars() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParam->getNppGUI(); + + if (nppGUI._customWordChars.empty()) + return; + + string chars2addStr; + for (size_t i = 0; i < nppGUI._customWordChars.length(); ++i) + { + bool found = false; + char char2check = nppGUI._customWordChars[i]; + for (size_t j = 0; j < _defaultCharList.length(); ++j) + { + char wordChar = _defaultCharList[j]; + if (char2check == wordChar) + { + found = true; + break; + } + } + if (not found) + { + chars2addStr.push_back(char2check); + } + } + + if (not chars2addStr.empty()) + { + string newCharList = _defaultCharList; + newCharList += chars2addStr; + execute(SCI_SETWORDCHARS, 0, reinterpret_cast(newCharList.c_str())); + } +} + +void ScintillaEditView::setWordChars() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParam->getNppGUI(); + if (nppGUI._isWordCharDefault) + restoreDefaultWordChars(); + else + addCustomWordChars(); +} + void ScintillaEditView::defineDocType(LangType typeDoc) { StyleArray & stylers = _pParameter->getMiscStylerArray(); @@ -1652,7 +1713,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer) // Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function // defineDocType() function should be called here, but not be after the fold info loop defineDocType(_currentBuffer->getLangType()); - setTabSettings(_currentBuffer->getCurrentLang()); + + setWordChars(); if (_currentBuffer->getNeedsLexing()) { restyleBuffer(); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 58e40daf..8fad9f00 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -618,6 +618,11 @@ public: }; void defineDocType(LangType typeDoc); //setup stylers for active document + + void addCustomWordChars(); + void restoreDefaultWordChars(); + void setWordChars(); + void mouseWheel(WPARAM wParam, LPARAM lParam) { scintillaNew_Proc(_hSelf, WM_MOUSEWHEEL, wParam, lParam); }; @@ -670,6 +675,8 @@ protected: int _beginSelectPosition = -1; + static std::string _defaultCharList; + //Lexers and Styling void restyleBuffer(); const char * getCompleteKeywordList(std::basic_string & kwl, LangType langType, int keywordIndex);