-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBulletText.py
More file actions
62 lines (49 loc) · 2.05 KB
/
BulletText.py
File metadata and controls
62 lines (49 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from Npp import editor
# Wim Gielis
# Apr. 2025
#
# BulletText script (Alt-b):
# - The selected text receives a bulleting in front: - and a space
# - Empty lines also receive them
# If there is no selection, do nothing
# if selected_text.strip():
# if editor.getSelectionEmpty():
# current_position = editor.getCurrentPos()
# current_line_number = editor.lineFromPosition(current_position)
# start_of_curr_line_pos = editor.positionFromLine(current_line_number)
# editor.setSel(start_of_curr_line_pos, start_of_curr_line_pos + len(editor.getLine(current_line_number)) - 1)
# Get the start and end positions of the current selection
sel_start = editor.getSelectionStart()
sel_end = editor.getSelectionEnd()
# Extend the selection to the start of the first selected line
line_start = editor.lineFromPosition(sel_start)
sel_start = editor.positionFromLine(line_start)
# Extend the selection to the end of the last selected line
line_end = editor.lineFromPosition(sel_end)
sel_end = editor.getLineEndPosition(line_end)
# Set the new selection range
editor.setSelection(sel_end, sel_start)
# Get the selected lines of text
selected_text = editor.getSelText()
# Split into lines and process
lines = selected_text.splitlines()
if lines:
new_lines = [f'- {line.rstrip()}' for line in lines]
new_text = '\r\n'.join(new_lines)
editor.replaceSel(new_text)
editor.setCurrentPos(sel_start + 2)
editor.gotoPos(sel_start + 2)
# In case the selection is smallish:
# def forEachSelectedLine(callback):
# start_line = editor.lineFromPosition(editor.getSelectionStart())
# end_line = editor.lineFromPosition(editor.getSelectionEnd())
# for line_num in range(start_line, end_line + 1):
# line_text = editor.getLine(line_num)
# callback(line_text, line_num)
#
# def Bulletted_Text(contents, lineNumber, totalLines=None):
# contents = str(contents).rstrip('\n\r')
# editor.replaceLine(lineNumber, f"- {contents}")
#
#
# forEachSelectedLine(Bulletted_Text)