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

Clarify is_end_of_document_line in docs #4145

Closed
TomJGooding opened this issue Feb 11, 2024 · 6 comments
Closed

Clarify is_end_of_document_line in docs #4145

TomJGooding opened this issue Feb 11, 2024 · 6 comments

Comments

@TomJGooding
Copy link
Contributor

The documentation for the DocumentNavigator says that a location "refers to a location, in document-space (in the raw document)".

I would expect the "end of line" in the example below to be at index 9. But the is_end_of_document_line is actually based on the length of the row, meaning it is off-by-one.

Perhaps what is meant by "end of line" just needs clarifying the docs, or this might be an unintended bug?

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

TEXT = "0123456789"


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        yield TextArea.code_editor(TEXT)

    def on_mount(self) -> None:
        text_area = self.query_one(TextArea)
        expected_eol = (0, 9)
        assert text_area.navigator.is_end_of_document_line(expected_eol)


if __name__ == "__main__":
    app = ExampleApp()
    app.run()
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor Author

Sorry I forgot to mention: I think the docstring might need correcting anyway here:

Returns:
True if and only if the document is on the last line of the document.

@darrenburns
Copy link
Member

It's not off by one - I should maybe clarify in the docs though. The end of the line is the maximum position in a line the cursor can rest on. Since you need to be able to move the cursor beyond the end of the text (otherwise inserting new text would be impossible), the "end of document line" is len(document_line). It's not "index of the last character".

@TomJGooding TomJGooding changed the title is_end_of_document_line is off-by-one? Clarify is_end_of_document_line in docs Feb 12, 2024
@TomJGooding
Copy link
Contributor Author

Thanks Darren for the explanation, I think clarifying this in the docs is a good idea.

darrenburns added a commit that referenced this issue Feb 13, 2024
* Add read_only reactive

* Using nested CSS in TextArea and adding COMPONENT_CLASS for read-only cursor

* Applying/removing CSS class `.-read-only` in TextArea

* Preventing some edits in read-only mode.

* Clearer distinction between user/keyboard driven edits and programmatic edits

* Ensure we refresh cursor correctly when pressing key in read-only mode

* Add test of paste in read-only mode

* Fix typo in docstring

* Ensure "delete line" keybinding doesnt move cursor in read_only mode in TextArea

* Add clarification to docs based on issue #4145

* Add test to ensure read-only cursor colour

* Update CHANGELOG

* Fix cursor styling in CSS on read-only

* Fix a docstring

* Improving docstrings

* Improving docstrings

* Simplify fixtures

* Test to ensure API driven editing still works on TextArea.read_only=True
@TomJGooding
Copy link
Contributor Author

Closed as completed by #4151 (thanks Darren!)

Copy link

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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants