Swap colors with right click or Ctrl+click on current colors area

This commit is contained in:
Isaiah Odhner 2023-09-04 10:08:24 -04:00
parent 778ecb2b8a
commit 2cff6c89e1
3 changed files with 15 additions and 3 deletions

View File

@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Right click can now be used as an alternative to Ctrl+click to pick a foreground color from the palette. In XTerm, Ctrl opens a context menu, so this is the only way in XTerm. It's also more convenient.
- Note: Left click in MS Paint selects the foreground (primary) color, whereas in Textual Paint it selects the background color, which is, strangely, essentially the primary color, since you draw with a space character by default. It may be worth changing the default character to a full block character (█), and swapping these mouse button mappings, to bring it in line with MS Paint. This would also allow drawing "pixels" and saving as a plain text file without it all becoming blank when color information is discarded.
- Side note: I was previously saving right click for a possible future UI where the foreground and background selections both have a foreground, background, and glyph, with the three components being analogous to a single color in MS Paint. I haven't explored that idea yet. It's likely too complicated conceptually, but it would allow more granular color replacement with the Color Eraser tool (if that's even desirable), and quicker access to two different glyphs.
- Right click or Ctrl+click on the current colors area to swap the foreground and background colors. This is a great convenience, especially when using the Color Eraser tool, or when using custom colors that may be similar to each other.
- Side note: The only reason I didn't add this until now is because I didn't consider right click! (Unlike in JS Paint, where I've had this feature for a long time, left click is used to focus the character input field, which is also the current colors area.)
### Fixed

View File

@ -152,6 +152,9 @@ You can set the text color by right clicking or holding <kbd>Ctrl</kbd> while cl
Also, if you double right click or hold <kbd>Ctrl</kbd> while double clicking on a color to open the Edit Colors dialog,
if will edit the text color when you click OK.
You can swap the foreground and background colors by right clicking or holding <kbd>Ctrl</kbd> while clicking the current colors area.
This is a great convenience, especially when using the Color Eraser tool, or when using custom colors that may be similar to each other.
You can display a saved ANSI file in the terminal with `cat`:
```bash

View File

@ -504,10 +504,13 @@ class CharInput(Input, inherit_bindings=False):
return original_strip.apply_filter(self.Recolor(fg_color, bg_color), background=bg_color)
last_click_time = 0
def on_click(self, event: events.Click) -> None:
"""Detect double click and open character selector dialog."""
def on_mouse_down(self, event: events.MouseDown) -> None:
"""Detect double click and open character selector dialog, or swap colors on right click or Ctrl+click."""
assert isinstance(self.app, PaintApp)
if event.ctrl or event.button == 3: # right click
self.app.action_swap_colors()
return
if event.time - self.last_click_time < 0.8:
assert isinstance(self.app, PaintApp)
self.app.action_open_character_selector()
self.last_click_time = event.time
@ -3332,6 +3335,10 @@ class PaintApp(App[None]):
)
self.mount(window)
def action_swap_colors(self) -> None:
"""Swap the foreground and background colors."""
self.selected_bg_color, self.selected_fg_color = self.selected_fg_color, self.selected_bg_color
def action_edit_colors(self, color_palette_index: int|None = None, as_foreground: bool = False) -> None:
"""Show dialog to edit colors."""
self.close_windows("#edit_colors_dialog")