From fdae99e6c01b106082215b1956470c53913be214 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 4 Aug 2023 04:00:50 +0200 Subject: [PATCH] Fix new document number jumps from "New 1" to "New 3" issue Solution from: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/13931#issuecomment-1653523758 Fix #13194, fix #8677, close #13960 --- PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/Notepad_plus.h | 6 ++++-- PowerEditor/src/ScintillaComponent/Buffer.cpp | 16 +++++++++++----- PowerEditor/src/ScintillaComponent/Buffer.h | 2 +- .../src/ScintillaComponent/ScintillaEditView.cpp | 2 +- .../src/ScintillaComponent/ScintillaEditView.h | 6 ++++++ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 4f6eaa059..8b05fed4f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7788,6 +7788,7 @@ static const QuoteParams quotes[] = {TEXT("Anonymous #203"), QuoteParams::rapid , false, SC_CP_UTF8, L_TEXT, TEXT("My gynecologist follows me on Instagram, I really do not know what else he want to see.\n\n") }, {TEXT("Anonymous #204"), QuoteParams::slow , false, SC_CP_UTF8, L_TEXT, TEXT("The greatest security vulnerability in any computer system is located between the keyboard and the chair.\n\n") }, {TEXT("Anonymous #205"), QuoteParams::slow , false, SC_CP_UTF8, L_TEXT, TEXT("Courage is knowing it might hurt, and doing it anyway.\nStupidity is the same.\nAnd that's why life is hard.\n\n") }, + {TEXT("Anonymous #206"), QuoteParams::rapid , false, SC_CP_UTF8, L_TEXT, TEXT("RegEx can save 30 minutes of your dev time with only 10 characters.\nBut you have to spend more than 40 minutes to figure out what these 10 characters need to be.\n\n") }, {TEXT("xkcd"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("Never have I felt so close to another soul\nAnd yet so helplessly alone\nAs when I Google an error\nAnd there's one result\nA thread by someone with the same problem\nAnd no answer\nLast posted to in 2003\n\n\"Who were you, DenverCoder9?\"\n\"What did you see?!\"\n\n(ref: https://xkcd.com/979/)") }, {TEXT("A developer"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("No hugs & kisses.\nOnly bugs & fixes.") }, {TEXT("Elon Musk"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("Don't set your password as your child's name.\nName your child after your password.") }, diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index a4863d2fd..4c333c1bb 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -50,6 +50,8 @@ #define MENU 0x01 #define TOOLBAR 0x02 +#define MAIN_EDIT_ZONE true + enum FileTransferMode { TransferClone = 0x01, TransferMove = 0x02 @@ -278,8 +280,8 @@ private: DocTabView* _pDocTab = nullptr; DocTabView* _pNonDocTab = nullptr; - ScintillaEditView _subEditView; - ScintillaEditView _mainEditView; + ScintillaEditView _subEditView = ScintillaEditView(MAIN_EDIT_ZONE); // only _mainEditView and _subEditView are MAIN_EDIT_ZONE comparing with other Scintilla controls + ScintillaEditView _mainEditView = ScintillaEditView(MAIN_EDIT_ZONE); // only _mainEditView and _subEditView are MAIN_EDIT_ZONE comparing with other Scintilla controls ScintillaEditView _invisibleEditView; // for searches ScintillaEditView _fileEditView; // for FileManager ScintillaEditView* _pEditView = nullptr; diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index f0fa3ca45..3d3312817 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -1329,13 +1329,19 @@ BufferID FileManager::newEmptyDocument() return id; } -BufferID FileManager::bufferFromDocument(Document doc) +BufferID FileManager::bufferFromDocument(Document doc, bool isMainEditZone) { NppParameters& nppParamInst = NppParameters::getInstance(); - generic_string newTitle = (nppParamInst.getNativeLangSpeaker())->getLocalizedStrFromID("tab-untitled-string", UNTITLED_STR); - TCHAR nb[10]; - wsprintf(nb, TEXT("%d"), static_cast(nextUntitledNewNumber())); - newTitle += nb; + std::wstring newTitle = L"newNonMainEditZoneInvisibleTitle "; // This title is invisible for "Document map", "Find result" or other Scintilla controls other than _mainEditView and _subEditView. + // Its strong length and the space at the end are for preventing the tab name modification from the collision with it. + + if (isMainEditZone) // only _mainEditView or _subEditView is main edit zone, so we count new number of doc only for these 2 scintilla edit views. + { + newTitle = (nppParamInst.getNativeLangSpeaker())->getLocalizedStrFromID("tab-untitled-string", UNTITLED_STR); + wchar_t nb[10]; + wsprintf(nb, TEXT("%d"), static_cast(nextUntitledNewNumber())); + newTitle += nb; + } Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str(), false); BufferID id = newBuf; diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index ed6f4bf16..3f4a8a791 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -89,7 +89,7 @@ public: BufferID newEmptyDocument(); //create Buffer from existing Scintilla, used from new Scintillas. - BufferID bufferFromDocument(Document doc); + BufferID bufferFromDocument(Document doc, bool isMainEditZone); BufferID getBufferFromName(const TCHAR * name); BufferID getBufferFromDocument(Document doc); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 271c3685d..e6ad570ff 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -1881,7 +1881,7 @@ BufferID ScintillaEditView::attachDefaultDoc() // get the doc pointer attached (by default) on the view Scintilla Document doc = execute(SCI_GETDOCPOINTER, 0, 0); execute(SCI_ADDREFDOCUMENT, 0, doc); - BufferID id = MainFileManager.bufferFromDocument(doc); + BufferID id = MainFileManager.bufferFromDocument(doc, _isMainEditZone); Buffer * buf = MainFileManager.getBufferByID(id); MainFileManager.addBufferReference(id, this); //add a reference. Notepad only shows the buffer in tabbar diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index 6675d4ed9..88497633c 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -309,6 +309,11 @@ public: ScintillaEditView(): Window() { ++_refCount; }; + + ScintillaEditView(bool isMainEditZone) : Window() { + _isMainEditZone = isMainEditZone; + ++_refCount; + }; virtual ~ScintillaEditView() { @@ -782,6 +787,7 @@ protected: static LRESULT CALLBACK scintillaStatic_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); LRESULT scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + bool _isMainEditZone = false; SCINTILLA_FUNC _pScintillaFunc = nullptr; SCINTILLA_PTR _pScintillaPtr = nullptr; static WNDPROC _scintillaDefaultProc;