Merge pull request #4155 from RaiKoHoff/Dev_Master

Fix book mark handling in case of delete
This commit is contained in:
Rainer Kottenhoff 2022-09-01 01:18:21 +02:00 committed by GitHub
commit 538b9b1193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 40 deletions

View File

@ -4571,7 +4571,7 @@ void EditFocusMarkedLinesCmd(HWND hwnd, bool bCopy, bool bDelete)
}
DocLn const curLn = Sci_GetCurrentLineNumber();
int const bitmask = SciCall_MarkerGet(curLn) & OCCURRENCE_MARKER_BITMASK();
int const bitmask = SciCall_MarkerGet(curLn) & ALL_MARKERS_BITMASK();
if (!bitmask) {
return;
@ -4585,7 +4585,7 @@ void EditFocusMarkedLinesCmd(HWND hwnd, bool bCopy, bool bDelete)
while (line >= 0) {
line = SciCall_MarkerNext(line, bitmask);
if (line >= 0) {
int const lnmask = SciCall_MarkerGet(line) & OCCURRENCE_MARKER_BITMASK();
int const lnmask = SciCall_MarkerGet(line) & ALL_MARKERS_BITMASK();
if (lnmask == bitmask) { // must fit all markers
copyBufSize += SciCall_LineLength(line); // incl line-breaks
}
@ -4602,7 +4602,7 @@ void EditFocusMarkedLinesCmd(HWND hwnd, bool bCopy, bool bDelete)
while (line >= 0) {
line = SciCall_MarkerNext(line, bitmask);
if (line >= 0) {
int const lnmask = SciCall_MarkerGet(line) & OCCURRENCE_MARKER_BITMASK();
int const lnmask = SciCall_MarkerGet(line) & ALL_MARKERS_BITMASK();
if (lnmask == bitmask) { // must fit all markers
DocPos const lnBeg = SciCall_PositionFromLine(line);
DocPos const lnLen = SciCall_LineLength(line); // incl line-breaks
@ -4647,9 +4647,9 @@ void EditFocusMarkedLinesCmd(HWND hwnd, bool bCopy, bool bDelete)
while (line >= 0) {
line = SciCall_MarkerNext(line, bitmask);
if (line >= 0) {
int const lnmask = SciCall_MarkerGet(line) & OCCURRENCE_MARKER_BITMASK();
int const lnmask = SciCall_MarkerGet(line) & ALL_MARKERS_BITMASK();
if (lnmask == bitmask) { // must fit all markers
SciCall_MarkerDelete(line, -1);
UserMarkerDeleteAll(line);
DocPos const lnBeg = SciCall_PositionFromLine(line);
DocPos const lnLen = SciCall_LineLength(line); // incl line-breaks
SciCall_DeleteRange(lnBeg, lnLen); // complete line
@ -7527,7 +7527,7 @@ void EditClearAllOccurrenceMarkers(HWND hwnd)
void EditClearAllBookMarks(HWND hwnd)
{
UNREFERENCED_PARAMETER(hwnd);
int const bitmask = OCCURRENCE_MARKER_BITMASK() & ~(1 << MARKER_NP3_BOOKMARK);
int const bitmask = OCCURRENCE_MARKER_BITMASK();
DocLn const line = SciCall_MarkerNext(0, bitmask);
if (line >= 0) {
// 1st press: clear all occurrences marker
@ -8185,17 +8185,17 @@ void EditBookMarkLineRange(HWND hwnd)
//
void EditDeleteMarkerInSelection()
{
if (SciCall_IsSelectionEmpty()) {
SciCall_MarkerDelete(Sci_GetCurrentLineNumber(), -1);
} else if (Sci_IsStreamSelection()) {
DocPos const posSelBeg = SciCall_GetSelectionStart();
DocPos const posSelEnd = SciCall_GetSelectionEnd();
DocLn const lnBeg = SciCall_LineFromPosition(posSelBeg);
DocLn const lnEnd = SciCall_LineFromPosition(posSelEnd);
DocLn const lnDelBeg = (posSelBeg <= SciCall_PositionFromLine(lnBeg)) ? lnBeg : lnBeg + 1;
DocLn const lnDelEnd = (posSelEnd > SciCall_GetLineEndPosition(lnEnd)) ? lnEnd : lnEnd - 1;
for (DocLn ln = lnDelBeg; ln <= lnDelEnd; ++ln) {
SciCall_MarkerDelete(ln, -1);
if (!SciCall_IsSelectionEmpty()) {
if (Sci_IsStreamSelection()) {
DocPos const posSelBeg = SciCall_GetSelectionStart();
DocPos const posSelEnd = SciCall_GetSelectionEnd();
DocLn const lnBeg = SciCall_LineFromPosition(posSelBeg);
DocLn const lnEnd = SciCall_LineFromPosition(posSelEnd);
DocLn const lnDelBeg = (posSelBeg <= SciCall_PositionFromLine(lnBeg)) ? lnBeg : lnBeg + 1;
DocLn const lnDelEnd = (posSelEnd > SciCall_GetLineEndPosition(lnEnd)) ? lnEnd : lnEnd - 1;
for (DocLn ln = lnDelBeg; ln <= lnDelEnd; ++ln) {
UserMarkerDeleteAll(ln);
}
}
}
}
@ -9352,7 +9352,7 @@ void EditGetBookmarkList(HWND hwnd, LPWSTR pszBookMarks, int cchLength)
UNREFERENCED_PARAMETER(hwnd);
WCHAR tchLine[32];
StringCchCopyW(pszBookMarks, cchLength, L"");
int const bitmask = (1 << MARKER_NP3_BOOKMARK);
int const bitmask = BOOKMARK_BITMASK();
DocLn iLine = 0;
do {
iLine = SciCall_MarkerNext(iLine, bitmask);
@ -9409,14 +9409,14 @@ void EditBookmarkNext(HWND hwnd, const DocLn iLine)
UNREFERENCED_PARAMETER(hwnd);
int bitmask = SciCall_MarkerGet(iLine) & OCCURRENCE_MARKER_BITMASK();
if (!bitmask) {
bitmask = (1 << MARKER_NP3_BOOKMARK);
bitmask = BOOKMARK_BITMASK();
}
DocLn iNextLine = SciCall_MarkerNext(iLine + 1, bitmask);
if (iNextLine == (DocLn)-1) {
iNextLine = SciCall_MarkerNext(0, bitmask); // wrap around
}
if (iNextLine == (DocLn)-1) {
bitmask = OCCURRENCE_MARKER_BITMASK();
bitmask = ALL_MARKERS_BITMASK();
iNextLine = SciCall_MarkerNext(iLine + 1, bitmask); // find any bookmark
}
if (iNextLine == (DocLn)-1) {
@ -9435,16 +9435,16 @@ void EditBookmarkNext(HWND hwnd, const DocLn iLine)
void EditBookmarkPrevious(HWND hwnd, const DocLn iLine)
{
UNREFERENCED_PARAMETER(hwnd);
int bitmask = SciCall_MarkerGet(iLine) & OCCURRENCE_MARKER_BITMASK();
int bitmask = SciCall_MarkerGet(iLine) & ALL_MARKERS_BITMASK();
if (!bitmask) {
bitmask = (1 << MARKER_NP3_BOOKMARK);
bitmask = BOOKMARK_BITMASK();
}
DocLn iPrevLine = SciCall_MarkerPrevious(max_ln(0, iLine - 1), bitmask);
if (iPrevLine == (DocLn)-1) {
iPrevLine = SciCall_MarkerPrevious(SciCall_GetLineCount(), bitmask); // wrap around
}
if (iPrevLine == (DocLn)-1) {
bitmask = OCCURRENCE_MARKER_BITMASK();
bitmask = ALL_MARKERS_BITMASK();
iPrevLine = SciCall_MarkerPrevious(max_ln(0, iLine - 1), bitmask); //find any bookmark
}
if (iPrevLine == (DocLn)-1) {
@ -9464,10 +9464,11 @@ void EditBookmarkPrevious(HWND hwnd, const DocLn iLine)
void EditBookmarkToggle(HWND hwnd, const DocLn ln, const int modifiers)
{
UNREFERENCED_PARAMETER(hwnd);
int const bitmask = SciCall_MarkerGet(ln) & OCCURRENCE_MARKER_BITMASK();
int const all = ALL_MARKERS_BITMASK();
int const bitmask = SciCall_MarkerGet(ln) & all;
if (!bitmask) {
SciCall_MarkerAdd(ln, MARKER_NP3_BOOKMARK); // set
} else if (bitmask & (1 << MARKER_NP3_BOOKMARK)) {
} else if (bitmask & BOOKMARK_BITMASK()) {
SciCall_MarkerDelete(ln, MARKER_NP3_BOOKMARK); // unset
} else {
for (int m = MARKER_NP3_1; m < MARKER_NP3_BOOKMARK; ++m) {

View File

@ -567,13 +567,6 @@ __forceinline ptrdiff_t MultiByteToWideCharEx(
// ============================================================================
inline int32_t bitmask32_n(unsigned short n)
{
return ((n >= 32) ? 0 - ((int32_t)1) : (((int32_t)1) << n) - 1);
}
// ============================================================================
inline int wcscmp_s(const wchar_t* s1, const wchar_t* s2)
{
return (s1 && s2) ? wcscmp(s1, s2) : ((s1 ? 1 : (s2 ? -1 : 0)));

View File

@ -3666,7 +3666,7 @@ LRESULT MsgContextMenu(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
DocPos const iCurrentPos = SciCall_PositionFromPoint(pt.x, pt.y);
DocLn const curLn = SciCall_LineFromPosition(iCurrentPos);
int const bitmask = SciCall_MarkerGet(curLn) & OCCURRENCE_MARKER_BITMASK() & ~(1 << MARKER_NP3_BOOKMARK);
int const bitmask = SciCall_MarkerGet(curLn) & OCCURRENCE_MARKER_BITMASK();
imenu = (bitmask && ((Settings.FocusViewMarkerMode & FVMM_LN_BACKGR) || !Settings.ShowBookmarkMargin)) ? MNU_MARGIN : MNU_EDIT;
if (imenu == MNU_EDIT) {
@ -3699,7 +3699,7 @@ LRESULT MsgContextMenu(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
}
DocLn const curLn = Sci_GetCurrentLineNumber();
int const bitmask = SciCall_MarkerGet(curLn) & OCCURRENCE_MARKER_BITMASK();
int const bitmask = SciCall_MarkerGet(curLn) & ALL_MARKERS_BITMASK();
EnableCmd(hMenuCtx, IDM_EDIT_CLEAR_MARKER, bitmask);
EnableCmd(hMenuCtx, IDM_EDIT_CUT_MARKED, bitmask);
EnableCmd(hMenuCtx, IDM_EDIT_COPY_MARKED, bitmask);
@ -5004,7 +5004,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_DELETELINE: {
SciCall_MarkerDelete(Sci_GetCurrentLineNumber(), -1);
UserMarkerDeleteAll(Sci_GetCurrentLineNumber());
SciCall_LineDelete();
}
break;
@ -6533,7 +6533,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
if (iStartPos != iEndPos) {
SciCall_DelWordRight();
} else { // iStartPos == iEndPos
SciCall_MarkerDelete(Sci_GetCurrentLineNumber(), -1);
UserMarkerDeleteAll(Sci_GetCurrentLineNumber());
SciCall_LineDelete();
}
}
@ -7950,9 +7950,9 @@ static void _HandleAutoIndent(int const charAdded)
if (iCurLine > 0) {
//~DocPos const iPrevLineLength = Sci_GetNetLineLength(iCurLine - 1);
if (SciCall_GetLineEndPosition(iCurLine - 1) == SciCall_GetLineIndentPosition(iCurLine - 1)) {
int const bitmask = SciCall_MarkerGet(iCurLine - 1) & bitmask32_n(MARKER_NP3_BOOKMARK + 1); // all bookmarks
int const bitmask = SciCall_MarkerGet(iCurLine - 1) & ALL_MARKERS_BITMASK();
if (bitmask) {
SciCall_MarkerDelete((iCurLine - 1), -1);
UserMarkerDeleteAll(iCurLine - 1);
SciCall_MarkerAddSet(iCurLine, bitmask);
}
}
@ -10073,6 +10073,7 @@ void UndoRedoRecordingStart()
InterlockedExchange(&UndoActionToken, UNDOREDO_FREE); // clear
_UndoRedoActionMap(-1, NULL);
SciCall_SetUndoCollection(true);
//SciCall_SetChangeHistory(SC_CHANGE_HISTORY_DISABLED);
SciCall_SetChangeHistory(SC_CHANGE_HISTORY_ENABLED | SC_CHANGE_HISTORY_MARKERS | SC_CHANGE_HISTORY_INDICATORS);
}

View File

@ -243,6 +243,21 @@ void ObserveNotifyDocChangedEvent();
// ----------------------------------------------------------------------------
inline void UserMarkerDeleteAll(const DocLn ln)
{
//~~~ SciCall_MarkerDelete(line, -1);
int const bitmask = ALL_MARKERS_BITMASK();
int markers = SciCall_MarkerGet(ln);
while (markers & bitmask) {
for (int m = 0; m <= MARKER_NP3_BOOKMARK; ++m) {
if (TEST_BIT(int, m, markers)) {
SciCall_MarkerDelete(ln, m);
}
}
markers = SciCall_MarkerGet(ln);
}
}
// ----------------------------------------------------------------------------
#endif //_NP3_NOTEPAD3_H_

View File

@ -230,6 +230,14 @@ typedef enum STATUS_SECTOR_T {
// --------------------------------------------------------------------------
// |- len -|
// 0000000111111111000000000000
// |-- pos ---|
#define BITMASK_GEN(typ, pos, len) (~(~((typ)0ull) << (len)) << (pos))
#define TEST_BIT(typ, pos, set) (BITMASK_GEN(typ, pos, 1) & (set))
// --------------------------------------------------------------------------
typedef struct FILEVARS {
int mask;
@ -341,10 +349,25 @@ typedef enum MARKER_ID {
MARKER_NP3_BOOKMARK
} MARKER_ID;
// ASSERT( MARKER_NP3_BOOKMARK < SC_MARKNUM_HISTORY_REVERTED_TO_ORIGIN )
// ASSERT( MARKER_NP3_BOOKMARK < SC_MARKNUM_FOLDEREND )
#define OCCURRENCE_MARKER_BITMASK() (bitmask32_n(MARKER_NP3_BOOKMARK + 1) & ~(1 << MARKER_NP3_OCCURRENCE))
// SC_MARKNUM_HISTORY_REVERTED_TO_ORIGIN 21
// SC_MARKNUM_HISTORY_SAVED 22
// SC_MARKNUM_HISTORY_MODIFIED 23
// SC_MARKNUM_HISTORY_REVERTED_TO_MODIFIED 24
// SC_MARKNUM_FOLDEREND 25
// SC_MARKNUM_FOLDEROPENMID 26
// SC_MARKNUM_FOLDERMIDTAIL 27
// SC_MARKNUM_FOLDERTAIL 28
// SC_MARKNUM_FOLDERSUB 29
// SC_MARKNUM_FOLDER 30
// SC_MARKNUM_FOLDEROPEN 31
#define BOOKMARK_BITMASK() BITMASK_GEN(int, MARKER_NP3_BOOKMARK, 1)
#define OCCURRENCE_MARKER_BITMASK() BITMASK_GEN(int, 0, MARKER_NP3_8+1)
#define ALL_MARKERS_BITMASK() BITMASK_GEN(int, 0, MARKER_NP3_BOOKMARK+1)
extern LPCWSTR WordBookMarks[];