mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ fix: Reverting file from storage - Preserve view, cancel selection
This commit is contained in:
parent
59edb291e5
commit
540ed2726a
67
src/Edit.c
67
src/Edit.c
@ -274,7 +274,7 @@ void EditSetNewText(HWND hwnd,char* lpstrText,DWORD cbText)
|
||||
UndoRedoActionMap(-1,NULL);
|
||||
SendMessage(hwnd,SCI_CLEARALL,0,0);
|
||||
SendMessage(hwnd,SCI_MARKERDELETEALL,(WPARAM)MARKER_NP3_BOOKMARK,0);
|
||||
SendMessage(hwnd,SCI_SETSCROLLWIDTH, 1,0);
|
||||
SendMessage(hwnd,SCI_SETSCROLLWIDTH, GetSystemMetrics(SM_CXSCREEN), 0);
|
||||
SendMessage(hwnd,SCI_SETXOFFSET,0,0);
|
||||
|
||||
FileVars_Apply(hwnd,&fvCurFile);
|
||||
@ -285,6 +285,7 @@ void EditSetNewText(HWND hwnd,char* lpstrText,DWORD cbText)
|
||||
SendMessage(hwnd,SCI_SETUNDOCOLLECTION,1,0);
|
||||
//SendMessage(hwnd,EM_EMPTYUNDOBUFFER,0,0); // deprecated
|
||||
SendMessage(hwnd,SCI_SETSAVEPOINT,0,0);
|
||||
SendMessage(hwnd, SCI_SETSCROLLWIDTH, 1, 0);
|
||||
SendMessage(hwnd,SCI_GOTOPOS,0,0);
|
||||
SendMessage(hwnd,SCI_CHOOSECARETX,0,0);
|
||||
|
||||
@ -723,6 +724,9 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck)
|
||||
EditClearClipboard(hwnd);
|
||||
EditSelectEx(hwnd, iAnchorPos, SciCall_GetCurrentPos(), -1, -1);
|
||||
}
|
||||
//else {
|
||||
// EditSelectEx(hwnd, SciCall_GetCurrentPos(), SciCall_GetCurrentPos(), -1, -1);
|
||||
//}
|
||||
}
|
||||
else {
|
||||
char* pszText = LocalAlloc(LPTR, SciCall_GetSelText(NULL));
|
||||
@ -737,7 +741,7 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck)
|
||||
}
|
||||
else {
|
||||
if (iCurPos < iAnchorPos)
|
||||
EditSelectEx(hwnd, iCurPos, iCurPos, -1, -1);
|
||||
EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1);
|
||||
}
|
||||
LocalFree(pszText);
|
||||
}
|
||||
@ -748,7 +752,7 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck)
|
||||
{
|
||||
if (bSwapClipBoard) { SciCall_Copy(); }
|
||||
EditPaste2RectSel(hwnd, pClip);
|
||||
// TODO: restore selection in case of swap clipboard
|
||||
//TODO: restore selection in case of swap clipboard
|
||||
}
|
||||
else // Selection: SC_SEL_STREAM, SC_SEL_LINES
|
||||
{
|
||||
@ -4253,16 +4257,10 @@ void EditSortLines(HWND hwnd, int iSortFlags)
|
||||
|
||||
LocalFree(pmszResult);
|
||||
|
||||
if (bIsRectangular) {
|
||||
SendMessage(hwnd, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)iAnchorPos, 0);
|
||||
SendMessage(hwnd, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)iCurPos, 0);
|
||||
SendMessage(hwnd, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)iAnchorPosVS, 0);
|
||||
SendMessage(hwnd, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)iCurPosVS, 0);
|
||||
}
|
||||
else {
|
||||
if (bIsRectangular)
|
||||
EditSelectEx(hwnd, iAnchorPos, iCurPos, iAnchorPosVS, iCurPosVS);
|
||||
else
|
||||
EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -4272,6 +4270,8 @@ void EditSortLines(HWND hwnd, int iSortFlags)
|
||||
//
|
||||
void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos, int vSpcAnchor, int vSpcCurrent)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
|
||||
if ((iAnchorPos < 0) && (iCurrentPos < 0)) {
|
||||
SciCall_SelectAll();
|
||||
}
|
||||
@ -4289,7 +4289,7 @@ void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos, int vSpcAnch
|
||||
// This needs to be done *before* the SCI_SETSEL message
|
||||
SciCall_EnsureVisible(iAnchorLine);
|
||||
if (iAnchorLine != iNewLine) { SciCall_EnsureVisible(iNewLine); }
|
||||
|
||||
|
||||
if ((vSpcAnchor >= 0) && (vSpcCurrent >= 0)) {
|
||||
SciCall_SetRectangularSelectionAnchor(iAnchorPos);
|
||||
if (vSpcAnchor > 0)
|
||||
@ -4301,6 +4301,7 @@ void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos, int vSpcAnch
|
||||
else
|
||||
SciCall_SetSel(iAnchorPos, iCurrentPos);
|
||||
|
||||
//Sci_PostMsgV2(SCROLLRANGE, iAnchorPos, iCurrentPos);
|
||||
SciCall_ScrollRange(iAnchorPos, iCurrentPos);
|
||||
|
||||
// remember x-pos for moving caret vertically
|
||||
@ -4308,7 +4309,34 @@ void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos, int vSpcAnch
|
||||
|
||||
UpdateToolbar();
|
||||
UpdateStatusbar();
|
||||
UpdateLineNumberWidth();
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditEnsureSelectionVisible()
|
||||
//
|
||||
void EditEnsureSelectionVisible(HWND hwnd)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
DocPos iAnchorPos = 0;
|
||||
DocPos iCurrentPos = 0;
|
||||
DocPos iAnchorPosVS = -1;
|
||||
DocPos iCurPosVS = -1;
|
||||
|
||||
if (SciCall_IsSelectionRectangle())
|
||||
{
|
||||
iAnchorPos = SciCall_GetRectangularSelectionAnchor();
|
||||
iCurrentPos = SciCall_GetRectangularSelectionCaret();
|
||||
iAnchorPosVS = SciCall_GetRectangularSelectionAnchorVirtualSpace();
|
||||
iCurPosVS = SciCall_GetRectangularSelectionCaretVirtualSpace();
|
||||
}
|
||||
else {
|
||||
iAnchorPos = SciCall_GetAnchor();
|
||||
iCurrentPos = SciCall_GetCurrentPos();
|
||||
}
|
||||
EditSelectEx(hwnd, iAnchorPos, iCurrentPos, iAnchorPosVS, iCurPosVS);
|
||||
}
|
||||
|
||||
|
||||
@ -4366,19 +4394,6 @@ void EditFixPositions(HWND hwnd)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditEnsureSelectionVisible()
|
||||
//
|
||||
void EditEnsureSelectionVisible(HWND hwnd)
|
||||
{
|
||||
const DocPos iAnchorPos = SciCall_GetAnchor();
|
||||
const DocPos iCurrentPos = SciCall_GetCurrentPos();
|
||||
EditSelectEx(hwnd, iAnchorPos, iCurrentPos, -1, -1);
|
||||
UNUSED(hwnd);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditGetExcerpt()
|
||||
|
||||
@ -208,7 +208,7 @@ int iSciFontQuality;
|
||||
int iHighDpiToolBar;
|
||||
int iUpdateDelayHyperlinkStyling;
|
||||
int iUpdateDelayMarkAllCoccurrences;
|
||||
int iCurrentLineHorizontalSlop = 1;
|
||||
int iCurrentLineHorizontalSlop = 0;
|
||||
int iCurrentLineVerticalSlop = 0;
|
||||
|
||||
const int DirectWriteTechnology[4] = {
|
||||
@ -1280,18 +1280,19 @@ void __fastcall InitializeSciEditCtrl(HWND hwndEditCtrl)
|
||||
SendMessage(hwndEditCtrl, SCI_SETCARETSTICKY, SC_CARETSTICKY_OFF, 0);
|
||||
//SendMessage(hwndEditCtrl,SCI_SETCARETSTICKY,SC_CARETSTICKY_WHITESPACE,0);
|
||||
|
||||
#define _CARET_SYMETRY CARET_EVEN /// CARET_EVEN or 0
|
||||
if (iCurrentLineHorizontalSlop > 0)
|
||||
SendMessage(hwndEditCtrl, SCI_SETXCARETPOLICY, (WPARAM)(CARET_SLOP | CARET_EVEN | CARET_STRICT), iCurrentLineHorizontalSlop);
|
||||
SendMessage(hwndEditCtrl, SCI_SETXCARETPOLICY, (WPARAM)(CARET_SLOP | _CARET_SYMETRY | CARET_STRICT), iCurrentLineHorizontalSlop);
|
||||
else
|
||||
SendMessage(hwndEditCtrl, SCI_SETXCARETPOLICY, (WPARAM)(CARET_SLOP | CARET_EVEN | CARET_STRICT), (LPARAM)0);
|
||||
SendMessage(hwndEditCtrl, SCI_SETXCARETPOLICY, (WPARAM)(CARET_SLOP | _CARET_SYMETRY | CARET_STRICT), (LPARAM)0);
|
||||
|
||||
if (iCurrentLineVerticalSlop > 0)
|
||||
SendMessage(hwndEditCtrl, SCI_SETYCARETPOLICY, (WPARAM)(CARET_SLOP | CARET_EVEN | CARET_STRICT), iCurrentLineVerticalSlop);
|
||||
SendMessage(hwndEditCtrl, SCI_SETYCARETPOLICY, (WPARAM)(CARET_SLOP | _CARET_SYMETRY | CARET_STRICT), iCurrentLineVerticalSlop);
|
||||
else
|
||||
SendMessage(hwndEditCtrl, SCI_SETYCARETPOLICY, (WPARAM)(CARET_EVEN), 0);
|
||||
SendMessage(hwndEditCtrl, SCI_SETYCARETPOLICY, (WPARAM)(_CARET_SYMETRY), 0);
|
||||
|
||||
SendMessage(hwndEditCtrl, SCI_SETVIRTUALSPACEOPTIONS, (WPARAM)(bDenyVirtualSpaceAccess ? SCVS_NONE : SCVS_RECTANGULARSELECTION), 0);
|
||||
SendMessage(hwndEditCtrl, SCI_SETENDATLASTLINE, ((bScrollPastEOF) ? 0 : 1), 0);
|
||||
SendMessage(hwndEditCtrl, SCI_SETENDATLASTLINE, (WPARAM)((bScrollPastEOF) ? 0 : 1), 0);
|
||||
|
||||
// Tabs
|
||||
SendMessage(hwndEditCtrl, SCI_SETUSETABS, !g_bTabsAsSpaces, 0);
|
||||
@ -2964,8 +2965,10 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
int token = BeginUndoAction();
|
||||
EditPasteClipboard(g_hwndEdit, FALSE, bSkipUnicodeDetection);
|
||||
EndUndoAction(token);
|
||||
UpdateToolbar();
|
||||
UpdateStatusbar();
|
||||
// Updates done by EditPasteClipboard():
|
||||
//~UpdateToolbar();
|
||||
//~UpdateStatusbar();
|
||||
//~UpdateLineNumberWidth();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -4323,7 +4326,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case IDM_VIEW_SCROLLPASTEOF:
|
||||
bScrollPastEOF = (bScrollPastEOF) ? FALSE : TRUE;
|
||||
SendMessage(g_hwndEdit, SCI_SETENDATLASTLINE, ((bScrollPastEOF) ? 0 : 1), 0);
|
||||
SciCall_SetEndAtLastLine(!bScrollPastEOF);
|
||||
break;
|
||||
|
||||
case IDM_VIEW_TOOLBAR:
|
||||
@ -5658,7 +5661,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
|
||||
|
||||
case SCN_SAVEPOINTREACHED:
|
||||
SendMessage(g_hwndEdit, SCI_SETSCROLLWIDTH, 1, 0);
|
||||
SciCall_SetScrollWidth(1);
|
||||
SetDocumentModified(FALSE);
|
||||
break;
|
||||
|
||||
@ -7827,10 +7830,14 @@ BOOL FileRevert(LPCWSTR szFileName)
|
||||
|
||||
const DocPos iCurPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaret() : SciCall_GetCurrentPos();
|
||||
const DocPos iAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchor() : SciCall_GetAnchor();
|
||||
const int vSpcCaretPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaretVirtualSpace() : -1;
|
||||
const int vSpcAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchorVirtualSpace() : -1;
|
||||
//const int vSpcCaretPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaretVirtualSpace() : -1;
|
||||
//const int vSpcAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchorVirtualSpace() : -1;
|
||||
|
||||
const DocLn iCurrLine = SciCall_LineFromPosition(iCurPos);
|
||||
const DocPos iCurColumn = SciCall_GetColumn(iCurPos);
|
||||
const DocLn iVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
const DocLn iDocTopLine = SciCall_DocLineFromVisible(iVisTopLine);
|
||||
const int iXOffset = SciCall_GetXoffset();
|
||||
const BOOL bIsTail = (iCurPos == iAnchorPos) && (iCurrLine >= (SciCall_GetLineCount() - 1));
|
||||
|
||||
Encoding_SrcWeak(Encoding_Current(CPI_GET));
|
||||
@ -7846,9 +7853,16 @@ BOOL FileRevert(LPCWSTR szFileName)
|
||||
}
|
||||
else if (SciCall_GetTextLength() >= 4) {
|
||||
char tch[5] = { '\0' };
|
||||
|
||||
SciCall_GetText(5, tch);
|
||||
if (StringCchCompareXA(tch,".LOG") != 0) {
|
||||
EditSelectEx(g_hwndEdit, iAnchorPos, iCurPos, vSpcAnchorPos, vSpcCaretPos);
|
||||
SciCall_ClearSelections();
|
||||
//~EditSelectEx(g_hwndEdit, iAnchorPos, iCurPos, vSpcAnchorPos, vSpcCaretPos);
|
||||
EditJumpTo(g_hwndEdit, iCurrLine+1, iCurColumn+1);
|
||||
SciCall_EnsureVisible(iDocTopLine);
|
||||
const DocLn iNewTopLine = SciCall_GetFirstVisibleLine();
|
||||
SciCall_LineScroll(0,iVisTopLine - iNewTopLine);
|
||||
SciCall_SetXoffset(iXOffset);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@ -66,6 +66,9 @@ extern HANDLE g_hwndEdit;
|
||||
#define Sci_SendMsgV1(CMD,WP) SendMessage(g_hwndEdit, SCI_##CMD, (WPARAM)(WP), (LPARAM)0)
|
||||
#define Sci_SendMsgV2(CMD,WP,LP) SendMessage(g_hwndEdit, SCI_##CMD, (WPARAM)(WP), (LPARAM)(LP))
|
||||
|
||||
#define Sci_PostMsgV0(CMD) PostMessage(g_hwndEdit, SCI_##CMD, (WPARAM)0, (LPARAM)0)
|
||||
#define Sci_PostMsgV1(CMD,WP) PostMessage(g_hwndEdit, SCI_##CMD, (WPARAM)(WP), (LPARAM)0)
|
||||
#define Sci_PostMsgV2(CMD,WP,LP) PostMessage(g_hwndEdit, SCI_##CMD, (WPARAM)(WP), (LPARAM)(LP))
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
@ -155,6 +158,7 @@ DeclareSciCallR0(GetRectangularSelectionAnchorVirtualSpace, GETRECTANGULARSELECT
|
||||
DeclareSciCallV1(SetRectangularSelectionAnchorVirtualSpace, SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, DocPos, position)
|
||||
|
||||
// Multiselections (Lines of Rectangular selection)
|
||||
DeclareSciCallV0(ClearSelections, CLEARSELECTIONS)
|
||||
DeclareSciCallR0(GetSelections, GETSELECTIONS, DocPosU)
|
||||
DeclareSciCallR1(GetSelectionNCaret, GETSELECTIONNCARET, DocPos, DocPosU, selnum)
|
||||
DeclareSciCallR1(GetSelectionNAnchor, GETSELECTIONNANCHOR, DocPos, DocPosU, selnum)
|
||||
@ -170,6 +174,7 @@ DeclareSciCallV0(Cut, CUT)
|
||||
DeclareSciCallV0(Copy, COPY)
|
||||
DeclareSciCallV0(Paste, PASTE)
|
||||
DeclareSciCallV0(Clear, CLEAR)
|
||||
DeclareSciCallV0(Cancel, CANCEL)
|
||||
DeclareSciCallV0(CopyAllowLine, COPYALLOWLINE)
|
||||
DeclareSciCallV0(LineDelete, LINEDELETE)
|
||||
DeclareSciCallV2(CopyText, COPYTEXT, DocPos, length, const char*, text)
|
||||
@ -210,17 +215,11 @@ DeclareSciCallR1(PositionFromLine, POSITIONFROMLINE, DocPos, DocLn, line)
|
||||
DeclareSciCallR1(GetLineEndPosition, GETLINEENDPOSITION, DocPos, DocLn, line)
|
||||
DeclareSciCallR1(GetColumn, GETCOLUMN, DocPos, DocPos, position)
|
||||
DeclareSciCallR2(FindColumn, FINDCOLUMN, DocPos, DocLn, line, DocPos, column)
|
||||
|
||||
DeclareSciCallR0(LinesOnScreen, LINESONSCREEN, DocLn)
|
||||
DeclareSciCallR0(GetFirstVisibleLine, GETFIRSTVISIBLELINE, DocLn)
|
||||
DeclareSciCallR1(DocLineFromVisible, DOCLINEFROMVISIBLE, DocLn, DocLn, line)
|
||||
DeclareSciCallR1(GetLineIndentPosition, GETLINEINDENTPOSITION, DocPos, DocLn, line)
|
||||
|
||||
|
||||
DeclareSciCallR2(GetRangePointer, GETRANGEPOINTER, char* const, DocPos, start, DocPos, length)
|
||||
DeclareSciCallR0(GetCharacterPointer, GETCHARACTERPOINTER, const char*)
|
||||
|
||||
|
||||
DeclareSciCallV1(SetVirtualSpaceOptions, SETVIRTUALSPACEOPTIONS, int, options)
|
||||
|
||||
|
||||
@ -237,7 +236,16 @@ DeclareSciCallV0(NewLine, NEWLINE)
|
||||
//
|
||||
DeclareSciCallV0(ChooseCaretX, CHOOSECARETX)
|
||||
DeclareSciCallV0(ScrollCaret, SCROLLCARET)
|
||||
DeclareSciCallV2(LineScroll, LINESCROLL, DocPos, columns, DocLn, lines)
|
||||
DeclareSciCallV2(ScrollRange, SCROLLRANGE, DocPos, secondaryPos, DocPos, primaryPos)
|
||||
DeclareSciCallV1(SetScrollWidth, SETSCROLLWIDTH, int, width)
|
||||
DeclareSciCallV1(SetEndAtLastLine, SETENDATLASTLINE, bool, flag)
|
||||
DeclareSciCallR0(GetXoffset, GETXOFFSET, int)
|
||||
DeclareSciCallV1(SetXoffset, SETXOFFSET, int, offset)
|
||||
|
||||
DeclareSciCallR0(LinesOnScreen, LINESONSCREEN, DocLn)
|
||||
DeclareSciCallR0(GetFirstVisibleLine, GETFIRSTVISIBLELINE, DocLn)
|
||||
DeclareSciCallR1(DocLineFromVisible, DOCLINEFROMVISIBLE, DocLn, DocLn, line)
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
typedef Sci_Position DocPos;
|
||||
typedef Sci_PositionU DocPosU;
|
||||
typedef Sci_PositionCR DocCR;
|
||||
typedef Sci_Position DocLn; // Sci_Line?
|
||||
typedef Sci_Line DocLn;
|
||||
#else
|
||||
|
||||
#ifdef NP3_COMPILE_TEST
|
||||
|
||||
Loading…
Reference in New Issue
Block a user