Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input selection #5340

Merged
merged 34 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f029383
Initial machinery for text selection in Input widget
darrenburns Dec 4, 2024
24cad3c
Demoting cursor_position to property
darrenburns Dec 4, 2024
a1cefa5
Update validator and watcher to work with Input.selection instead of …
darrenburns Dec 4, 2024
9c8cfcb
Click and drag to select
darrenburns Dec 4, 2024
e376a4e
Remove input selection foreground
darrenburns Dec 4, 2024
f01bcc8
Select left and right words
darrenburns Dec 4, 2024
e1bf6ff
Use line API
darrenburns Dec 4, 2024
bd39e0f
Remove more unused reactives
darrenburns Dec 4, 2024
0e0ca7c
Fixes
darrenburns Dec 4, 2024
02c67bf
Fix accidental multiple cursors
darrenburns Dec 5, 2024
64adf92
Fix MaskedInput
darrenburns Dec 5, 2024
5c45656
Fix scrolling with double width characters
darrenburns Dec 5, 2024
f540622
Update snapshots, remove old tests
darrenburns Dec 5, 2024
8dc81ac
Snapshot tests for Input
darrenburns Dec 5, 2024
c72d85f
Creating new snapshots
darrenburns Dec 5, 2024
ff54125
Simplifying implementations
darrenburns Dec 5, 2024
1788ca8
More simplification
darrenburns Dec 5, 2024
5aa06c2
Simplify delete_word_left
darrenburns Dec 5, 2024
c3339df
Apply Input.restrict to all edits
darrenburns Dec 5, 2024
7a7e553
Ensure interaction between selections and insertions (paste and inser…
darrenburns Dec 5, 2024
a949717
Add shift+home and shift+end bindings to Input
darrenburns Dec 5, 2024
9212b80
Testing Input.replace and Input.delete
darrenburns Dec 5, 2024
c1d871d
Create new snapshot
darrenburns Dec 5, 2024
4972463
Import annotations from __future__
darrenburns Dec 5, 2024
3336181
Selection goes under highlights
darrenburns Dec 5, 2024
dbc0dac
Rename `empty` to `is_empty` in Input Selection class
darrenburns Dec 5, 2024
c33f36e
Select Input text on focus
darrenburns Dec 5, 2024
3d21493
Snapshot fixes
darrenburns Dec 5, 2024
083b69e
Ensure we dont scroll to the end of an input on the initial value set
darrenburns Dec 5, 2024
8e75f48
Update CHANGELOG.md
darrenburns Dec 5, 2024
9ff7cbc
Extra Input selection tests
darrenburns Dec 5, 2024
f9c0aeb
Add copy_selection bindings
darrenburns Dec 5, 2024
2d773ce
Add missing docstrings
darrenburns Dec 5, 2024
bffbc57
Update snapshots
darrenburns Dec 5, 2024
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added "tab" border style https://github.com/Textualize/textual/pull/5335
- Added support for XML syntax highlighting https://github.com/Textualize/textual/pull/5320
- Added `TextArea.update_highlight_query` https://github.com/Textualize/textual/pull/5320
- `Input` widget now supports text selection via mouse and keyboard https://github.com/Textualize/textual/pull/5340
- Added new keybinds (hold shift) for text selection in `Input` https://github.com/Textualize/textual/pull/5340
- Added `Input.selection` reactive attribute for reading and updating the current selection https://github.com/Textualize/textual/pull/5340
- Added `Input.select_on_focus` (default `True`) to enable/disable selecting all text in an `Input` on focus https://github.com/Textualize/textual/pull/5340
- Added methods `Input.replace`, `Input.insert`, `Input.delete`, `Input.delete_selection` for editing text https://github.com/Textualize/textual/pull/5340
- Added `Input.selected_text` property for getting the currently selected text https://github.com/Textualize/textual/pull/5340
- `Input` can now be scrolled independently of cursor position (hold shift and scroll with the mouse wheel in supported environments) https://github.com/Textualize/textual/pull/5340

## Changed

- Breaking change: Removed `Input` reactive attributes `view_position`, `cursor_position` (now exists as a property which proxies to the `Input.selection` reactive attribute), https://github.com/Textualize/textual/pull/5340
- `Input.restrict` now checked on all edit operations (rather than just on `insert`) https://github.com/Textualize/textual/pull/5340


## Fixed
Expand Down
1 change: 0 additions & 1 deletion docs/guide/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ Here's a comprehensive list of these variables, their purposes, and default valu
| `$input-cursor-foreground` | Text color of the input cursor | `$background` |
| `$input-cursor-text-style` | Text style of the input cursor | `"none"` |
| `$input-selection-background` | Background color of selected text | `$primary-lighten-1` with 40% opacity |
| `$input-selection-foreground` | Text color of selected text | `$background` |

### Scrollbar

Expand Down
3 changes: 0 additions & 3 deletions src/textual/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ def luminosity_range(spread: float) -> Iterable[tuple[str, float]]:
"input-selection-background",
Color.parse(colors["primary-lighten-1"]).with_alpha(0.4).hex,
)
colors["input-selection-foreground"] = get(
"input-selection-foreground", background.hex
)

# Markdown header styles
colors["markdown-h1-color"] = get("markdown-h1-color", primary.hex)
Expand Down
1 change: 0 additions & 1 deletion src/textual/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def to_color_system(self) -> ColorSystem:
"block-cursor-text-style": "b",
"block-cursor-blurred-text-style": "i",
"input-selection-background": "ansi_blue",
"input-selection-foreground": "ansi_white",
"input-cursor-text-style": "reverse",
"scrollbar": "ansi_blue",
"border-blurred": "ansi_blue",
Expand Down
Loading
Loading