Skip to content

Commit 4f131ec

Browse files
committed
copy text + bindings
1 parent a1c48a1 commit 4f131ec

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

browsr/browsr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def action_download_file(self) -> None:
7474
"""
7575
self.code_browser_screen.code_browser.download_file_workflow()
7676

77+
def action_copy_text(self) -> None:
78+
"""
79+
An action to copy text.
80+
"""
81+
self.code_browser_screen.code_browser.window_switcher.text_window.copy_selected_text()
82+
7783

7884
app = Browsr(
7985
config_object=TextualAppContext(

browsr/screens/code_browser.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@ class CodeBrowserScreen(SortedBindingsScreen):
3232
Binding(key="n", action="linenos", description="Line Numbers"),
3333
Binding(key="r", action="reload", description="Reload"),
3434
Binding(key=".", action="parent_dir", description="Parent Directory"),
35-
Binding(key="C", action="copy_text", description="Copy Text", show=False),
35+
Binding(key="w", action="toggle_wrap", description="Toggle Wrap"),
3636
]
3737

3838
BINDING_WEIGHTS: ClassVar[dict[str, int]] = {
39-
"ctrl+c": 1,
40-
"q": 2,
41-
"f": 3,
42-
"t": 4,
43-
"n": 5,
44-
"d": 6,
45-
"r": 994,
46-
".": 995,
47-
"c": 996,
48-
"x": 997,
49-
"C": 998,
39+
"ctrl+c": 5,
40+
"q": 10,
41+
"f": 15,
42+
"t": 20,
43+
"n": 25,
44+
"d": 30,
45+
"r": 905,
46+
".": 910,
47+
"c": 920,
48+
"x": 925,
49+
"w": 930,
50+
"C": 935,
5051
}
5152

5253
def __init__(
@@ -152,21 +153,6 @@ def action_theme(self) -> None:
152153
"""
153154
self.code_browser.window_switcher.next_theme()
154155

155-
def action_copy_text(self) -> None:
156-
"""
157-
An action to copy text.
158-
"""
159-
active_widget = self.code_browser.window_switcher.get_active_widget()
160-
if active_widget is self.code_browser.window_switcher.text_window:
161-
self.code_browser.window_switcher.text_window.action_copy_text()
162-
else:
163-
self.notify(
164-
title="No Selection",
165-
message="Text selection is only supported in code files",
166-
severity="warning",
167-
timeout=1,
168-
)
169-
170156
def action_linenos(self) -> None:
171157
"""
172158
An action to toggle line numbers.
@@ -205,3 +191,11 @@ def action_reload(self) -> None:
205191
severity="information",
206192
timeout=1,
207193
)
194+
195+
def action_toggle_wrap(self) -> None:
196+
"""
197+
Toggle soft wrap for the text area.
198+
"""
199+
self.code_browser.window_switcher.text_window.soft_wrap = (
200+
not self.code_browser.window_switcher.text_window.soft_wrap
201+
)

browsr/widgets/code_browser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ def bind_keys(self) -> None:
128128
self.app.bind(
129129
keys="c", action="copy_file_path", description="Copy Path", show=True
130130
)
131+
self.app.bind(
132+
keys="C",
133+
action="copy_text",
134+
description="Copy Text",
135+
show=True,
136+
key_display="shift+c",
137+
)
138+
131139
if is_remote_path(self.initial_file_path): # type: ignore[arg-type]
132140
self.app.bind(
133141
keys="x", action="download_file", description="Download File", show=True

browsr/widgets/windows.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,13 @@ class TextWindow(TextArea, BaseCodeWindow):
232232
Binding("k", "cursor_up", "Up", show=False),
233233
Binding("l", "cursor_right", "Right", show=False),
234234
Binding("h", "cursor_left", "Left", show=False),
235-
Binding(
236-
"C", "copy_text", "Copy Selected Text", show=True, key_display="shift+c"
237-
),
238235
]
239236

240237
def __init__(self, **kwargs: Any) -> None:
241238
super().__init__(read_only=True, **kwargs)
242239
self.theme = self.default_theme
243240
self.show_line_numbers = self.linenos
241+
self.soft_wrap = False
244242
self.display = False
245243

246244
def watch_linenos(self, linenos: bool) -> None:
@@ -249,7 +247,7 @@ def watch_linenos(self, linenos: bool) -> None:
249247
"""
250248
self.show_line_numbers = linenos
251249

252-
def action_copy_text(self) -> None:
250+
def copy_selected_text(self) -> None:
253251
"""
254252
Copy the selected text to the clipboard.
255253
"""

0 commit comments

Comments
 (0)