mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-09-25 19:08:47 +02:00
Fix JavaScript indent settings incorrect behaviour
1. More understandable naming: "javascript.js" to "JavaScript". 2. Disassociate the value of Embedded JS & JavaScript, and remove Embedded JS from the list. 3. Prevent from eventual crash due to null pointer. Fix #16884, close #16885
This commit is contained in:
parent
c710439b51
commit
76c3e30fe3
@ -9148,3 +9148,14 @@ COLORREF NppParameters::getFindDlgStatusMsgColor(int colourIndex)
|
||||
|
||||
return findDlgStatusMessageColor[colourIndex];
|
||||
}
|
||||
|
||||
LanguageNameInfo NppParameters::getLangNameInfoFromNameID(const wstring& langNameID)
|
||||
{
|
||||
LanguageNameInfo res;
|
||||
for (LanguageNameInfo lnf : ScintillaEditView::_langNameInfoArray)
|
||||
{
|
||||
if (lnf._langName == langNameID)
|
||||
return lnf;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1507,6 +1507,8 @@ private:
|
||||
std::wstring _lastCmdLabel;
|
||||
};
|
||||
|
||||
struct LanguageNameInfo;
|
||||
|
||||
class NppParameters final
|
||||
{
|
||||
private:
|
||||
@ -1912,6 +1914,8 @@ public:
|
||||
void addScintillaModEventMask(unsigned long mask2Add) { _sintillaModEventMask |= mask2Add; };
|
||||
bool isAsNotepadStyle() const { return _asNotepadStyle; }
|
||||
|
||||
LanguageNameInfo getLangNameInfoFromNameID(const std::wstring& langNameID);
|
||||
|
||||
private:
|
||||
NppParameters();
|
||||
~NppParameters();
|
||||
|
@ -4333,24 +4333,12 @@ void ScintillaEditView::restoreHiddenLines()
|
||||
|
||||
void ScintillaEditView::setTabSettings(Lang* lang)
|
||||
{
|
||||
if (!lang) return;
|
||||
|
||||
if (lang && lang->_tabSize != -1 && lang->_tabSize != 0)
|
||||
{
|
||||
if (lang->_langID == L_JAVASCRIPT)
|
||||
{
|
||||
Lang* ljs = NppParameters::getInstance().getLangFromID(L_JS_EMBEDDED);
|
||||
execute(SCI_SETTABWIDTH, ljs->_tabSize > 0 ? ljs->_tabSize : lang->_tabSize);
|
||||
execute(SCI_SETUSETABS, !ljs->_isTabReplacedBySpace);
|
||||
execute(SCI_SETBACKSPACEUNINDENTS, ljs->_isBackspaceUnindent);
|
||||
}
|
||||
else
|
||||
{
|
||||
execute(SCI_SETTABWIDTH, lang->_tabSize);
|
||||
execute(SCI_SETUSETABS, !lang->_isTabReplacedBySpace);
|
||||
execute(SCI_SETBACKSPACEUNINDENTS, lang->_isBackspaceUnindent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const NppGUI& nppgui = NppParameters::getInstance().getNppGUI();
|
||||
|
@ -106,7 +106,8 @@ intptr_t CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
|
||||
int nColor;
|
||||
for (nColor = 0 ; nColor < int(sizeof(colourItems)/sizeof(DWORD)) ; ++nColor)
|
||||
{
|
||||
::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, nColor, reinterpret_cast<LPARAM>(""));
|
||||
auto i = ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(""));
|
||||
if (i != LB_ERR)
|
||||
::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA, nColor, static_cast<LPARAM>(colourItems[nColor]));
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -1022,6 +1022,8 @@ void WordStyleDlg::setStyleListFromLexer(int index)
|
||||
const wchar_t *langName = _lsArray.getLexerNameFromIndex(index - 1);
|
||||
const wchar_t *ext = NppParameters::getInstance().getLangExtFromName(langName);
|
||||
const wchar_t *userExt = (_lsArray.getLexerStylerByName(langName))->getLexerUserExt();
|
||||
|
||||
if (ext)
|
||||
::SendDlgItemMessage(_hSelf, IDC_DEF_EXT_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(ext));
|
||||
|
||||
// WM_SETTEXT cause sending WM_COMMAND message with EN_CHANGE.
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "EncodingMapper.h"
|
||||
#include "localization.h"
|
||||
#include <algorithm>
|
||||
#include "ScintillaEditView.h"
|
||||
|
||||
|
||||
#define MyGetGValue(rgb) (LOBYTE((rgb)>>8))
|
||||
|
||||
@ -3446,7 +3448,7 @@ intptr_t CALLBACK NewDocumentSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
getNameStrFromCmd(cmdID, str);
|
||||
if (str.length() > 0)
|
||||
{
|
||||
size_t index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(str.c_str()));
|
||||
auto index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(str.c_str()));
|
||||
::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_SETITEMDATA, index, lt);
|
||||
}
|
||||
}
|
||||
@ -3990,7 +3992,15 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
const int nbLang = nppParam.getNbLang();
|
||||
for (int i = 0; i < nbLang; ++i)
|
||||
{
|
||||
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(nppParam.getLangFromIndex(i)->_langName.c_str()));
|
||||
Lang* lang = nppParam.getLangFromIndex(i);
|
||||
if (!lang) continue;
|
||||
|
||||
LanguageNameInfo lni = nppParam.getLangNameInfoFromNameID(lang->_langName);
|
||||
if (!lni._shortName || lni._langID == L_JS_EMBEDDED) continue;
|
||||
|
||||
auto j = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(lni._shortName));
|
||||
if (j != LB_ERR)
|
||||
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_SETITEMDATA, j, reinterpret_cast<LPARAM>(lang));
|
||||
}
|
||||
const int index2Begin = 0;
|
||||
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_SETCURSEL, index2Begin, 0);
|
||||
@ -4045,10 +4055,10 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
const int dlgCtrlID = ::GetDlgCtrlID(reinterpret_cast<HWND>(lParam));
|
||||
const auto& hdcStatic = reinterpret_cast<HDC>(wParam);
|
||||
// handle blurry text with disabled states for the affected static controls
|
||||
const size_t index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
const auto index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
if ((index > 0) && (dlgCtrlID == IDC_TABSIZE_STATIC || dlgCtrlID == IDC_INDENTUSING_STATIC))
|
||||
{
|
||||
const Lang* lang = nppParam.getLangFromIndex(index - 1);
|
||||
const Lang* lang = reinterpret_cast<Lang *>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (lang == nullptr)
|
||||
{
|
||||
return NppDarkMode::onCtlColorDlg(hdcStatic);
|
||||
@ -4084,7 +4094,7 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
Lang* lang = nppParam.getLangFromIndex(index - 1);
|
||||
const Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (!lang) return FALSE;
|
||||
|
||||
bool useDefaultTab = (lang->_tabSize == -1 || lang->_tabSize == 0);
|
||||
@ -4140,31 +4150,11 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
}
|
||||
|
||||
const bool useDefaultTab = isCheckedOrNot(IDC_CHECK_DEFAULTTABVALUE);
|
||||
const size_t index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
const auto index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
if (!useDefaultTab && index > 0)
|
||||
{
|
||||
Lang* lang = nppParam.getLangFromIndex(index - 1);
|
||||
if (lang == nullptr)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (lang->_langID == L_JS_EMBEDDED)
|
||||
{
|
||||
Lang* ljs = nppParam.getLangFromID(L_JAVASCRIPT);
|
||||
if (!ljs)
|
||||
return FALSE;
|
||||
|
||||
ljs->_tabSize = tabSize;
|
||||
}
|
||||
else if (lang->_langID == L_JAVASCRIPT)
|
||||
{
|
||||
Lang* ljavascript = nppParam.getLangFromID(L_JS_EMBEDDED);
|
||||
if (!ljavascript)
|
||||
return FALSE;
|
||||
|
||||
ljavascript->_tabSize = tabSize;
|
||||
}
|
||||
Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (lang == nullptr) return FALSE;
|
||||
|
||||
lang->_tabSize = tabSize;
|
||||
|
||||
@ -4199,11 +4189,11 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
if (tabSize < 1)
|
||||
{
|
||||
const bool useDefaultTab = isCheckedOrNot(IDC_CHECK_DEFAULTTABVALUE);
|
||||
const size_t index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
const auto index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
|
||||
auto prevSize = nppGUI._tabSize;
|
||||
if (!useDefaultTab && index > 0)
|
||||
{
|
||||
Lang* lang = nppParam.getLangFromIndex(index - 1);
|
||||
const Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (lang != nullptr && lang->_tabSize > 0)
|
||||
{
|
||||
prevSize = lang->_tabSize;
|
||||
@ -4243,26 +4233,11 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
Lang *lang = nppParam.getLangFromIndex(index - 1);
|
||||
Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (!lang) return FALSE;
|
||||
if (!lang->_tabSize || lang->_tabSize == -1)
|
||||
lang->_tabSize = nppGUI._tabSize;
|
||||
|
||||
if (lang->_langID == L_JS_EMBEDDED)
|
||||
{
|
||||
Lang *ljs = nppParam.getLangFromID(L_JAVASCRIPT);
|
||||
if (!ljs) return FALSE;
|
||||
|
||||
ljs->_isTabReplacedBySpace = isTabReplacedBySpace;
|
||||
}
|
||||
else if (lang->_langID == L_JAVASCRIPT)
|
||||
{
|
||||
Lang *ljavascript = nppParam.getLangFromID(L_JS_EMBEDDED);
|
||||
if (!ljavascript) return FALSE;
|
||||
|
||||
ljavascript->_isTabReplacedBySpace = isTabReplacedBySpace;
|
||||
}
|
||||
|
||||
lang->_isTabReplacedBySpace = isTabReplacedBySpace;
|
||||
|
||||
// write in langs.xml
|
||||
@ -4287,26 +4262,11 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
Lang* lang = nppParam.getLangFromIndex(index - 1);
|
||||
Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (!lang) return FALSE;
|
||||
if (!lang->_tabSize || lang->_tabSize == -1)
|
||||
lang->_tabSize = nppGUI._tabSize;
|
||||
|
||||
if (lang->_langID == L_JS_EMBEDDED)
|
||||
{
|
||||
Lang* ljs = nppParam.getLangFromID(L_JAVASCRIPT);
|
||||
if (!ljs) return FALSE;
|
||||
|
||||
ljs->_isBackspaceUnindent = isBackspaceUnindent;
|
||||
}
|
||||
else if (lang->_langID == L_JAVASCRIPT)
|
||||
{
|
||||
Lang* ljavascript = nppParam.getLangFromID(L_JS_EMBEDDED);
|
||||
if (!ljavascript) return FALSE;
|
||||
|
||||
ljavascript->_isBackspaceUnindent = isBackspaceUnindent;
|
||||
}
|
||||
|
||||
lang->_isBackspaceUnindent = isBackspaceUnindent;
|
||||
|
||||
// write in langs.xml
|
||||
@ -4329,7 +4289,7 @@ intptr_t CALLBACK IndentationSubDlg::run_dlgProc(UINT message, WPARAM wParam, LP
|
||||
if (index == LB_ERR || index == 0) // index == 0 shouldn't happen
|
||||
return FALSE;
|
||||
|
||||
Lang *lang = nppParam.getLangFromIndex(index - 1);
|
||||
Lang* lang = reinterpret_cast<Lang*>(::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETITEMDATA, index, 0));
|
||||
if (!lang)
|
||||
return FALSE;
|
||||
|
||||
|
@ -324,6 +324,9 @@ void ProjectPanel::destroyMenus()
|
||||
|
||||
bool ProjectPanel::openWorkSpace(const wchar_t *projectFileName, bool force)
|
||||
{
|
||||
if (!projectFileName)
|
||||
return false;
|
||||
|
||||
if ((!force) && (_workSpaceFilePath.length() > 0))
|
||||
{ // Return if it is better to keep the current workspace tree
|
||||
wstring newWorkspace = projectFileName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user