Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/guiguts/maintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,14 +951,7 @@ def text_peer_focus_track(event: tk.Event) -> None:
self.bind_event(
"<Escape>", lambda _: self.cancel_drag_sel(), add=True, bind_peer=True
)

def set_anchor(_: tk.Event) -> str:
"""Set anchor point at current position, then allow Shift-click to
execute its default behavior."""
self.mark_set(TK_ANCHOR_MARK, f"{self.index(tk.INSERT)}")
return ""

self.bind("<Shift-Button-1>", set_anchor)
self.bind("<Shift-Button-1>", lambda _event: self.set_tk_selection_anchor())

# Override default left/right/up/down arrow key behavior if there is a selection
# Above behavior would affect Shift-Left/Right/Up/Down, so also bind those to
Expand Down Expand Up @@ -2687,7 +2680,14 @@ def _move_to_selection_edge(self, end: bool, force_line: bool = False) -> str:
"""
sel_ranges = self.selected_ranges()
if not sel_ranges:
return ""
if force_line:
sel_ranges.append(
IndexRange(
maintext().get_insert_index(), maintext().get_insert_index()
)
)
else:
return ""
pos = sel_ranges[-1].end if end else sel_ranges[0].start
idx = pos.index()
if force_line:
Expand All @@ -2696,6 +2696,7 @@ def _move_to_selection_edge(self, end: bool, force_line: bool = False) -> str:
self.focus_widget().mark_set(tk.INSERT, idx)
self.focus_widget().see(tk.INSERT)
self.clear_selection()
self.set_tk_selection_anchor()
return "break"

def move_to_start(self) -> None:
Expand Down Expand Up @@ -3920,6 +3921,11 @@ def strip_end_of_line_spaces(self) -> None:
while start := self.search(" +$", start, regexp=True):
self.delete(start, f"{start} lineend")

def set_tk_selection_anchor(self) -> str:
"""Set anchor point at current position."""
self.mark_set(TK_ANCHOR_MARK, f"{self.index(tk.INSERT)}")
return ""

def go_home(self, event: tk.Event) -> str:
"""Handle the Home key. Either move to start of line, or if
already there, move to first non-space on line."""
Expand Down Expand Up @@ -3955,6 +3961,7 @@ def go_home(self, event: tk.Event) -> str:
# If no Shift, just moving, so clear selection
else:
self.clear_selection()
self.set_tk_selection_anchor()
self.see(tk.INSERT)
return "break"

Expand Down Expand Up @@ -3986,6 +3993,7 @@ def go_end(self, event: tk.Event) -> str:
# If no Shift, just moving, so clear selection
else:
self.clear_selection()
self.set_tk_selection_anchor()
self.see(tk.INSERT)
return "break"

Expand Down
Loading