From 785459bf8e4da396ac933588eab73fca048e6a85 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 5 Aug 2013 00:38:01 +0000 Subject: [PATCH] [BUG_FIXED] (Author: Andreas Jonsson) Now statusbar reports the number of selected characters instead of number of bytes. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1098 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 7 +++++-- .../src/ScitillaComponent/ScintillaEditView.h | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index bb371f9f..476f0458 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2736,8 +2736,11 @@ void Notepad_plus::updateStatusBar() int selByte = 0; int selLine = 0; - if (_pEditView->getSelectedCount(selByte, selLine)) - wsprintf(strSel, TEXT("Sel : %d | %d"), selByte, selLine); + _pEditView->getSelectedCount(selByte, selLine); + + long selected_length = _pEditView->getSelectedLength(); + if (selected_length != -1) + wsprintf(strSel, TEXT("Sel : %d | %d"), selected_length, selLine); else wsprintf(strSel, TEXT("Sel : %s"), TEXT("N/A")); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index b886e46a..1120a3c0 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -470,6 +470,26 @@ public: return true; }; + long getSelectedLength() const { + // return -1 if it's multi-selection or rectangle selection + if ((execute(SCI_GETSELECTIONS) > 1) || execute(SCI_SELECTIONISRECTANGLE)) + return -1; + long size_selected = execute(SCI_GETSELTEXT); + char *selected = new char[size_selected + 1]; + execute(SCI_GETSELTEXT, (WPARAM)0, (LPARAM)selected); + char *c = selected; + long length = 0; + while(*c != '\0') + { + if( (*c & 0xC0) != 0x80) + ++length; + ++c; + } + delete [] selected; + return length; + }; + + long getLineLength(int line) const { return long(execute(SCI_GETLINEENDPOSITION, line) - execute(SCI_POSITIONFROMLINE, line)); };