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

don't cut off text for addendum in mid-word #607

Merged
merged 10 commits into from
Nov 10, 2022
Merged

Conversation

nonprofittechy
Copy link
Member

@nonprofittechy nonprofittechy commented Nov 8, 2022

Fix #243

Sample interactive test:

---
modules:
  - .al_document
---
mandatory: True
code: |
  text_input
  display_results
---
objects:
  - myfield: ALAddendumField.using(field_name="text_input")
---
question: |
  Enter some text
fields:
  - Overflow trigger: myfield.overflow_trigger
    datatype: integer
  - Text: text_input
    datatype: area
    rows: 5
---
event: display_results
question: |
  Results
subquestion: |
  
  ${ single_to_double_newlines(myfield.safe_value(overflow_message="...", preserve_newlines=True, preserve_words=True)) }
  
  ${ single_to_double_newlines(myfield.overflow_value(overflow_message="...", preserve_newlines=True, preserve_words=True)) }
  

@nonprofittechy nonprofittechy changed the title don't cut off words for addendum in mid-sentence don't cut off text for addendum in mid-word Nov 8, 2022
Format Python code with psf/black push
@nonprofittechy nonprofittechy marked this pull request as ready for review November 8, 2022 21:06
Copy link
Contributor

@BryceStevenWilley BryceStevenWilley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it needs a little more tests, I'm not sure I understand what textwrap does to multi-line input, which text areas are likely to get often

docassemble/AssemblyLine/test_al_document.py Show resolved Hide resolved
width=input_width,
max_lines=max_lines,
replace_whitespace=False,
placeholder=overflow_message,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this would interact with newlines in value, which people are likely to add in text areas I think.https://docs.python.org/3/library/textwrap.html#textwrap.TextWrapper.replace_whitespace says that it'll "cause strange output", which makes me a little hesitant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't cause strange output in our usage, which ends up removing the line breaks after any get added.

We just use textwrap.wrap to figure out how many lines should fit, but we let the pdf renderer handle the actual soft line breaks in the output.

Copy link
Contributor

@BryceStevenWilley BryceStevenWilley Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't removing all of the line breaks, we're just collapsing things where multiple appear in a row. Test overflow of 90, and input:

At least 10% of people 

in this target audience do not know what this term means.
 
Therefore, you must avoid this term, explain this term, or link to an explanation.

Results in 3 lines of text, when there should only be 2, because there are still some \ns inside the input text. Extra lines like that could cause things to get cut off in the PDF by pushing the last line below the height of the text box, right?

@nonprofittechy
Copy link
Member Author

Tricky to test this given different way that whitespace (particularly newlines) happen in-browser input fields vs in a docstring in the unit test file, but I think this is all correct now! This now also fixes some minor, undiscovered but long-standing bugs in the addendum code too.

Copy link
Contributor

@BryceStevenWilley BryceStevenWilley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The only weird thing was that preserve_newlines isn't really respected if max_lines < 1, but that makes sense IMO, maybe worth documenting, but up to you.

@nonprofittechy nonprofittechy merged commit 2122366 into main Nov 10, 2022
@nonprofittechy
Copy link
Member Author

LGTM. The only weird thing was that preserve_newlines isn't really respected if max_lines < 1, but that makes sense IMO, maybe worth documenting, but up to you.

I'm going to add some better documentation on the public documentation site

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

Successfully merging this pull request may close these issues.

Use smarter character limits in overflow fields so words are not cut off mid-word
2 participants