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
Added maxLines config option to MultilineInput #4477
Added maxLines config option to MultilineInput #4477
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I left a few comments and questions.
* If exceeded, scrolling functionality is enabled. | ||
* @type {number} | ||
*/ | ||
this.maxLines_ = Infinity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trailing underscore should only be used for private/protected properties. In this case, since you already have public getters and setters, you should mark this property as protected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, will fix!
core/field_multilineinput.js
Outdated
var text = lines[i]; | ||
if (text.length > this.maxDisplayLength) { | ||
if (text.length > this.maxDisplayLength || overflow && i === displayLinesNumber - 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct either way, but could you add parentheses around the condition you added here? That way a reader doesn't have to stop and think about the order of operations like I did when I got here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
@@ -211,6 +228,27 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { | |||
totalHeight += this.getConstants().FIELD_TEXT_HEIGHT + | |||
(i > 0 ? this.getConstants().FIELD_BORDER_RECT_Y_PADDING : 0); | |||
} | |||
if (this.isBeingEdited_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me a little more about what this section of code is doing? I'm not sure what you're trying to solve that isn't covered by the existing code (I checked out your PR and removed this bit and it seems fine, but I could be missing something). One difference I noticed is that when you have a truncated line (referring to maxDisplayLength, not maxLines), the block gets slightly wider when you start editing, then shrinks again when you finish. In the existing behavior, the block stays the same width. Unless we have good reason, I think we should prefer the existing behavior here.
Then, if the size doesn't change, I don't think you need to override showEditor_ either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you type in the editor, the underlying SVG text changes, and the width of the block is originally set as the longest SVG text element (above this section).
When we restrict the number of lines, then the block width is always restricted by the first maxLines
number of SVG lines.
This results in a behavior where if maxLines
is exceeded in editor mode, editor size no longer matches the longest line in the editor.
So here I set the block width as the longest string in editor, if it is being edited. This is important, otherwise you will have situations where the first maxLines
lines have length of say 1, and then if another maxLines+1
-th line followed with more characters, it would keep breaking down into tiny peaces, as shown below.
here's what it looks like without this section. The last line should not break but should resize the editor.
With this section enabled:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the difference you were talking about here, that you had noticed, seems to be it was a bug, I think it's fixed now. That was happening because I was scaling the fontsize here before calculating line width. Actually, I still don't know why, but it seems to work perfectly fine without that, and even the bug is fixed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, makes sense, and glad you were able to fix the resizing issue! Could you add a comment summarizing what you said here? Something like "The default width is based on the longest line in the display text, but we need to calculate based on the absolute longest line even if it would be truncated after editing."
core/field_multilineinput.js
Outdated
@@ -286,9 +359,14 @@ Blockly.Css.register([ | |||
'.blocklyHtmlTextAreaInput {', | |||
'font-family: monospace;', | |||
'resize: none;', | |||
'overflow: hidden;', | |||
'overflow: scroll;', | |||
'-ms-overflow-style: none;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default should show the scrollbars since that is the typical paradigm for a scrollable text area. You can remove them for your project in your own css if you really don't want to show them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this too in a few days.
I cant just enable them because it will result in improper block size, and text will break down in places where it should not. Last time I tried updating block size in a way to include scrollbar width by using clientWidth
, got some strange glitches, so I need a little more time to figure this one out.
if (this.isBeingEdited_) { | ||
var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); | ||
if (this.isOverflowedY_) { | ||
Blockly.utils.dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); | ||
} else { | ||
Blockly.utils.dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I should probably explain why I have decided enabling the scrollbar manually like this.
Initially I tried using overflow-y:auto;
, but because the textarea is not resizable, I would get a glitch like this:
As I understand it, when we have a non-resizable textarea filled with text, another symbol automatically triggers scrollbar, and even though the next moment we set the correct width, the scrollbars' width is still there and it still counts as existing. Probably has something to do with the reflow order... and so we get the phantom scrollbar space. I tried fixing this thing, but eventually it got too painful, and I settled with current approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just requesting that you add some of the explanations you gave here into the code so it's clear for future readers.
Please note that as we have the release next week, develop
is currently frozen except for bug fixes so that we have adequate time to test all feature additions. This means after approval, your PR won't be merged for a few days until after the release (and possibly a bit longer than that since most of us will be taking vacation through the end of December) and your feature will be included in the following (q1 2021) release of Blockly. Thanks again for your work on this!
@@ -211,6 +228,27 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { | |||
totalHeight += this.getConstants().FIELD_TEXT_HEIGHT + | |||
(i > 0 ? this.getConstants().FIELD_BORDER_RECT_Y_PADDING : 0); | |||
} | |||
if (this.isBeingEdited_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, makes sense, and glad you were able to fix the resizing issue! Could you add a comment summarizing what you said here? Something like "The default width is based on the longest line in the display text, but we need to calculate based on the absolute longest line even if it would be truncated after editing."
Thanks for your contribution! And your patience, as develop was frozen for release and then most of us were on holiday. :) This should be available in the next release. |
This is a great PR! Thank you so much @gagiopapinni ! |
The basics
The details
Resolves
#3969
Proposed Changes
Added a maxLines config option to multiline text input
Reason for Changes
#3969 proposed to add a scrolling functionality, to make working with large amounts of text more comfortable.
So one of the reasons is to close the issue, another - to make working with large amounts of text more comfortable :)
Test Coverage
Tested on:
Additional Information
Additionally, I have added a clamsy block to playground here to test it, so you can also play with it