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

TextArea still has a cursor, until it's had focus and then lost it #4109

Closed
davep opened this issue Feb 2, 2024 · 8 comments · Fixed by #4128
Closed

TextArea still has a cursor, until it's had focus and then lost it #4109

davep opened this issue Feb 2, 2024 · 8 comments · Fixed by #4128
Assignees
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Feb 2, 2024

Sort of related to #3722: a TextArea still has a cursor when not focused, if it hasn't received focus yet. For example, this code:

from textual.app import App, ComposeResult
from textual.widgets import Input, TextArea

class TextAreaCursorApp(App[None]):

    def compose(self) -> ComposeResult:
        yield Input()
        yield TextArea()

if __name__ == "__main__":
    TextAreaCursorApp().run()

starts up looking like this:

Screenshot 2024-02-02 at 21 07 37

@davep davep added bug Something isn't working Task labels Feb 2, 2024
davep added a commit to davep/textual-sandbox that referenced this issue Feb 2, 2024
@darrenburns
Copy link
Member

Cheers - I reckon this will be changing a True to a False somewhere 😄

@TomJGooding
Copy link
Contributor

TomJGooding commented Feb 3, 2024

I had a quick look at this and found that if you set cursor_blink = False (needed for snapshot testing), the TextArea still has a cursor even after focussing then blurring:

from textual.app import App, ComposeResult
from textual.widgets import Input, TextArea


class TextAreaCursorApp(App[None]):
    def compose(self) -> ComposeResult:
        input = Input()
        text_area = TextArea()
        input.cursor_blink = False
        text_area.cursor_blink = False
        yield input
        yield text_area


if __name__ == "__main__":
    TextAreaCursorApp().run()

Then I spotted that the _on_blur method actually also seems to set the cursor to be visible which is confusing? Changing this to False has no effect, which suggests the cursor visibility must actually be updated elsewhere...?

def _on_blur(self, _: events.Blur) -> None:
self._pause_blink(visible=True)

EDIT: Ah-ha, I missed that it also has this watch method!

def watch_has_focus(self, value: bool) -> None:
self._cursor_visible = value
super().watch_has_focus(value)

@darrenburns
Copy link
Member

Oh yeah, the _on_blur can probably be removed. It was intended to ensure that the cursor remains visible when it's blurred for consistency. Otherwise the visibility of the cursor depended on when you blurred the widget.

I was thinking initialising self._cursor_visible to False in the constructor might be enough.

@TomJGooding
Copy link
Contributor

Just to note for whoever picks this up (maybe me!), potentially any fix should also account for this issue:

@TomJGooding
Copy link
Contributor

TomJGooding commented Feb 6, 2024

Oh yeah, the _on_blur can probably be removed. It was intended to ensure that the cursor remains visible when it's blurred for consistency. Otherwise the visibility of the cursor depended on when you blurred the widget.

Sorry I'm not sure I fully understand this - is that just the old implementation, or related to #2476?

@darrenburns
Copy link
Member

Sorry, I meant the _on_blur could be removed because we could handle the logic of pausing the blink insidewatch_has_focus instead, rather than doing blur-related stuff in 2 places. We'll probably need to pause blink in watch_has_focus with visible=False.

@darrenburns
Copy link
Member

I'm going to pick this up now.

Copy link

github-actions bot commented Feb 7, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants