Use SCI_TARGETWHOLEDOCUMENT and SCI_COUNTCHARACTERS

This commit is contained in:
dail8859 2019-05-24 20:43:43 -04:00
parent 9a2dfeb263
commit 492870be0b
2 changed files with 7 additions and 14 deletions

View File

@ -1526,7 +1526,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_EOL2WS: case IDM_EDIT_EOL2WS:
_pEditView->execute(SCI_BEGINUNDOACTION); _pEditView->execute(SCI_BEGINUNDOACTION);
_pEditView->execute(SCI_SETTARGETRANGE, 0, _pEditView->getCurrentDocLen()); _pEditView->execute(SCI_TARGETWHOLEDOCUMENT);
_pEditView->execute(SCI_LINESJOIN); _pEditView->execute(SCI_LINESJOIN);
_pEditView->execute(SCI_ENDUNDOACTION); _pEditView->execute(SCI_ENDUNDOACTION);
break; break;
@ -1538,7 +1538,7 @@ void Notepad_plus::command(int id)
_pEditView->execute(SCI_BEGINUNDOACTION); _pEditView->execute(SCI_BEGINUNDOACTION);
doTrim(lineTail); doTrim(lineTail);
doTrim(lineHeader); doTrim(lineHeader);
_pEditView->execute(SCI_SETTARGETRANGE, 0, _pEditView->getCurrentDocLen()); _pEditView->execute(SCI_TARGETWHOLEDOCUMENT);
_pEditView->execute(SCI_LINESJOIN); _pEditView->execute(SCI_LINESJOIN);
_pEditView->execute(SCI_ENDUNDOACTION); _pEditView->execute(SCI_ENDUNDOACTION);
break; break;

View File

@ -477,18 +477,11 @@ public:
// return -1 if it's multi-selection or rectangle selection // return -1 if it's multi-selection or rectangle selection
if ((execute(SCI_GETSELECTIONS) > 1) || execute(SCI_SELECTIONISRECTANGLE)) if ((execute(SCI_GETSELECTIONS) > 1) || execute(SCI_SELECTIONISRECTANGLE))
return -1; return -1;
auto size_selected = execute(SCI_GETSELTEXT);
char *selected = new char[size_selected + 1]; long start = long(execute(SCI_GETSELECTIONSTART));
execute(SCI_GETSELTEXT, 0, reinterpret_cast<LPARAM>(selected)); long end = long(execute(SCI_GETSELECTIONEND));
char *c = selected; long length = long(execute(SCI_COUNTCHARACTERS, start, end));
long length = 0;
while (*c != '\0')
{
if ( (*c & 0xC0) != 0x80)
++length;
++c;
}
delete [] selected;
return length; return length;
}; };