Here’s the Pythonscript I mentioned earlier.
After running it, it will update the “Sel:” area in the status bar as follows:
If selection contains partial lines which do not include the first line’s first character, not the last line’s last character (non-line-ending), then NO CHANGE from normal Notepad++ behavior.
If the selection contains the first line’s first character, the part after the vertical bar (|) in “Sel: X | Y” will have a caret character (^) before the number of lines, e.g. ^7
If the selection contains the last line’s last character (but not the line ending character(s)), the part after the vertical bar will have a dollar sign character ($) after the number of lines, e.g. 7$
If the selection contains the last line’s last character AND the line ending character(s), the part after the vertical bar will have a dollar sign character ($) and \R after the number of lines, e.g. 7$\R
If the selection contains lines in their entirety, the part after the vertical bar will combine all of these symbols, an example being ^7$\R. Note that this example means that 7 FULL LINES are in the selection, fixing the original “bad” Notepad++ behavior for this case.
Regular expression users will feel very comfortable with the meaning behind the choice of special symbols used here.
Okay, so here’s the Pythonscript code:
# Sel : C | L in the status bar shows an off-by-one L (line count) sometimes (open to debate)
# make it better:
# Sel : C | L <-- selection spans L partial lines
# Sel : C | ^L <-- selection spans L partial lines and includes first character on its first line
# Sel : C | L$ <-- selection spans L partial lines and includes last char (but not line-ending) on its last line
# Sel : C | L$\R <-- selection spans L partial lines and includes line-ending on its last line
# Sel : C | ^L$\R <-- selection spans L FULL lines and includes line-ending on its last line
def StatusbarSelOverride(args):
curr_pos = editor.getCurrentPos()
curr_line = editor.lineFromPosition(curr_pos)
curr_col = editor.getColumn(curr_pos)
sel_part = 'N/A'
if editor.getSelections() == 1:
sel_mode = editor.getSelectionMode()
rect_sel_mode = True if (sel_mode == SELECTIONMODE.RECTANGLE or sel_mode == SELECTIONMODE.THIN) else False
if not rect_sel_mode:
if editor.getSelectionEmpty():
sel_part = '0 | 0'
else:
sel_start_pos = editor.getSelectionStart()
sel_end_pos = editor.getSelectionEnd()
sel_start_line = editor.lineFromPosition(sel_start_pos)
sel_end_line = editor.lineFromPosition(editor.getSelectionEnd())
lines_touched_by_sel = sel_end_line - sel_start_line + 1
start_of_line_symbol = '^' if sel_start_pos == editor.positionFromLine(sel_start_line) else ''
end_of_line_symbols = '$' if sel_end_pos == editor.getLineEndPosition(sel_end_line) else ''
selected_text = editor.getSelText()
line_ending = ['\r\n', '\r', '\n'][notepad.getFormatType()]
if selected_text.endswith(line_ending): end_of_line_symbols = r'$\R'; lines_touched_by_sel -= 1
sel_text_len = len(selected_text)
sel_part = '{tl} | {sol}{lis}{eol}'.format(
tl=sel_text_len,
sol=start_of_line_symbol,
lis=lines_touched_by_sel,
eol=end_of_line_symbols,
)
line_col_sel_info_for_sb = 'Ln : {user_line} Col : {user_col} Sel : {sel}'.format(
user_line=curr_line+1,
user_col=curr_col+1,
sel=sel_part,
)
notepad.setStatusBar(STATUSBARSECTION.CURPOS, line_col_sel_info_for_sb)
editor.callback(StatusbarSelOverride, [SCINTILLANOTIFICATION.UPDATEUI]) # register callback