Skip to content

Commit

Permalink
Merge branch 'npp_official_svn' into jl/LH-45/integrate-npp-svn
Browse files Browse the repository at this point in the history
[BUG_FIXED] Fix comment stream without selection bug.

[#45]

Signed-off-by: Jocelyn Legault <jocelynlegault@gmail.com>
  • Loading branch information
joce committed Sep 30, 2010
2 parents c69ffb5 + b886334 commit fee56ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
12 changes: 1 addition & 11 deletions PowerEditor/src/MISC/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT c
}
len = MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, len);

if ((size_t)*mstart < strlen(mbcs2Convert) && (size_t)*mend < strlen(mbcs2Convert))
if ((size_t)*mstart < strlen(mbcs2Convert) && (size_t)*mend <= strlen(mbcs2Convert))
{
*mstart = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mstart, _wideCharStr, 0);
*mend = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mend, _wideCharStr, 0);
Expand All @@ -322,11 +322,6 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT c
*mend = 0;
}
}
else
{
*mstart = 0;
*mend = 0;
}
}
else
{
Expand Down Expand Up @@ -391,11 +386,6 @@ const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UI
*mend = 0;
}
}
else
{
*mstart = 0;
*mend = 0;
}
}
else
_multiByteStr[0] = 0;
Expand Down
36 changes: 4 additions & 32 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,7 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode)
generic_string comment(commentLineSybol);
comment += TEXT(" ");

const int linebufferSize = 1000;
const int linebufferSize = 1024;
TCHAR linebuf[linebufferSize];
size_t comment_length = comment.length();
size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART);
Expand Down Expand Up @@ -3275,41 +3275,13 @@ bool Notepad_plus::doStreamComment()
size_t caretPosition = _pEditView->execute(SCI_GETCURRENTPOS);
// checking if caret is located in _beginning_ of selected block
bool move_caret = caretPosition < selectionEnd;

// if there is no selection?
if (selectionEnd - selectionStart <= 0)
{
int selLine = _pEditView->execute(SCI_LINEFROMPOSITION, selectionStart);
int lineIndent = _pEditView->execute(SCI_GETLINEINDENTPOSITION, selLine);
int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, selLine);

TCHAR linebuf[1000];
_pEditView->getGenericText(linebuf, lineIndent, lineEnd);

int caret = _pEditView->execute(SCI_GETCURRENTPOS);
int line = _pEditView->execute(SCI_LINEFROMPOSITION, caret);
int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE, line);
int current = caret - lineStart;
// checking if we are not inside a word

int startword = current;
int endword = current;
int start_counter = 0;
int end_counter = 0;
while (startword > 0)// && wordCharacters.contains(linebuf[startword - 1]))
{
start_counter++;
startword--;
}
// checking _beginning_ of the word
if (startword == current)
return true; // caret is located _before_ a word
while (linebuf[endword + 1] != '\0') // && wordCharacters.contains(linebuf[endword + 1]))
{
end_counter++;
endword++;
}
selectionStart -= start_counter;
selectionEnd += (end_counter + 1);
selectionStart = _pEditView->execute(SCI_GETLINEINDENTPOSITION, selLine);
selectionEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, selLine);
}
_pEditView->execute(SCI_BEGINUNDOACTION);
_pEditView->insertGenericTextFrom(selectionStart, start_comment.c_str());
Expand Down

0 comments on commit fee56ce

Please sign in to comment.