Skip to content

Commit

Permalink
Improve loading large file (issue #79) by replacing SciCall_AddText()…
Browse files Browse the repository at this point in the history
… with SciCall_AppendText()

to avoid moving caret to end of document then moving back to beginning of document.
  • Loading branch information
zufuliu committed Aug 11, 2020
1 parent 6015404 commit 792c34f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void EditSetNewText(LPCSTR lpstrText, DWORD cbText, Sci_Line lineCount) {
StopWatch_Start(watch);
#endif
SciCall_SetInitLineCount(lineCount);
SciCall_AddText(cbText, lpstrText);
SciCall_AppendText(cbText, lpstrText);
#if 0
StopWatch_Stop(watch);
StopWatch_ShowLog(&watch, "AddText time");
Expand All @@ -176,8 +176,6 @@ void EditSetNewText(LPCSTR lpstrText, DWORD cbText, Sci_Line lineCount) {
SciCall_SetUndoCollection(TRUE);
SciCall_EmptyUndoBuffer();
SciCall_SetSavePoint();
SciCall_GotoPos(0);
SciCall_ChooseCaretX();

bFreezeAppTitle = FALSE;
}
Expand Down Expand Up @@ -219,16 +217,16 @@ BOOL EditConvertText(UINT cpSource, UINT cpDest, BOOL bSetSavePoint) {
SciCall_SetCodePage(cpDest);

if (cbText > 0) {
SciCall_AddText(cbText, pchText);
SciCall_SetModEventMask(SC_MOD_NONE);
SciCall_AppendText(cbText, pchText);
SciCall_SetModEventMask(SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT);
}
if (pchText != NULL) {
NP2HeapFree(pchText);
}

SciCall_EmptyUndoBuffer();
SciCall_SetUndoCollection(TRUE);
SciCall_GotoPos(0);
SciCall_ChooseCaretX();
if (length == 0 && bSetSavePoint) {
SciCall_SetSavePoint();
}
Expand Down Expand Up @@ -262,7 +260,7 @@ void EditConvertToLargeMode(void) {
EditReplaceDocument(pdoc);
if (length > 0) {
SciCall_SetModEventMask(SC_MOD_NONE);
SciCall_AddText(length, pchText);
SciCall_AppendText(length, pchText);
SciCall_SetModEventMask(SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT);
}
if (pchText != NULL) {
Expand All @@ -271,8 +269,6 @@ void EditConvertToLargeMode(void) {

SciCall_SetUndoCollection(TRUE);
SciCall_EmptyUndoBuffer();
SciCall_GotoPos(0);
SciCall_ChooseCaretX();
SciCall_SetSavePoint();

Style_SetLexer(pLexCurrent, TRUE);
Expand Down Expand Up @@ -8026,7 +8022,6 @@ void EditGotoBlock(int menu) {

case IDM_EDIT_GOTO_NEXT_BLOCK:
case IDM_EDIT_GOTO_NEXT_SIBLING_BLOCK: {
SciCall_ColouriseAll();
const Sci_Line lineCount = SciCall_GetLineCount();
if (iLine >= 0) {
iLine = SciCall_GetLastChild(iLine);
Expand Down
9 changes: 9 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ BOOL InitApplication(HINSTANCE hInstance) {
//
//
HWND InitInstance(HINSTANCE hInstance, int nCmdShow) {
#if 0
StopWatch watch;
StopWatch_Start(watch);
#endif
const BOOL defaultPos = (wi.x == CW_USEDEFAULT || wi.y == CW_USEDEFAULT || wi.cx == CW_USEDEFAULT || wi.cy == CW_USEDEFAULT);
RECT rc = { wi.x, wi.y, (defaultPos ? CW_USEDEFAULT : (wi.x + wi.cx)), (defaultPos ? CW_USEDEFAULT : (wi.y + wi.cy)) };

Expand Down Expand Up @@ -952,6 +956,11 @@ HWND InitInstance(HINSTANCE hInstance, int nCmdShow) {
UpdateToolbar();
UpdateStatusbar();
}

#if 0
StopWatch_Stop(watch);
StopWatch_ShowLog(&watch, "InitInstance() time");
#endif
return hwndMain;
}

Expand Down

0 comments on commit 792c34f

Please sign in to comment.