From 492870be0b753d951d8818246ecfa0b4c5a07012 Mon Sep 17 00:00:00 2001 From: dail8859 Date: Fri, 24 May 2019 20:43:43 -0400 Subject: [PATCH] Use SCI_TARGETWHOLEDOCUMENT and SCI_COUNTCHARACTERS --- PowerEditor/src/NppCommands.cpp | 4 ++-- .../src/ScitillaComponent/ScintillaEditView.h | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 553b07bb0..d12f95c16 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1526,7 +1526,7 @@ void Notepad_plus::command(int id) case IDM_EDIT_EOL2WS: _pEditView->execute(SCI_BEGINUNDOACTION); - _pEditView->execute(SCI_SETTARGETRANGE, 0, _pEditView->getCurrentDocLen()); + _pEditView->execute(SCI_TARGETWHOLEDOCUMENT); _pEditView->execute(SCI_LINESJOIN); _pEditView->execute(SCI_ENDUNDOACTION); break; @@ -1538,7 +1538,7 @@ void Notepad_plus::command(int id) _pEditView->execute(SCI_BEGINUNDOACTION); doTrim(lineTail); doTrim(lineHeader); - _pEditView->execute(SCI_SETTARGETRANGE, 0, _pEditView->getCurrentDocLen()); + _pEditView->execute(SCI_TARGETWHOLEDOCUMENT); _pEditView->execute(SCI_LINESJOIN); _pEditView->execute(SCI_ENDUNDOACTION); break; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 2aef4b1fa..3dc7cb6e6 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -477,18 +477,11 @@ public: // return -1 if it's multi-selection or rectangle selection if ((execute(SCI_GETSELECTIONS) > 1) || execute(SCI_SELECTIONISRECTANGLE)) return -1; - auto size_selected = execute(SCI_GETSELTEXT); - char *selected = new char[size_selected + 1]; - execute(SCI_GETSELTEXT, 0, reinterpret_cast(selected)); - char *c = selected; - long length = 0; - while (*c != '\0') - { - if ( (*c & 0xC0) != 0x80) - ++length; - ++c; - } - delete [] selected; + + long start = long(execute(SCI_GETSELECTIONSTART)); + long end = long(execute(SCI_GETSELECTIONEND)); + long length = long(execute(SCI_COUNTCHARACTERS, start, end)); + return length; };