Merge pull request #322 from RaiKoHoff/Bugfixes_0126

Bugfixes 0126
This commit is contained in:
Derick Payne 2018-01-27 11:24:55 +02:00 committed by GitHub
commit f287fd39a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 516 additions and 399 deletions

Binary file not shown.

View File

@ -1613,45 +1613,54 @@ void EditUnescapeCChars(HWND hwnd) {
//
void EditChar2Hex(HWND hwnd) {
//TODO: iterate over complete selection?
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
int iSelStart = SciCall_GetSelectionStart();
const int iCurPos = SciCall_GetCurrentPos();
const int iAnchorPos = SciCall_GetAnchor();
const int iSelStart = SciCall_GetSelectionStart();
int iSelEnd = SciCall_GetSelectionEnd();
if (iSelStart == iSelEnd) {
iSelEnd = (int)SendMessage(hwnd, SCI_POSITIONAFTER, (WPARAM)iSelStart, 0);
if (iCurPos == iAnchorPos) {
iSelEnd = SciCall_PositionAfter(iCurPos);
}
if (iSelStart == iSelEnd) { return; }
//TODO: iterate over complete selection?
if ((iSelEnd - iSelStart) != 1) { return; }
char ch[32] = { '\0' };
WCHAR wch[32] = { L'\0' };
EditSelectEx(hwnd, iSelStart, iSelEnd);
if ((int)SendMessage(hwnd, SCI_GETSELTEXT, 0, 0) <= COUNTOF(ch))
{
SendMessage(hwnd, SCI_GETSELTEXT, 0, (LPARAM)ch);
SendMessage(hwnd, SCI_GETSELTEXT, 0, (LPARAM)ch);
if (ch[0] == '\0') {
StringCchCopyA(ch, COUNTOF(ch), "\\x00");
}
else {
UINT cp = Encoding_SciGetCodePage(hwnd);
MultiByteToWideCharStrg(cp, ch, wch);
if (wch[0] <= 0xFF)
StringCchPrintfA(ch, COUNTOF(ch), "\\x%02X", wch[0] & 0xFF);
else
StringCchPrintfA(ch, COUNTOF(ch), "\\u%04X", wch[0]);
}
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ch);
if (ch[0] == '\0') {
StringCchCopyA(ch, COUNTOF(ch), "\\x00");
}
else {
UINT cp = Encoding_SciGetCodePage(hwnd);
MultiByteToWideCharStrg(cp, ch, wch);
if (wch[0] <= 0xFF)
StringCchPrintfA(ch, COUNTOF(ch), "\\x%02X", wch[0] & 0xFF);
else
StringCchPrintfA(ch, COUNTOF(ch), "\\u%04X", wch[0]);
}
const int iReplLen = StringCchLenA(ch, COUNTOF(ch));
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ch);
EditSelectEx(hwnd, iSelStart, iSelStart + StringCchLenA(ch, COUNTOF(ch)));
if (iCurPos < iAnchorPos) {
EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos);
}
else if (iCurPos > iAnchorPos) {
EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iReplLen);
}
else { // empty selection
EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos + iReplLen);
}
}
@ -1660,65 +1669,133 @@ void EditChar2Hex(HWND hwnd) {
//
// EditHex2Char()
//
void EditHex2Char(HWND hwnd) {
if (SciCall_IsSelectionEmpty())
return;
void EditHex2Char(HWND hwnd)
{
if (SciCall_IsSelectionEmpty()) { return; }
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
char ch[32] = { L'\0' };
int i;
BOOL bTrySelExpand = FALSE;
int iCurPos = SciCall_GetCurrentPos();
int iAnchorPos = SciCall_GetAnchor();
int iSelStart = SciCall_GetSelectionStart();
int iSelEnd = SciCall_GetSelectionEnd();
const int iSelEnd = SciCall_GetSelectionEnd();
char ch[32] = { L'\0' };
if ((int)SendMessage(hwnd, SCI_GETSELTEXT, 0, 0) <= COUNTOF(ch))
{
SendMessage(hwnd, SCI_GETSELTEXT, 0, (LPARAM)ch);
BOOL bTrySelExpand = FALSE;
SendMessage(hwnd, SCI_GETSELTEXT, 0, (LPARAM)ch);
ch[31] = '\0';
if (StrChrIA(ch, ' ') || StrChrIA(ch, '\t') || StrChrIA(ch, '\r') || StrChrIA(ch, '\n') || StrChrIA(ch, '-'))
if (StrChrIA(ch, ' ') || StrChrIA(ch, '\t') || StrChrIA(ch, '\r') || StrChrIA(ch, '\n') || StrChrIA(ch, '-')) {
return;
}
if (StrCmpNIA(ch, "\\x", 2) == 0 || StrCmpNIA(ch, "\\u", 2) == 0) {
ch[0] = '0';
ch[1] = 'x';
}
else if (StrChrIA("xu", ch[0])) {
ch[0] = '0';
bTrySelExpand = TRUE;
}
else
return;
int i = 0;
if (sscanf_s(ch, "%x", &i) == 1) {
int cch;
int cch = 0;
if (i == 0) {
ch[0] = 0;
cch = 1;
}
else {
WCHAR wch[8] = { L'\0' };
UINT cp = Encoding_SciGetCodePage(hwnd);
WCHAR wch[4];
StringCchPrintf(wch, COUNTOF(wch), L"%lc", (WCHAR)i);
StringCchPrintfW(wch, COUNTOF(wch), L"%lc", (WCHAR)i);
cch = WideCharToMultiByteStrg(cp, wch, ch) - 1;
if (bTrySelExpand && (char)SendMessage(hwnd, SCI_GETCHARAT, (WPARAM)iSelStart - 1, 0) == '\\') {
iSelStart--;
--iSelStart;
if (iCurPos < iAnchorPos) { --iCurPos; } else { --iAnchorPos; }
}
}
EditSelectEx(hwnd, iSelStart, iSelEnd);
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ch);
EditSelectEx(hwnd, iSelStart, iSelStart + cch);
if (iCurPos < iAnchorPos)
EditSelectEx(hwnd, iCurPos + cch, iCurPos);
else
EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cch);
}
}
}
//=============================================================================
//
// EditFindMatchingBrace()
//
void EditFindMatchingBrace(HWND hwnd)
{
BOOL bIsAfter = FALSE;
int iMatchingBracePos = -1;
const int iCurPos = SciCall_GetCurrentPos();
const char c = SciCall_GetCharAt(iCurPos);
if (StrChrA("()[]{}", c)) {
iMatchingBracePos = (int)SendMessage(hwnd, SCI_BRACEMATCH, iCurPos, 0);
}
else { // Try one before
const int iPosBefore = SciCall_PositionBefore(iCurPos);
const char cb = SciCall_GetCharAt(iPosBefore);
if (StrChrA("()[]{}", cb)) {
iMatchingBracePos = (int)SendMessage(hwnd, SCI_BRACEMATCH, iPosBefore, 0);
}
bIsAfter = TRUE;
}
if (iMatchingBracePos != -1) {
iMatchingBracePos = bIsAfter ? iMatchingBracePos : SciCall_PositionAfter(iMatchingBracePos);
EditSelectEx(hwnd, iMatchingBracePos, iMatchingBracePos);
}
}
//=============================================================================
//
// EditSelectToMatchingBrace()
//
void EditSelectToMatchingBrace(HWND hwnd)
{
BOOL bIsAfter = FALSE;
int iMatchingBracePos = -1;
const int iCurPos = SciCall_GetCurrentPos();
const char c = SciCall_GetCharAt(iCurPos);
if (StrChrA("()[]{}", c)) {
iMatchingBracePos = (int)SendMessage(hwnd, SCI_BRACEMATCH, iCurPos, 0);
}
else { // Try one before
const int iPosBefore = SciCall_PositionBefore(iCurPos);
const char cb = SciCall_GetCharAt(iPosBefore);
if (StrChrA("()[]{}", cb)) {
iMatchingBracePos = (int)SendMessage(hwnd, SCI_BRACEMATCH, iPosBefore, 0);
}
bIsAfter = TRUE;
}
if (iMatchingBracePos != -1) {
if (bIsAfter)
EditSelectEx(hwnd, iCurPos, iMatchingBracePos);
else
EditSelectEx(hwnd, iCurPos, SciCall_PositionAfter(iMatchingBracePos));
}
}
//=============================================================================
//
// EditModifyNumber()
@ -2702,8 +2779,8 @@ void EditAlignText(HWND hwnd,int nMode)
SendMessage(hwnd, SCI_SETTARGETRANGE, iPos, SciCall_GetLineEndPosition(iLine));
SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)cch, (LPARAM)tchLineBuf);
if (nMode == ALIGN_LEFT)
SendMessage(hwnd,SCI_SETLINEINDENTATION,(WPARAM)iLine,(LPARAM)iMinIndent);
if (nMode == ALIGN_LEFT)
SendMessage(hwnd, SCI_SETLINEINDENTATION, (WPARAM)iLine, (LPARAM)iMinIndent);
}
}
}
@ -2712,24 +2789,24 @@ void EditAlignText(HWND hwnd,int nMode)
ObserveNotifyChangeEvent();
}
else
MsgBox(MBINFO,IDS_BUFFERTOOSMALL);
MsgBox(MBINFO, IDS_BUFFERTOOSMALL);
if (bModified) {
SendMessage(hwnd, SCI_ENDUNDOACTION, 0, 0);
}
if (iCurPos < iAnchorPos) {
iCurPos = SciCall_PositionFromLine(iLineStart);
iAnchorPos = SciCall_PositionFromLine(iLineEnd + 1);
}
else {
iAnchorPos = SciCall_PositionFromLine(iLineStart);
iCurPos = SciCall_PositionFromLine(iLineEnd + 1);
}
EditSelectEx(hwnd, iAnchorPos, iCurPos);
if (bModified) {
SendMessage(hwnd, SCI_ENDUNDOACTION, 0, 0);
}
if (iCurPos < iAnchorPos) {
iCurPos = SciCall_PositionFromLine(iLineStart);
iAnchorPos = SciCall_PositionFromLine(iLineEnd + 1);
}
else {
iAnchorPos = SciCall_PositionFromLine(iLineStart);
iCurPos = SciCall_PositionFromLine(iLineEnd + 1);
}
EditSelectEx(hwnd, iAnchorPos, iCurPos);
}
else
MsgBox(MBWARN,IDS_SELRECT);
MsgBox(MBWARN, IDS_SELRECT);
}
@ -2739,8 +2816,7 @@ void EditAlignText(HWND hwnd,int nMode)
//
void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose)
{
if (SciCall_IsSelectionRectangle())
{
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
@ -2748,8 +2824,10 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose)
char mszOpen[256 * 3] = { '\0' };
char mszClose[256 * 3] = { '\0' };
int iSelStart = SciCall_GetSelectionStart();
int iSelEnd = SciCall_GetSelectionEnd();
const int iCurPos = SciCall_GetCurrentPos();
const int iAnchorPos = SciCall_GetAnchor();
const int iSelStart = SciCall_GetSelectionStart();
const int iSelEnd = SciCall_GetSelectionEnd();
UINT mbcp = Encoding_SciGetCodePage(hwnd);
@ -2758,42 +2836,25 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose)
if (lstrlen(pwszClose))
WideCharToMultiByteStrg(mbcp, pwszClose, mszClose);
const int iLenOpen = StringCchLenA(mszOpen, COUNTOF(mszOpen));
const int iLenClose = StringCchLenA(mszClose, COUNTOF(mszClose));
int token = BeginUndoAction();
EditEnterTargetTransaction();
if (iLenOpen > 0) {
SciCall_SetSel(iSelStart, iSelStart);
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)mszOpen);
SendMessage(hwnd, SCI_SETTARGETRANGE, iSelStart, iSelStart);
SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)mszOpen);
}
if (iLenClose > 0) {
SciCall_SetSel(iSelEnd + iLenOpen, iSelEnd + iLenOpen);
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)mszClose);
SendMessage(hwnd, SCI_SETTARGETRANGE, iSelEnd + iLenOpen, iSelEnd + iLenOpen);
SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)mszClose);
}
EditLeaveTargetTransaction();
// Fix selection
if (iSelStart == iSelEnd) {
const int iPos = iSelStart + iLenOpen;
EditSelectEx(hwnd, iPos, iPos);
}
else {
int iCurPos = SciCall_GetCurrentPos();
int iAnchorPos = SciCall_GetAnchor();
if (iCurPos < iAnchorPos) {
iCurPos = iSelStart + iLenOpen;
iAnchorPos = iSelEnd + iLenOpen;
}
else {
iAnchorPos = iSelStart + iLenOpen;
iCurPos = iSelEnd + iLenOpen;
}
EditSelectEx(hwnd, iAnchorPos, iCurPos);
}
EndUndoAction(token);
EditSelectEx(hwnd, iAnchorPos + iLenOpen, iCurPos + iLenOpen);
}
@ -2801,114 +2862,115 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose)
//
// EditToggleLineComments()
//
void EditToggleLineComments(HWND hwnd,LPCWSTR pwszComment,BOOL bInsertAtStart)
void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, BOOL bInsertAtStart)
{
int iSelStart = SciCall_GetSelectionStart();
int iSelEnd = SciCall_GetSelectionEnd();
int iCurPos = SciCall_GetCurrentPos();
const int iCurPos = SciCall_GetCurrentPos();
const int iAnchorPos = SciCall_GetAnchor();
const int iSelStart = SciCall_GetSelectionStart();
const int iSelEnd = SciCall_GetSelectionEnd();
UINT mbcp = Encoding_SciGetCodePage(hwnd);
char mszComment[256*3] = { '\0' };
const int iSelBegCol = SciCall_GetColumn(iSelStart);
if (lstrlen(pwszComment))
WideCharToMultiByte(mbcp,0,pwszComment,-1,mszComment,COUNTOF(mszComment),NULL,NULL);
char mszComment[256 * 3] = { '\0' };
int cchComment = StringCchLenA(mszComment,COUNTOF(mszComment));
if ((!SciCall_IsSelectionRectangle()) && (cchComment > 0))
{
int iCommentCol = 0;
int iLineStart = SciCall_LineFromPosition(iSelStart);
int iLineEnd = SciCall_LineFromPosition(iSelEnd);
if (iSelEnd <= SciCall_PositionFromLine(iLineEnd))
{
if ((iLineEnd - iLineStart) >= 1)
--iLineEnd;
}
if (!bInsertAtStart) {
iCommentCol = 1024;
for (int iLine = iLineStart; iLine <= iLineEnd; iLine++) {
int iLineEndPos = SciCall_GetLineEndPosition(iLine);
int iLineIndentPos = (int)SendMessage(hwnd,SCI_GETLINEINDENTPOSITION,(WPARAM)iLine,0);
if (iLineIndentPos != iLineEndPos) {
int iIndentColumn = SciCall_GetColumn(iLineIndentPos);
iCommentCol = min(iCommentCol,iIndentColumn);
}
}
}
int token = BeginUndoAction();
IgnoreNotifyChangeEvent();
EditEnterTargetTransaction();
for (int iLine = iLineStart; iLine <= iLineEnd; iLine++)
{
int iIndentPos = (int)SendMessage(hwnd,SCI_GETLINEINDENTPOSITION,(WPARAM)iLine,0);
if (iIndentPos == SciCall_GetLineEndPosition(iLine))
continue;
char tchBuf[32] = { L'\0' };
struct Sci_TextRange tr = { { 0, 0 }, NULL };
tr.chrg.cpMin = iIndentPos;
tr.chrg.cpMax = tr.chrg.cpMin + min(31,cchComment);
tr.lpstrText = tchBuf;
SendMessage(hwnd,SCI_GETTEXTRANGE,0,(LPARAM)&tr);
int iAction = 0;
if (StrCmpNIA(tchBuf,mszComment,cchComment) == 0) {
switch (iAction) {
case 0:
iAction = 2;
case 2:
SendMessage(hwnd, SCI_SETTARGETRANGE, iIndentPos, iIndentPos + cchComment);
SendMessage(hwnd, SCI_REPLACETARGET, 0, (LPARAM)"");
break;
case 1:
break;
}
}
else {
switch (iAction) {
case 0:
iAction = 1;
case 1:
{
int iCommentPos = (int)SendMessage(hwnd, SCI_FINDCOLUMN, (WPARAM)iLine, (LPARAM)iCommentCol);
SendMessage(hwnd, SCI_INSERTTEXT, (WPARAM)iCommentPos, (LPARAM)mszComment);
}
break;
case 2:
break;
}
}
}
EditLeaveTargetTransaction();
ObserveNotifyChangeEvent();
if (iSelStart != iSelEnd)
{
int iAnchorPos;
if (iCurPos == iSelStart) {
iCurPos = SciCall_PositionFromLine(iLineStart);
iAnchorPos = SciCall_PositionFromLine(iLineEnd + 1);
}
else {
iAnchorPos = SciCall_PositionFromLine(iLineStart);
iCurPos = SciCall_PositionFromLine(iLineEnd + 1);
}
EditSelectEx(hwnd, iAnchorPos, iCurPos);
}
EndUndoAction(token);
if (lstrlen(pwszComment)) {
UINT mbcp = Encoding_SciGetCodePage(hwnd);
WideCharToMultiByte(mbcp, 0, pwszComment, -1, mszComment, COUNTOF(mszComment), NULL, NULL);
}
const int cchComment = StringCchLenA(mszComment, COUNTOF(mszComment));
if (SciCall_IsSelectionRectangle() || (cchComment == 0)) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
const int iLineStart = SciCall_LineFromPosition(iSelStart);
int iLineEnd = SciCall_LineFromPosition(iSelEnd);
if (iSelEnd <= SciCall_PositionFromLine(iLineEnd)) {
if ((iLineEnd - iLineStart) >= 1)
--iLineEnd;
}
int iSelStartOffset = cchComment;
int iSelEndOffset = 0;
int iCommentCol = 0;
if (!bInsertAtStart) {
iCommentCol = 1024;
for (int iLine = iLineStart; iLine <= iLineEnd; iLine++)
{
const int iLineEndPos = SciCall_GetLineEndPosition(iLine);
const int iLineIndentPos = (int)SendMessage(hwnd, SCI_GETLINEINDENTPOSITION, (WPARAM)iLine, 0);
if (iLineIndentPos != iLineEndPos) {
const int iIndentColumn = SciCall_GetColumn(iLineIndentPos);
iCommentCol = min(iCommentCol, iIndentColumn);
if ((iLine == iLineStart) && (iIndentColumn > iSelBegCol)) { iSelStartOffset = 0; }
}
else
if (iLine == iLineStart) { iSelStartOffset = 0; }
}
}
IgnoreNotifyChangeEvent();
EditEnterTargetTransaction();
int iAction = 0;
for (int iLine = iLineStart; iLine <= iLineEnd; iLine++)
{
const int iIndentPos = (int)SendMessage(hwnd, SCI_GETLINEINDENTPOSITION, (WPARAM)iLine, 0);
if (iIndentPos == SciCall_GetLineEndPosition(iLine))
continue;
char tchBuf[32] = { L'\0' };
struct Sci_TextRange tr = { { 0, 0 }, NULL };
tr.chrg.cpMin = iIndentPos;
tr.chrg.cpMax = tr.chrg.cpMin + min(31, cchComment);
tr.lpstrText = tchBuf;
SendMessage(hwnd, SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
if (StrCmpNIA(tchBuf, mszComment, cchComment) == 0) {
switch (iAction) {
case 0:
iAction = 2;
case 2:
SendMessage(hwnd, SCI_SETTARGETRANGE, iIndentPos, iIndentPos + cchComment);
SendMessage(hwnd, SCI_REPLACETARGET, 0, (LPARAM)"");
iSelEndOffset -= cchComment;
if (iLine == iLineStart) { iSelStartOffset = (0 - iSelStartOffset); }
break;
case 1:
break;
}
}
else {
switch (iAction) {
case 0:
iAction = 1;
case 1:
{
const int iCommentPos = (int)SendMessage(hwnd, SCI_FINDCOLUMN, (WPARAM)iLine, (LPARAM)iCommentCol);
SendMessage(hwnd, SCI_INSERTTEXT, (WPARAM)iCommentPos, (LPARAM)mszComment);
iSelEndOffset += cchComment;
}
break;
case 2:
break;
}
}
}
EditLeaveTargetTransaction();
ObserveNotifyChangeEvent();
if (iCurPos < iAnchorPos)
EditSelectEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset);
else if (iCurPos > iAnchorPos)
EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset);
else
MsgBox(MBWARN,IDS_SELRECT);
EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset);
}
@ -3004,24 +3066,20 @@ void EditPadWithSpaces(HWND hwnd,BOOL bSkipEmpty,BOOL bNoUndoGroup)
for (iLine = iLineStart; iLine <= iLineEnd; iLine++) {
int iPos;
int iPadLen;
int iLineSelEndPos;
iLineSelEndPos = SciCall_GetLineSelEndPosition(iLine);
const int iLineSelEndPos = SciCall_GetLineSelEndPosition(iLine);
if (bIsRectangular && (INVALID_POSITION == iLineSelEndPos))
continue;
iPos = SciCall_GetLineEndPosition(iLine);
const int iPos = SciCall_GetLineEndPosition(iLine);
if (bIsRectangular && iPos > iLineSelEndPos)
continue;
if (bSkipEmpty && (SciCall_PositionFromLine(iLine) >= iPos))
continue;
int iCol = SciCall_GetColumn(iPos);
const int iCol = SciCall_GetColumn(iPos);
//iCol += (int)SendMessage(hwnd, SCI_GETSELECTIONNCARETVIRTUALSPACE, 0, 0);
iPadLen = iMaxColumn - iCol;
const int iPadLen = iMaxColumn - iCol;
pmszPadStr[iPadLen] = '\0';
SendMessage(hwnd, SCI_SETTARGETRANGE, iPos, iPos);
@ -3062,8 +3120,8 @@ void EditPadWithSpaces(HWND hwnd,BOOL bSkipEmpty,BOOL bNoUndoGroup)
}
else if (bIsRectangular)
{
int iCurPos = (int)SendMessage(hwnd,SCI_FINDCOLUMN,(WPARAM)iRcCurLine,(LPARAM)iRcCurCol);
int iAnchorPos = (int)SendMessage(hwnd,SCI_FINDCOLUMN,(WPARAM)iRcAnchorLine,(LPARAM)iRcAnchorCol);
const int iCurPos = (int)SendMessage(hwnd,SCI_FINDCOLUMN,(WPARAM)iRcCurLine,(LPARAM)iRcCurCol);
const int iAnchorPos = (int)SendMessage(hwnd,SCI_FINDCOLUMN,(WPARAM)iRcAnchorLine,(LPARAM)iRcAnchorCol);
SendMessage(hwnd,SCI_SETRECTANGULARSELECTIONCARET,(WPARAM)iCurPos,0);
SendMessage(hwnd,SCI_SETRECTANGULARSELECTIONANCHOR,(WPARAM)iAnchorPos,0);
}
@ -3079,9 +3137,12 @@ void EditStripFirstCharacter(HWND hwnd)
{
int iSelStart = 0;
int iSelEnd = 0;
BOOL bIsSelEmpty = SciCall_IsSelectionEmpty();
if (!bIsSelEmpty) {
if (SciCall_IsSelectionEmpty())
{
iSelEnd = SciCall_GetTextLength();
}
else {
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
@ -3089,22 +3150,16 @@ void EditStripFirstCharacter(HWND hwnd)
iSelStart = SciCall_GetSelectionStart();
iSelEnd = SciCall_GetSelectionEnd();
}
else {
iSelEnd = SciCall_GetTextLength();
}
int iLineStart = SciCall_LineFromPosition(iSelStart);
int iLineEnd = SciCall_LineFromPosition(iSelEnd);
if (iSelStart > SciCall_PositionFromLine(iLineStart)) { ++iLineStart; }
if (iSelEnd <= SciCall_PositionFromLine(iLineEnd)) { --iLineEnd; }
const int iLineStart = SciCall_LineFromPosition(iSelStart);
const int iLineEnd = SciCall_LineFromPosition(iSelEnd);
IgnoreNotifyChangeEvent();
EditEnterTargetTransaction();
int chCnt = 0;
for (int iLine = iLineStart; iLine <= iLineEnd; ++iLine) {
int iPos = SciCall_PositionFromLine(iLine);
const int iPos = SciCall_PositionFromLine(iLine);
if (iPos < SciCall_GetLineEndPosition(iLine)) {
SendMessage(hwnd, SCI_SETTARGETRANGE, (WPARAM)iPos, (LPARAM)SciCall_PositionAfter(iPos));
SendMessage(hwnd, SCI_REPLACETARGET, 0, (LPARAM)"");
@ -3125,34 +3180,29 @@ void EditStripLastCharacter(HWND hwnd)
{
int iSelStart = 0;
int iSelEnd = 0;
BOOL bIsSelEmpty = SciCall_IsSelectionEmpty();
if (!bIsSelEmpty) {
if (SciCall_IsSelectionEmpty()) {
iSelEnd = SciCall_GetTextLength();
}
else {
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
iSelStart = SciCall_GetSelectionStart();
iSelEnd = SciCall_GetSelectionEnd();
}
else {
iSelEnd = SciCall_GetTextLength();
}
int iLineStart = SciCall_LineFromPosition(iSelStart);
int iLineEnd = SciCall_LineFromPosition(iSelEnd);
if (iSelStart >= SciCall_GetLineEndPosition(iLineStart)) { ++iLineStart; }
if (iSelEnd < SciCall_GetLineEndPosition(iLineEnd)) { --iLineEnd; }
const int iLineStart = SciCall_LineFromPosition(iSelStart);
const int iLineEnd = SciCall_LineFromPosition(iSelEnd);
IgnoreNotifyChangeEvent();
EditEnterTargetTransaction();
for (int iLine = iLineStart; iLine <= iLineEnd; ++iLine)
{
int iStartPos = SciCall_PositionFromLine(iLine);
int iEndPos = SciCall_GetLineEndPosition(iLine);
const int iStartPos = SciCall_PositionFromLine(iLine);
const int iEndPos = SciCall_GetLineEndPosition(iLine);
if (iStartPos < iEndPos)
{
SendMessage(hwnd, SCI_SETTARGETRANGE, (WPARAM)SciCall_PositionBefore(iEndPos), (LPARAM)iEndPos);
@ -3175,24 +3225,20 @@ void EditStripTrailingBlanks(HWND hwnd, BOOL bIgnoreSelection)
int iSelStart = 0;
int iSelEnd = 0;
if (!bIgnoreSelection && !SciCall_IsSelectionEmpty()) {
if (bIgnoreSelection || SciCall_IsSelectionEmpty()) {
iSelEnd = SciCall_GetTextLength();
}
else {
if (SciCall_IsSelectionRectangle()) {
MsgBox(MBWARN, IDS_SELRECT);
return;
}
iSelStart = SciCall_GetSelectionStart();
iSelEnd = SciCall_GetSelectionEnd();
}
else {
iSelEnd = SciCall_GetTextLength();
}
int iLineStart = SciCall_LineFromPosition(iSelStart);
int iLineEnd = SciCall_LineFromPosition(iSelEnd);
if (iSelStart >= SciCall_GetLineEndPosition(iLineStart)) { ++iLineStart; }
if (iSelEnd < SciCall_GetLineEndPosition(iLineEnd)) { --iLineEnd; }
const int iLineStart = SciCall_LineFromPosition(iSelStart);
const int iLineEnd = SciCall_LineFromPosition(iSelEnd);
IgnoreNotifyChangeEvent();
@ -3200,8 +3246,8 @@ void EditStripTrailingBlanks(HWND hwnd, BOOL bIgnoreSelection)
for (int iLine = iLineStart; iLine <= iLineEnd; ++iLine)
{
int iStartPos = SciCall_PositionFromLine(iLine);
int iEndPos = SciCall_GetLineEndPosition(iLine);
const int iStartPos = SciCall_PositionFromLine(iLine);
const int iEndPos = SciCall_GetLineEndPosition(iLine);
int i = iEndPos;
char ch = '\0';
@ -3307,11 +3353,11 @@ void EditCompressSpaces(HWND hwnd)
const int iNewLen = StringCchLenA(pszOut, LocalSize(pszOut));
if (iCurPos > iAnchorPos) {
EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen);
if (iCurPos < iAnchorPos) {
EditSelectEx(hwnd, iCurPos + iNewLen, iCurPos);
}
else if (iCurPos < iAnchorPos) {
EditSelectEx(hwnd, iCurPos, iCurPos + iNewLen);
else if (iCurPos > iAnchorPos) {
EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen);
}
else { // empty selection
int iNewPos = iCurPos;
@ -3980,25 +4026,27 @@ void EditSortLines(HWND hwnd, int iSortFlags)
//
void EditSelectEx(HWND hwnd, int iAnchorPos, int iCurrentPos)
{
if (iAnchorPos < 0) {
iAnchorPos = ((iCurrentPos >= 0) ? iCurrentPos : 0);
if ((iAnchorPos < 0) && (iCurrentPos < 0)) {
SendMessage(hwnd, SCI_SELECTALL, 0, 0);
}
else if (iAnchorPos < 0) {
iAnchorPos = 0;
}
if (iCurrentPos < 0) {
iCurrentPos = ((iAnchorPos >= 0) ? iAnchorPos : 0);
iCurrentPos = SciCall_GetTextLength();
}
int iNewLine = SciCall_LineFromPosition(iCurrentPos);
int iAnchorLine = SciCall_LineFromPosition(iAnchorPos);
const int iNewLine = SciCall_LineFromPosition(iCurrentPos);
const int iAnchorLine = SciCall_LineFromPosition(iAnchorPos);
// Ensure that the first and last lines of a selection are always unfolded
// This needs to be done *before* the SCI_SETSEL message
SciCall_EnsureVisible(iAnchorLine);
if (iAnchorLine != iNewLine) {
SciCall_EnsureVisible(iNewLine);
}
if (iAnchorLine != iNewLine) { SciCall_EnsureVisible(iNewLine); }
SciCall_SetSel(iAnchorPos, iCurrentPos);
SciCall_ScrollRange(iAnchorPos, iCurrentPos);
SciCall_ScrollRange(iCurrentPos, iAnchorPos);
// remember x-pos for moving caret vertically
SendMessage(hwnd, SCI_CHOOSECARETX, 0, 0);

View File

@ -78,6 +78,8 @@ void EditEscapeCChars(HWND);
void EditUnescapeCChars(HWND);
void EditChar2Hex(HWND);
void EditHex2Char(HWND);
void EditFindMatchingBrace(HWND);
void EditSelectToMatchingBrace(HWND);
void EditModifyNumber(HWND,BOOL);
void EditTabsToSpaces(HWND,int,BOOL);

View File

@ -417,19 +417,31 @@ typedef enum {
FOLD = -1
} FOLD_ACTION;
typedef enum {
UP = -1,
NONE = 0,
DOWN = 1
} FOLD_MOVE;
#define FOLD_CHILDREN SCMOD_CTRL
#define FOLD_SIBLINGS SCMOD_SHIFT
BOOL __stdcall FoldToggleNode( int ln, FOLD_ACTION action )
{
BOOL fExpanded = SciCall_GetFoldExpanded(ln);
const BOOL fExpanded = SciCall_GetFoldExpanded(ln);
if ((action == FOLD && fExpanded) || (action == EXPAND && !fExpanded))
{
SciCall_ToggleFold(ln);
return(TRUE);
return TRUE;
}
return(FALSE);
else if (action == SNIFF)
{
SciCall_ToggleFold(ln);
return TRUE;
}
return FALSE;
}
@ -524,7 +536,6 @@ void __stdcall FoldClick( int ln, int mode )
if (!(SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG))
{
// Not a fold point: need to look for a double-click
if ( prev.ln == ln && prev.mode == mode &&
GetTickCount() - prev.dwTickCount <= GetDoubleClickTime() )
{
@ -547,44 +558,38 @@ void __stdcall FoldClick( int ln, int mode )
}
}
FoldPerformAction(ln, mode, SNIFF);
if (fGotoFoldPoint)
if (fGotoFoldPoint) {
EditJumpTo(g_hwndEdit, ln + 1, 0);
}
}
void __stdcall FoldAltArrow( int key, int mode )
{
// Because Alt-Shift is already in use (and because the sibling fold feature
// is not as useful from the keyboard), only the Ctrl modifier is supported
if (bShowCodeFolding && (mode & (SCMOD_ALT | SCMOD_SHIFT)) == SCMOD_ALT)
void __stdcall FoldAltArrow( FOLD_MOVE move, FOLD_ACTION action )
{
if (bShowCodeFolding)
{
int ln = SciCall_LineFromPosition(SciCall_GetCurrentPos());
// Jump to the next visible fold point
if (key == SCK_DOWN && !(mode & SCMOD_CTRL))
if (move == DOWN)
{
int lnTotal = SciCall_GetLineCount();
for (ln = ln + 1; ln < lnTotal; ++ln)
{
if ( SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG &&
SciCall_GetLineVisible(ln) )
if ( (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG) && SciCall_GetLineVisible(ln) )
{
EditJumpTo(g_hwndEdit, ln + 1, 0);
return;
}
}
}
// Jump to the previous visible fold point
else if (key == SCK_UP && !(mode & SCMOD_CTRL))
else if (move == UP) // Jump to the previous visible fold point
{
for (ln = ln - 1; ln >= 0; --ln)
{
if ( SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG &&
SciCall_GetLineVisible(ln) )
if ( (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG) && SciCall_GetLineVisible(ln) )
{
EditJumpTo(g_hwndEdit, ln + 1, 0);
return;
@ -593,10 +598,11 @@ void __stdcall FoldAltArrow( int key, int mode )
}
// Perform a fold/unfold operation
else if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
{
if (key == SCK_LEFT ) FoldPerformAction(ln, mode, FOLD);
if (key == SCK_RIGHT) FoldPerformAction(ln, mode, EXPAND);
if (action != SNIFF) {
FoldToggleNode(ln, action);
}
}
}
}
@ -2338,7 +2344,7 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
EnableCmd(hmenu,IDM_EDIT_REDO,SendMessage(g_hwndEdit,SCI_CANREDO,0,0) /*&& !bReadOnly*/);
i = !(BOOL)SendMessage(g_hwndEdit, SCI_GETSELECTIONEMPTY, 0, 0);
i = !SciCall_IsSelectionEmpty();
i2 = SciCall_GetTextLength();
i3 = (int)SendMessage(g_hwndEdit, SCI_CANPASTE, 0, 0);
@ -2403,7 +2409,7 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
EnableCmd(hmenu,IDM_EDIT_ESCAPECCHARS,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_UNESCAPECCHARS,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CHAR2HEX,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CHAR2HEX,TRUE /*&& !bReadOnly*/); // Char2Hex allowed for char after curr pos
EnableCmd(hmenu,IDM_EDIT_HEX2CHAR,i /*&& !bReadOnly*/);
//EnableCmd(hmenu,IDM_EDIT_INCREASENUM,i /*&& !bReadOnly*/);
@ -3324,18 +3330,53 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_INDENT:
{
int token = BeginUndoAction();
SendMessage(g_hwndEdit,SCI_TAB,0,0);
EndUndoAction(token);
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
if (bTabIndents && !SciCall_IsSelectionEmpty()) {
const int iLineSelStart = SciCall_LineFromPosition(SciCall_GetSelectionStart());
const int iLineSelEnd = SciCall_LineFromPosition(SciCall_GetSelectionEnd());
if (iLineSelStart == iLineSelEnd) {
SendMessage(g_hwndEdit, SCI_VCHOME, 0, 0);
}
}
SendMessage(g_hwndEdit, SCI_TAB, 0, 0);
if (token >= 0) { EndUndoAction(token); }
}
break;
case IDM_EDIT_UNINDENT:
{
int token = BeginUndoAction();
SendMessage(g_hwndEdit,SCI_BACKTAB,0,0);
EndUndoAction(token);
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
if (bTabIndents && !SciCall_IsSelectionEmpty()) {
const int iLineSelStart = SciCall_LineFromPosition(SciCall_GetSelectionStart());
const int iLineSelEnd = SciCall_LineFromPosition(SciCall_GetSelectionEnd());
if (iLineSelStart == iLineSelEnd) {
SendMessage(g_hwndEdit, SCI_VCHOME, 0, 0);
}
}
SendMessage(g_hwndEdit, SCI_BACKTAB, 0, 0);
if (token >= 0) { EndUndoAction(token); }
}
break;
case CMD_CTRLTAB:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
SendMessage(g_hwndEdit, SCI_SETTABINDENTS, FALSE, 0);
SendMessage(g_hwndEdit, SCI_SETUSETABS, TRUE, 0);
SendMessage(g_hwndEdit, SCI_TAB, 0, 0);
SendMessage(g_hwndEdit, SCI_SETUSETABS, !bTabsAsSpaces, 0);
SendMessage(g_hwndEdit, SCI_SETTABINDENTS, bTabIndents, 0);
if (token >= 0) { EndUndoAction(token); }
}
break;
@ -3343,7 +3384,9 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_ENCLOSESELECTION:
if (EditEncloseSelectionDlg(hwnd,wchPrefixSelection,wchAppendSelection)) {
BeginWaitCursor(NULL);
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit,wchPrefixSelection,wchAppendSelection);
EndUndoAction(token);
EndWaitCursor();
}
break;
@ -3640,8 +3683,11 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
WCHAR wszOpen[256] = { L'\0' };
WCHAR wszClose[256] = { L'\0' };
if (EditInsertTagDlg(hwnd,wszOpen,wszClose))
EditEncloseSelection(g_hwndEdit,wszOpen,wszClose);
if (EditInsertTagDlg(hwnd, wszOpen, wszClose)) {
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, wszOpen, wszClose);
EndUndoAction(token);
}
}
break;
@ -3763,7 +3809,12 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_LINECOMMENT:
switch (SendMessage(g_hwndEdit,SCI_GETLEXER,0,0)) {
{
BeginWaitCursor(NULL);
int token = BeginUndoAction();
switch (SendMessage(g_hwndEdit, SCI_GETLEXER, 0, 0)) {
default:
case SCLEX_NULL:
case SCLEX_CSS:
case SCLEX_DIFF:
@ -3774,15 +3825,11 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case SCLEX_XML:
case SCLEX_CPP:
case SCLEX_PASCAL:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"//",FALSE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"//", FALSE);
break;
case SCLEX_VBSCRIPT:
case SCLEX_VB:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"'",FALSE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"'", FALSE);
break;
case SCLEX_MAKEFILE:
case SCLEX_PERL:
@ -3797,9 +3844,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case SCLEX_YAML:
case SCLEX_COFFEESCRIPT:
case SCLEX_NIMROD:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"#",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"#", TRUE);
break;
case SCLEX_ASM:
case SCLEX_PROPERTIES:
@ -3807,39 +3852,37 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case SCLEX_AHK:
case SCLEX_NSIS: // # could also be used instead
case SCLEX_INNOSETUP:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L";",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L";", TRUE);
break;
case SCLEX_REGISTRY:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L";;",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L";;", TRUE);
break;
case SCLEX_SQL:
case SCLEX_LUA:
case SCLEX_VHDL:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"--",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"--", TRUE);
break;
case SCLEX_BATCH:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"rem ",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"rem ", TRUE);
break;
case SCLEX_LATEX:
case SCLEX_MATLAB:
BeginWaitCursor(NULL);
EditToggleLineComments(g_hwndEdit,L"%",TRUE);
EndWaitCursor();
EditToggleLineComments(g_hwndEdit, L"%", TRUE);
break;
}
EndUndoAction(token);
EndWaitCursor();
}
break;
case IDM_EDIT_STREAMCOMMENT:
switch (SendMessage(g_hwndEdit,SCI_GETLEXER,0,0)) {
{
int token = BeginUndoAction();
switch (SendMessage(g_hwndEdit, SCI_GETLEXER, 0, 0)) {
default:
case SCLEX_NULL:
case SCLEX_VBSCRIPT:
case SCLEX_MAKEFILE:
@ -3873,20 +3916,22 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case SCLEX_NSIS:
case SCLEX_AVS:
case SCLEX_VHDL:
EditEncloseSelection(g_hwndEdit,L"/*",L"*/");
EditEncloseSelection(g_hwndEdit, L"/*", L"*/");
break;
case SCLEX_PASCAL:
case SCLEX_INNOSETUP:
EditEncloseSelection(g_hwndEdit,L"{",L"}");
EditEncloseSelection(g_hwndEdit, L"{", L"}");
break;
case SCLEX_LUA:
EditEncloseSelection(g_hwndEdit,L"--[[",L"]]");
EditEncloseSelection(g_hwndEdit, L"--[[", L"]]");
break;
case SCLEX_COFFEESCRIPT:
EditEncloseSelection(g_hwndEdit,L"###",L"###");
EditEncloseSelection(g_hwndEdit, L"###", L"###");
break;
case SCLEX_MATLAB:
EditEncloseSelection(g_hwndEdit,L"%{",L"%}");
EditEncloseSelection(g_hwndEdit, L"%{", L"%}");
}
EndUndoAction(token);
}
break;
@ -3936,59 +3981,29 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_CHAR2HEX:
BeginWaitCursor(NULL);
EditChar2Hex(g_hwndEdit);
EndWaitCursor();
{
int token = BeginUndoAction();
EditChar2Hex(g_hwndEdit);
EndUndoAction(token);
}
break;
case IDM_EDIT_HEX2CHAR:
BeginWaitCursor(NULL);
EditHex2Char(g_hwndEdit);
EndWaitCursor();
break;
case IDM_EDIT_FINDMATCHINGBRACE:
{
int iBrace2 = -1;
int iPos = (int)SendMessage(g_hwndEdit,SCI_GETCURRENTPOS,0,0);
char c = (char)SendMessage(g_hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = (int)SendMessage(g_hwndEdit,SCI_BRACEMATCH,iPos,0);
// Try one before
else {
iPos = (int)SendMessage(g_hwndEdit,SCI_POSITIONBEFORE,iPos,0);
c = (char)SendMessage(g_hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = (int)SendMessage(g_hwndEdit,SCI_BRACEMATCH,iPos,0);
}
if (iBrace2 != -1)
SendMessage(g_hwndEdit,SCI_GOTOPOS,(WPARAM)iBrace2,0);
}
EditFindMatchingBrace(g_hwndEdit);
break;
case IDM_EDIT_SELTOMATCHINGBRACE:
{
int iBrace2 = -1;
int iPos = (int)SendMessage(g_hwndEdit,SCI_GETCURRENTPOS,0,0);
char c = (char)SendMessage(g_hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = (int)SendMessage(g_hwndEdit,SCI_BRACEMATCH,iPos,0);
// Try one before
else {
iPos = (int)SendMessage(g_hwndEdit,SCI_POSITIONBEFORE,iPos,0);
c = (char)SendMessage(g_hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = (int)SendMessage(g_hwndEdit,SCI_BRACEMATCH,iPos,0);
}
if (iBrace2 != -1) {
if (iBrace2 > iPos)
SendMessage(g_hwndEdit,SCI_SETSEL,(WPARAM)iPos,(LPARAM)iBrace2+1);
else
SendMessage(g_hwndEdit,SCI_SETSEL,(WPARAM)iPos+1,(LPARAM)iBrace2);
}
int token = BeginUndoAction();
EditSelectToMatchingBrace(g_hwndEdit);
EndUndoAction(token);
}
break;
@ -4865,19 +4880,6 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
break;
case CMD_CTRLTAB:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
SendMessage(g_hwndEdit,SCI_SETTABINDENTS,FALSE,0);
SendMessage(g_hwndEdit,SCI_SETUSETABS,TRUE,0);
SendMessage(g_hwndEdit,SCI_TAB,0,0);
SendMessage(g_hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0);
SendMessage(g_hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
if (token >= 0) EndUndoAction(token);
}
break;
case CMD_RECODEDEFAULT:
{
WCHAR tchCurFile2[MAX_PATH] = { L'\0' };
@ -5166,34 +5168,57 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
}
break;
case CMD_STRINGIFY:
EditEncloseSelection(g_hwndEdit,L"'",L"'");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"'", L"'");
EndUndoAction(token);
}
break;
case CMD_STRINGIFY2:
EditEncloseSelection(g_hwndEdit,L"\"",L"\"");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"\"", L"\"");
EndUndoAction(token);
}
break;
case CMD_EMBRACE:
EditEncloseSelection(g_hwndEdit,L"(",L")");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"(", L")");
EndUndoAction(token);
}
break;
case CMD_EMBRACE2:
EditEncloseSelection(g_hwndEdit,L"[",L"]");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"[", L"]");
EndUndoAction(token);
}
break;
case CMD_EMBRACE3:
EditEncloseSelection(g_hwndEdit,L"{",L"}");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"{", L"}");
EndUndoAction(token);
}
break;
case CMD_EMBRACE4:
EditEncloseSelection(g_hwndEdit,L"`",L"`");
{
int token = BeginUndoAction();
EditEncloseSelection(g_hwndEdit, L"`", L"`");
EndUndoAction(token);
}
break;
@ -5302,11 +5327,27 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case CMD_OPEN_HYPERLINK:
{
OpenHotSpotURL((int)SendMessage(g_hwndEdit, SCI_GETCURRENTPOS, 0, 0), FALSE);
}
break;
case CMD_ALTDOWN:
FoldAltArrow(DOWN, SNIFF);
break;
case CMD_ALTUP:
FoldAltArrow(UP, SNIFF);
break;
case CMD_ALTLEFT:
FoldAltArrow(NONE, FOLD);
break;
case CMD_ALTRIGHT:
FoldAltArrow(NONE, EXPAND);
break;
case IDT_FILE_NEW:
if (IsCmdEnabled(hwnd,IDM_FILE_NEW))
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_FILE_NEW,1),0);
@ -5878,8 +5919,12 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
break;
case SCN_ZOOM:
UpdateLineNumberWidth();
case SCN_NEEDSHOWN:
{
int iFirstLine = SciCall_LineFromPosition(scn->position);
int iLastLine = SciCall_LineFromPosition(scn->position + scn->length - 1);
for (int i = iFirstLine; i <= iLastLine; ++i) { SciCall_EnsureVisible(i); }
}
break;
@ -5889,10 +5934,12 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
break;
case SCN_KEY:
// Also see the corresponding patch in scintilla\src\Editor.cxx
FoldAltArrow(scn->ch, scn->modifiers);
break;
// ~~~ Not used in Windows ~~~
// see: CMD_ALTUP / CMD_ALTDOWN
//case SCN_KEY:
// // Also see the corresponding patch in scintilla\src\Editor.cxx
// FoldAltArrow(scn->ch, scn->modifiers);
// break;
case SCN_SAVEPOINTREACHED:
@ -5904,6 +5951,12 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
SetDocumentModified(TRUE);
break;
case SCN_ZOOM:
UpdateLineNumberWidth();
break;
default:
return FALSE;
}
@ -7621,32 +7674,36 @@ void RestoreAction(int token, DoAction doAct)
// Ensure that the first and last lines of a selection are always unfolded
// This needs to be done _before_ the SCI_SETSEL message
SendMessage(g_hwndEdit, SCI_ENSUREVISIBLE, anchorPosLine, 0);
if (anchorPosLine != currPosLine) {
SendMessage(g_hwndEdit, SCI_ENSUREVISIBLE, currPosLine, 0);
}
if (anchorPosLine != currPosLine) { SendMessage(g_hwndEdit, SCI_ENSUREVISIBLE, currPosLine, 0); }
int currRectType = (int)SendMessage(g_hwndEdit,SCI_GETVIRTUALSPACEOPTIONS,0,0);
PostMessage(g_hwndEdit,SCI_SETSELECTIONMODE,(WPARAM)sel.selMode,0);
PostMessage(g_hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)sel.rectSelVS,0);
#define ISSUE_MESSAGE PostMessage
ISSUE_MESSAGE(g_hwndEdit,SCI_SETSELECTIONMODE,(WPARAM)sel.selMode,0);
ISSUE_MESSAGE(g_hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)sel.rectSelVS,0);
if (sel.selMode == SC_SEL_LINES) {
PostMessage(g_hwndEdit,SCI_SETSELECTIONSTART,(WPARAM)anchorPos,0);
PostMessage(g_hwndEdit,SCI_SETSELECTIONEND,(WPARAM)currPos,0);
ISSUE_MESSAGE(g_hwndEdit,SCI_SETSELECTIONSTART,(WPARAM)anchorPos,0);
ISSUE_MESSAGE(g_hwndEdit,SCI_SETSELECTIONEND,(WPARAM)currPos,0);
}
else if (sel.selMode == SC_SEL_RECTANGLE) {
PostMessage(g_hwndEdit, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)anchorPos, 0);
PostMessage(g_hwndEdit, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)currPos, 0);
ISSUE_MESSAGE(g_hwndEdit, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)anchorPos, 0);
ISSUE_MESSAGE(g_hwndEdit, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)currPos, 0);
if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) {
int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo);
int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo);
PostMessage(g_hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0);
PostMessage(g_hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0);
ISSUE_MESSAGE(g_hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0);
ISSUE_MESSAGE(g_hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0);
}
}
else {
PostMessage(g_hwndEdit, SCI_SETSEL, (LPARAM)anchorPos, (WPARAM)currPos);
PostMessage(g_hwndEdit, SCI_SCROLLRANGE, (LPARAM)anchorPos, (WPARAM)currPos);
ISSUE_MESSAGE(g_hwndEdit, SCI_SETSEL, (LPARAM)anchorPos, (WPARAM)currPos);
ISSUE_MESSAGE(g_hwndEdit, SCI_SCROLLRANGE, (LPARAM)anchorPos, (WPARAM)currPos);
}
PostMessage(g_hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0);
PostMessage(g_hwndEdit, SCI_CANCEL, 0, 0);
ISSUE_MESSAGE(g_hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0);
ISSUE_MESSAGE(g_hwndEdit, SCI_CANCEL, 0, 0);
#undef ISSUE_MASSAGE
}
}

View File

@ -181,8 +181,8 @@ BEGIN
END
POPUP "&Block"
BEGIN
MENUITEM "&Indent\tTab", IDM_EDIT_INDENT
MENUITEM "&Unindent\tShift+Tab", IDM_EDIT_UNINDENT
MENUITEM "&Indent\tTab", IDM_EDIT_INDENT
MENUITEM "&Unindent\tShift+Tab", IDM_EDIT_UNINDENT
MENUITEM SEPARATOR
POPUP "&Enclose Selection"
BEGIN
@ -517,7 +517,9 @@ BEGIN
"Z", IDM_EDIT_STRIP1STCHAR, VIRTKEY, ALT, NOINVERT
"Z", IDM_EDIT_REDO, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_LEFT, CMD_CTRLLEFT, VIRTKEY, CONTROL, NOINVERT
VK_LEFT, CMD_ALTLEFT, VIRTKEY, ALT, NOINVERT
VK_RIGHT, CMD_CTRLRIGHT, VIRTKEY, CONTROL, NOINVERT
VK_RIGHT, CMD_ALTRIGHT, VIRTKEY, ALT, NOINVERT
VK_ADD, IDM_VIEW_ZOOMIN, VIRTKEY, CONTROL, NOINVERT
VK_ADD, CMD_INCLINELIMIT, VIRTKEY, ALT, NOINVERT
VK_ADD, CMD_INCREASENUM, VIRTKEY, CONTROL, ALT, NOINVERT
@ -529,6 +531,7 @@ BEGIN
VK_DELETE, CMD_CTRLDEL, VIRTKEY, CONTROL, NOINVERT
VK_DELETE, IDM_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT
VK_DELETE, IDM_EDIT_DELETELINERIGHT, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_DOWN, CMD_ALTDOWN, VIRTKEY, ALT, NOINVERT
VK_DOWN, IDM_EDIT_MOVELINEDOWN, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_ESCAPE, CMD_ESCAPE, VIRTKEY, NOINVERT
VK_ESCAPE, CMD_SHIFTESC, VIRTKEY, SHIFT, NOINVERT
@ -597,6 +600,7 @@ BEGIN
VK_TAB, IDM_EDIT_INDENT, VIRTKEY, NOINVERT
VK_TAB, IDM_EDIT_UNINDENT, VIRTKEY, SHIFT, NOINVERT
VK_TAB, CMD_CTRLTAB, VIRTKEY, CONTROL, NOINVERT
VK_UP, CMD_ALTUP, VIRTKEY, ALT, NOINVERT
VK_UP, IDM_EDIT_MOVELINEUP, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_OEM_PERIOD, IDM_EDIT_INSERT_GUID, VIRTKEY, SHIFT, CONTROL, NOINVERT
END

View File

@ -111,8 +111,8 @@ DeclareSciCallR0(GetLineCount, GETLINECOUNT, int);
DeclareSciCallR0(GetTextLength, GETTEXTLENGTH, int);
DeclareSciCallR1(LineLength, LINELENGTH, int, Sci_Position, line);
DeclareSciCallR1(LineFromPosition, LINEFROMPOSITION, int, Sci_Position, position);
DeclareSciCallR1(PositionFromLine, POSITIONFROMLINE, int, Sci_Position, line);
DeclareSciCallR1(GetLineEndPosition, GETLINEENDPOSITION, int, Sci_Position, line);
DeclareSciCallR1(PositionFromLine, POSITIONFROMLINE, int, int, line);
DeclareSciCallR1(GetLineEndPosition, GETLINEENDPOSITION, int, int, line);
DeclareSciCallR1(GetColumn, GETCOLUMN, int, Sci_Position, position);
DeclareSciCallR0(LinesOnScreen, LINESONSCREEN, int);
DeclareSciCallR0(GetFirstVisibleLine, GETFIRSTVISIBLELINE, int);

View File

@ -6,7 +6,7 @@
* Version.h *
* Based on code from Notepad2-mod, (c) XhmikosR 2010-2015 *
* *
* (c) Rizonesoft 2008-2016 *
* (c) Rizonesoft 2008-2018 *
* https://www.rizonesoft.com *
* *
* *
@ -34,8 +34,8 @@
#define VERSION_FILEVERSION_NUM VERSION_MAJOR,VERSION_MINOR,VERSION_REV,VERSION_BUILD
#define VERSION_FILEVERSION STRINGIFY(VERSION_MAJOR) L"." STRINGIFY(VERSION_MINOR) L"." \
STRINGIFY(VERSION_REV) L"." STRINGIFY(VERSION_BUILD)
#define VERSION_LEGALCOPYRIGHT L"Copyright © 2008-2017 Rizonesoft"
//#define VERSION_LEGALCOPYRIGHT_LONG L"© Rizonesoft 2008-2017"
#define VERSION_LEGALCOPYRIGHT L"Copyright © 2008-2018 Rizonesoft"
//#define VERSION_LEGALCOPYRIGHT_LONG L"© Rizonesoft 2008-2018"
#define VERSION_AUTHORNAME L"© Rizonesoft"
#define VERSION_WEBPAGEDISPLAY L"https://www.rizonesoft.com"
#define VERSION_COMPANYNAME L"© Rizonesoft"
@ -59,7 +59,9 @@
// Compiler specific
#if defined(_MSC_VER)
#if (_MSC_VER >= 1912)
#if(_MSC_FULL_VER >= 191225834)
#if(_MSC_FULL_VER >= 191225835)
#define VER_CPL "Microsoft Visual C++ 2017 Ver. 15.5.5"
#elif(_MSC_FULL_VER >= 191225834)
#define VER_CPL "Microsoft Visual C++ 2017 Ver. 15.5.(3-4)"
#elif(_MSC_FULL_VER >= 191225831)
#define VER_CPL "Microsoft Visual C++ 2017 Ver. 15.5.2"

View File

@ -223,6 +223,10 @@
#define CMD_OPENINIFILE 20039
#define CMD_CTRLENTER 20040
#define CMD_OPEN_HYPERLINK 20041
#define CMD_ALTUP 20042
#define CMD_ALTDOWN 20043
#define CMD_ALTLEFT 20044
#define CMD_ALTRIGHT 20045
#define IDM_FILE_NEW 40000
#define IDM_FILE_OPEN 40001
#define IDM_FILE_REVERT 40002