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.
This commit is contained in:
Don HO 2017-02-17 00:35:28 +01:00
parent 2f2b56eb43
commit f524dfaf06
6 changed files with 88 additions and 84 deletions

View File

@ -715,8 +715,6 @@ LRESULT Notepad_plus::init(HWND hwnd)
_dockingManager.setActiveTab(cti._cont, cti._activeTab); _dockingManager.setActiveTab(cti._cont, cti._activeTab);
} }
retrieveDefaultWordChars(nppGUI._defaultWordChars);
//Load initial docs into doctab //Load initial docs into doctab
loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW);
loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW);
@ -2686,38 +2684,40 @@ BOOL Notepad_plus::processIncrFindAccel(MSG *msg) const
return ::TranslateAccelerator(_incrementFindDlg.getHSelf(), _accelerator.getIncrFindAccTable(), msg); 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 //Add logic to prevent changing a language when a document is shared between two views
//If so, release one document //If so, release one document
bool reset = false; bool reset = false;
Document prev = 0; Document prev = 0;
if (bothActive()) { if (bothActive())
if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) { {
if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID())
{
reset = true; reset = true;
_subEditView.saveCurrentPos(); _subEditView.saveCurrentPos();
prev = _subEditView.execute(SCI_GETDOCPOINTER); prev = _subEditView.execute(SCI_GETDOCPOINTER);
_subEditView.execute(SCI_SETDOCPOINTER, 0, 0); _subEditView.execute(SCI_SETDOCPOINTER, 0, 0);
} }
} }
if (reset) {
if (reset)
{
_mainEditView.getCurrentBuffer()->setLangType(langType); _mainEditView.getCurrentBuffer()->setLangType(langType);
} else { }
/* 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);
*/
_pEditView->getCurrentBuffer()->setLangType(langType); _pEditView->getCurrentBuffer()->setLangType(langType);
} }
if (reset) { if (reset)
{
_subEditView.execute(SCI_SETDOCPOINTER, 0, prev); _subEditView.execute(SCI_SETDOCPOINTER, 0, prev);
_subEditView.restoreCurrentPos(); _subEditView.restoreCurrentPos();
} }
}; };
enum LangType Notepad_plus::menuID2LangType(int cmdID) LangType Notepad_plus::menuID2LangType(int cmdID)
{ {
switch (cmdID) switch (cmdID)
{ {
@ -6724,57 +6724,3 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
//return retVal; //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<LPARAM>(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<LPARAM>(nppGUI._defaultWordChars.c_str()));
_subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast<LPARAM>(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<LPARAM>(newCharList.c_str()));
_subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast<LPARAM>(newCharList.c_str()));
}
}

View File

@ -437,11 +437,10 @@ private:
void setLangStatus(LangType langType); void setLangStatus(LangType langType);
void setDisplayFormat(EolType f); void setDisplayFormat(EolType f);
int getCmdIDFromEncoding(int encoding) const;
void setUniModeText(); void setUniModeText();
void checkLangsMenu(int id) const ; void checkLangsMenu(int id) const ;
void setLanguage(LangType langType); void setLanguage(LangType langType);
enum LangType menuID2LangType(int cmdID); LangType menuID2LangType(int cmdID);
BOOL processIncrFindAccel(MSG *msg) const; BOOL processIncrFindAccel(MSG *msg) const;
BOOL processFindAccel(MSG *msg) const; BOOL processFindAccel(MSG *msg) const;
@ -533,7 +532,6 @@ private:
void doSynScorll(HWND hW); void doSynScorll(HWND hW);
void setWorkingDir(const TCHAR *dir); void setWorkingDir(const TCHAR *dir);
bool str2Cliboard(const generic_string & str2cpy); bool str2Cliboard(const generic_string & str2cpy);
bool bin2Cliboard(const UCHAR *uchar2cpy, size_t length);
bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible); bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible);
int getLangFromMenuName(const TCHAR * langName); int getLangFromMenuName(const TCHAR * langName);
@ -541,7 +539,6 @@ private:
generic_string exts2Filters(generic_string exts) const; generic_string exts2Filters(generic_string exts) const;
int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1); int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1);
void markSelectedTextInc(bool enable);
Style * getStyleFromName(const TCHAR *styleName); Style * getStyleFromName(const TCHAR *styleName);
bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func
void drawTabbarColoursFromStylerArray(); void drawTabbarColoursFromStylerArray();
@ -570,10 +567,6 @@ private:
static bool deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID); static bool deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID);
static bool selectBack(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) static int getRandomNumber(int rangeMax = -1)
{ {
int randomNumber = rand(); int randomNumber = rand();

View File

@ -1393,11 +1393,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_SETWORDCHARS: case NPPM_INTERNAL_SETWORDCHARS:
{ {
const NppGUI & nppGUI = pNppParam->getNppGUI(); _mainEditView.setWordChars();
if (nppGUI._isWordCharDefault) _subEditView.setWordChars();
restoreDefaultWordChars();
else
addCustomWordChars();
return TRUE; return TRUE;
} }

View File

@ -761,7 +761,6 @@ struct NppGUI final
bool _backSlashIsEscapeCharacterForSql = true; bool _backSlashIsEscapeCharacterForSql = true;
bool _isWordCharDefault = true; bool _isWordCharDefault = true;
std::string _defaultWordChars;
std::string _customWordChars; std::string _customWordChars;
// 0 : do nothing // 0 : do nothing

View File

@ -56,6 +56,8 @@ const int ScintillaEditView::_SC_MARGE_FOLDER = 2;
//const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3; //const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3;
WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL; WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL;
string ScintillaEditView::_defaultCharList = "";
/* /*
SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
@ -283,6 +285,14 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere)
_callWindowProc = CallWindowProc; _callWindowProc = CallWindowProc;
_scintillaDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(scintillaStatic_Proc))); _scintillaDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(scintillaStatic_Proc)));
if (_defaultCharList.empty())
{
auto defaultCharListLen = execute(SCI_GETWORDCHARS);
char *defaultCharList = new char[defaultCharListLen + 1];
execute(SCI_GETWORDCHARS, 0, reinterpret_cast<LPARAM>(defaultCharList));
_defaultCharList = defaultCharList;
delete[] defaultCharList;
}
//Get the startup document and make a buffer for it so it can be accessed like a file //Get the startup document and make a buffer for it so it can be accessed like a file
attachDefaultDoc(); attachDefaultDoc();
} }
@ -1182,6 +1192,57 @@ void ScintillaEditView::makeStyle(LangType language, const TCHAR **keywordArray)
} }
} }
void ScintillaEditView::restoreDefaultWordChars()
{
execute(SCI_SETWORDCHARS, 0, reinterpret_cast<LPARAM>(_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<LPARAM>(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) void ScintillaEditView::defineDocType(LangType typeDoc)
{ {
StyleArray & stylers = _pParameter->getMiscStylerArray(); StyleArray & stylers = _pParameter->getMiscStylerArray();
@ -1652,7 +1713,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer)
// Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function // Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function
// defineDocType() function should be called here, but not be after the fold info loop // defineDocType() function should be called here, but not be after the fold info loop
defineDocType(_currentBuffer->getLangType()); defineDocType(_currentBuffer->getLangType());
setTabSettings(_currentBuffer->getCurrentLang());
setWordChars();
if (_currentBuffer->getNeedsLexing()) { if (_currentBuffer->getNeedsLexing()) {
restyleBuffer(); restyleBuffer();

View File

@ -618,6 +618,11 @@ public:
}; };
void defineDocType(LangType typeDoc); //setup stylers for active document void defineDocType(LangType typeDoc); //setup stylers for active document
void addCustomWordChars();
void restoreDefaultWordChars();
void setWordChars();
void mouseWheel(WPARAM wParam, LPARAM lParam) { void mouseWheel(WPARAM wParam, LPARAM lParam) {
scintillaNew_Proc(_hSelf, WM_MOUSEWHEEL, wParam, lParam); scintillaNew_Proc(_hSelf, WM_MOUSEWHEEL, wParam, lParam);
}; };
@ -670,6 +675,8 @@ protected:
int _beginSelectPosition = -1; int _beginSelectPosition = -1;
static std::string _defaultCharList;
//Lexers and Styling //Lexers and Styling
void restyleBuffer(); void restyleBuffer();
const char * getCompleteKeywordList(std::basic_string<char> & kwl, LangType langType, int keywordIndex); const char * getCompleteKeywordList(std::basic_string<char> & kwl, LangType langType, int keywordIndex);