Godot: TextEdit: wrap is not implemented

Created on 8 Mar 2016  Â·  50Comments  Â·  Source: godotengine/godot

Issue description (what happened, and what was expected):

_TextEdit_ has method set_wrap(bool) which is a setter for the variable wrap. This variable is never used, so I assume this option was never implemented (or was removed).

This should be either implemented or the method should be removed to avoid confusion (like this one).

enhancement pr welcome core

Most helpful comment

Another quick update: I've managed to get the text to display in the proper position on subsequent lines (no longer writes ON TOP of previous wrapped lines, but moves down to accommodate them). I've also disabled the horizontal scrollbar when wrap is enabled. Currently working on getting the viewport adjustment and vertical scrollbar to respond appropriately to wrapped lines so that they don't start getting drawn off the edge of the TextEdit.

All 50 comments

It used to work.. wonder what happened..

On Tue, Mar 8, 2016 at 11:47 AM, Ignacio Etcheverry <
[email protected]> wrote:

_Issue description_ (what happened, and what was expected):

_TextEdit_ has method set_wrap(bool) which is a setter for the variable
wrap
https://github.com/godotengine/godot/blob/master/scene/gui/text_edit.h#L207.
This variable is never used, so I assume this option was never implemented
(or was removed).

This should be either implemented or the method should be removed to avoid
confusion (like this one
http://godotengine.org/qa/838/textedit-set_wrap-doesnt-seem-to-do-anything-thoughts
).

—
Reply to this email directly or view it on GitHub
https://github.com/godotengine/godot/issues/3985.

I went through all scene/gui/text_edit.cpp commits, and none seem to have touched this option. Maybe it was removed before going open source?

The wrap argument does not seem to be used anywhere in text_edit.cpp.

Reporting in that this is still an issue in the 2.1 beta release.

Bump! set_wrap still not working in 2.1.stable.official

Bump. This is a real bummer!

PR for this welcome

On Mon, Sep 12, 2016 at 1:43 PM, Qualitymix [email protected]
wrote:

Bump. This is a real bummer!

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-246409718,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z27BDngFobdq9bQghzlDnmFT5YZtNks5qpYFFgaJpZM4HrzjV
.

Note that it should ideally also be added in the script editor (and maybe made configurable, so that you can e.g. wrap at 80 chars) after it has been implemented in TextEdit.

So designing it to work with both variable width fonts on full TextEdit width, and fixed width fonts on fixed number of chars would be nice.

I noticed this is not currently in 2.1.1. Will it make its way there?

Sent from TypeApphttp://www.typeapp.com/r

On Oct 9, 2016, at 3:00 PM, "Rémi Verschelde" <[email protected]notifications@github.com> wrote:

Note that it should ideally also be added in the script editor (and maybe made configurable, so that you can e.g. wrap at 80 chars) after it has been implemented in TextEdit.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/godotengine/godot/issues/3985#issuecomment-252505229, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH6C0WfYUyoAQPy74fPldXMK3t0x6rpRks5qyTm7gaJpZM4HrzjV.

I noticed this is not currently in 2.1.1. Will it make its way there?

It would have to be implemented first, and 2.1.1 is not released.

Got it. I downloaded and compiled from master branch. Are there any roadblocks to implementing this ? Or is it just a matter of time and priorities?

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:00 PM, "Rémi Verschelde" <[email protected]notifications@github.com> wrote:

I noticed this is not currently in 2.1.1. Will it make its way there?

It would have to be implemented first, and 2.1.1 is not released.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/godotengine/godot/issues/3985#issuecomment-252664562, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH6C0TP6U_tC4yAWWg6_2dPUSQAupyH9ks5qymEjgaJpZM4HrzjV.

The only roadblock is that no one offered to do it, same as code folding.
So if anyone wants to contribute this work be welcome

On Mon, Oct 10, 2016 at 1:05 PM, Qualitymix [email protected]
wrote:

Got it. I downloaded and compiled from master branch. Are there any
roadblocks to implementing this ? Or is it just a matter of time and
priorities?

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:00 PM, "Rémi Verschelde" <[email protected]<
mailto:[email protected]>> wrote:

I noticed this is not currently in 2.1.1. Will it make its way there?

It would have to be implemented first, and 2.1.1 is not released.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub godotengine/godot/issues/3985#issuecomment-252664562>, or mute the thread<
https://github.com/notifications/unsubscribe-auth/AH6C0TP6U_tC4yAWWg6_
2dPUSQAupyH9ks5qymEjgaJpZM4HrzjV>.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-252665851,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z28yZjCh2xVN8u5W-XvEMH-OtcoZGks5qymJVgaJpZM4HrzjV
.

If someone could point to where in the source code the textedit node is located I could take a look at it. C++ right? I might be able to help.

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:10 PM, Juan Linietsky <[email protected]notifications@github.com> wrote:
The only roadblock is that no one offered to do it, same as code folding.
So if anyone wants to contribute this work be welcome

On Mon, Oct 10, 2016 at 1:05 PM, Qualitymix [email protected]
wrote:

Got it. I downloaded and compiled from master branch. Are there any
roadblocks to implementing this ? Or is it just a matter of time and
priorities?

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:00 PM, "Rémi Verschelde" <[email protected]<
mailto:[email protected]>> wrote:

I noticed this is not currently in 2.1.1. Will it make its way there?

It would have to be implemented first, and 2.1.1 is not released.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub godotengine/godot/issues/3985#issuecomment-252664562>, or mute the thread<
https://github.com/notifications/unsubscribe-auth/AH6C0TP6U_tC4yAWWg6_
2dPUSQAupyH9ks5qymEjgaJpZM4HrzjV>.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-252665851,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z28yZjCh2xVN8u5W-XvEMH-OtcoZGks5qymJVgaJpZM4HrzjV
.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/godotengine/godot/issues/3985#issuecomment-252667059, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH6C0SWV1IwHP6urE_3papskotBmwRlJks5qymNSgaJpZM4HrzjV.

great! :D

source code of text edit is scene/gui/text_edit.h,.cpp

everything is in there

On Mon, Oct 10, 2016 at 1:22 PM, Qualitymix [email protected]
wrote:

If someone could point to where in the source code the textedit node is
located I could take a look at it. C++ right? I might be able to help.

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:10 PM, Juan Linietsky <[email protected]<
mailto:[email protected]>> wrote:
The only roadblock is that no one offered to do it, same as code folding.
So if anyone wants to contribute this work be welcome

On Mon, Oct 10, 2016 at 1:05 PM, Qualitymix [email protected]
wrote:

Got it. I downloaded and compiled from master branch. Are there any
roadblocks to implementing this ? Or is it just a matter of time and
priorities?

Sent from TypeApphttp://www.typeapp.com/r

On Oct 10, 2016, at 12:00 PM, "Rémi Verschelde" <
[email protected]<
mailto:[email protected]>> wrote:

I noticed this is not currently in 2.1.1. Will it make its way there?

It would have to be implemented first, and 2.1.1 is not released.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub godotengine/godot/issues/3985#issuecomment-252664562>, or mute the
thread<
https://github.com/notifications/unsubscribe-auth/AH6C0TP6U_tC4yAWWg6_
2dPUSQAupyH9ks5qymEjgaJpZM4HrzjV>.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-252665851,

or mute the thread
XvEMH-OtcoZGks5qymJVgaJpZM4HrzjV>
.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub godotengine/godot/issues/3985#issuecomment-252667059>, or mute the thread<
https://github.com/notifications/unsubscribe-auth/AH6C0SWV1IwHP6urE_
3papskotBmwRlJks5qymNSgaJpZM4HrzjV>.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-252670241,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z2yXPOxLkh05uHphpoI-Y5l0Bd2NIks5qymZcgaJpZM4HrzjV
.

Drawing blanks with this. The C++ code is hard for me to grasp, not having written it myself. I suck at reading others' code. :(

Oh no! I just spent all day investigating the possibility of writing a simple text editor for my tablet today using Godot and just came across this issue. Godot was absolutely perfect for the job but then I discovered set_wrap didn't work and my plans were completely ruined.

I've had a glance at text_edit.cpp but it's largely uncommented black magic it seems.

I would be willing to add a $50 bounty to this, though I know that's massively low-balling the work required.

It would be great if this could be fixed. TextEdit is a very useful node, but it's quite annoying that wrapping doesn't work.

Yep. Definitelly wait for this one too. Please work on this

yes, please fix this. With text wrapping, an in-game wiki system can be made complete :sunglasses:

Ok, I'm going to go ahead and try to tackle this (first real bug fix challenge). Specifically because I have about 3 different tool concepts I wanna work on for Godot and ALL of them would require textedit wrapping to have the right feel, haha.

Symptoms I've noticed (in summary):

  • set_wrap is not effective.
  • set_max_chars is not effective.
  • If you hold down shift and highlight the content of the TextEdit, the section will be highlighted, but then the remaining contents of the TextEdit will begin flashing grey/white so long as you aren't holding down shift anymore.

Edit: seems that the last bug just triggers automatically so long as you are in block mode and the cursor is not at the end of a line. Everything from the curser to the end of the file will start blinking in inverted colors.

I'll try to work on these. I also plan to implement a max_line_chars variable so that you can specify a max length per line.

Feel free to contribute a fix!

On Jul 23, 2017 8:13 PM, "Will Nations" notifications@github.com wrote:

Ok, I'm going to go ahead and try to tackle this. Specifically because I
have about 3 different tool concepts I wanna work on for Godot and ALL of
them would require textedit wrapping to have the right feel.

Symptoms I've noticed (in summary):

  • set_wrap is not effective.
  • set_max_chars is not effective.
  • If you hold down shift and highlight the content of the TextEdit,
    the section will be highlighted, but then the remaining contents of the
    TextEdit will begin flashing grey/white so long as you aren't holding down
    shift anymore.

I'll try to work on these. I also plan to implement a max_line_chars
variable so that you can specify a max length per line.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-317289258,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z2-i1-WE-my1f32J4W2za7n9NndG8ks5sQ9OtgaJpZM4HrzjV
.

@reduz Is there a reason you know of why text_edit.cpp::_update_line_cache runs through the lines checking for color regions two completely separate times (lines 151-208)? It seems like it would just end up adding two separate color region info objects for each actual color region...

Color regions can span multiple lines for comments, line constants, etc.

On Jul 23, 2017 9:05 PM, "Will Nations" notifications@github.com wrote:

@reduz https://github.com/reduz Is there a reason you know of why
text_edit.cpp::_update_line_cache runs through the lines checking for
color regions two completely separate times (lines 151-208)? It seems like
it would just end up adding two separate color region info objects for each
actual color region...

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-317292136,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z29iR1R-WTRqYXgT6wQm-XB5IuiSuks5sQ9-ugaJpZM4HrzjV
.

TextEdit should also have an auto_height when wrap is enabled. See #9746.

TextEdit is storing its underlying data as a mutable Vector\\n exists where it doesn't (it would reflect in an increased/decreased count for line numbers which I would want to avoid).

Place of interest is /scene/gui/text_edit.cpp, line 2776, method _base_insert_text

It seems like the most appropriate way to handle it is to write an algorithm that...

  1. Connects preinsert_text to the new text on the insertion line.
  2. Checks the current line and detects the starting position of the first word to go beyond the visible width.
  3. Adds a new line to the editor WITHOUT adding a new line (best way to handle that?) and writes the remaining text on the current line.
  4. Reconnects postinsert_text to the end of the current line.
  5. Repeats steps 2 and 3 for each new line created until no more text goes beyond the visible width.

P.S. I already managed to fix the block_caret font-color-change issue. So yay.

Probably the best is to use, for each line, a sub-line array (starting
positions of sub-lines, like, Vector that is cached and re-computed on
screen resize (width) or line modification.

On Fri, Jul 28, 2017 at 11:41 AM, Will Nations notifications@github.com
wrote:

TextEdit is storing its underlying data as a mutable Vector (one String
for each line). Does anyone have any suggestions on how best to tackle the
cascading repositioning of strings as you resize the window / insert text?
My first thought would just be to move things to lines below/above as the
window contracts/expands; however, doing that would essentially be
pretending that \n exists where it doesn't (it would reflect in an
increased/decreased count for line numbers which I would want to avoid).

Place of interest is /scene/gui/text_edit.cpp, line 2776, method
_base_insert_text

It seems like the most appropriate way to handle it is to write an
algorithm that...

  1. Connects preinsert_text to the next text on the insertion line.
  2. Checks the current line and detects the starting position of the
    first word to go beyond the visible width.
  3. Adds a new line to the editor WITHOUT adding a new line (best way
    to handle that?) and write the remaining text on the current line.
  4. Repeats steps 1 and 2 for each new line created until no more text
    goes beyond the visible width.
  5. Reconnects the postinsert_text.
  6. Repeats step 4.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/3985#issuecomment-318670086,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z27ait6OeQEnqMbVPk_OkZraubqg1ks5sSfMLgaJpZM4HrzjV
.

Trying to think of how that would work in practice, the actual drawing of it in NOTIFICATION_DRAW. I figure I'd have to amend things so that the TextEdit keeps track of how many ACTUAL lines it has versus the number of VISUAL lines (actual + sub-lines), and all of the drawing operations would have to work off of the visual lines while things like highlighting a breakpoint/marked row shows every line and its sub-lines. That way you can reposition the font->draw_char parameters to target the visual position and whatnot. Geez, this is gonna be more complicated than I thought. XD

Update: I have implemented the following bug fixes / features:

  1. block_caret altering subsequent font color change (bug fix)
  2. max_chars not working properly (bug fix)
  3. Adding a max_line_chars (and associated getter/setter methods)
  4. Adding signals for both max_chars and max_line_chars (max_chars_reached and max_line_chars_reached, respectively) notifying the user when an attempt is made to insert beyond the limitation and which line.

I am now moving on to the actual wrap implementation (already have an initial implementation caching the appropriate string indexes during insertion for later wrapping).

Another update:

I am realizing the large task that involves word wrapping. XD It took a while to really figure out where everything is happening / what everything does, but I think I'm getting the hang of it.

So far, I have text showing up in a wrapped fashion as it moves off the screen. I'm going to have to start messing with the more low-level calculations however, so that they can return "wrapped" coordinates or use "wrapped" coordinates when wrap is toggled (scrollbars, viewport adjustments, selection box highlighting). I also still need to teach the cursor to adjust its writing position based on the presence of sub-rows when wrap is toggled since it currently will have new lines writing on top of the previous lines' wrapped rows of text. This'll all take me a while probably as there are a lot of changes to make.

Thanks so much for doing this my game is desperate for word wrapping to work with text edit. It's a problem I have been having for a while. How are you getting on with the task?

Well, For the last week I've been on vacation with family (programming forbidden) and before that i was rushing to get work stuff done, so it's pretty much in the state mentioned above. You can review the progress at willnationsdev/godotengine on the text-edit-wrap-fix branch.

Another quick update: I've managed to get the text to display in the proper position on subsequent lines (no longer writes ON TOP of previous wrapped lines, but moves down to accommodate them). I've also disabled the horizontal scrollbar when wrap is enabled. Currently working on getting the viewport adjustment and vertical scrollbar to respond appropriately to wrapped lines so that they don't start getting drawn off the edge of the TextEdit.

Hi @willnationsdev, just a quick question, will your textwrap fix also be applicable to godot 3.0?

@stubbsy345 Hey, sorry, I saw this in an email notification, and then forgot to respond.

Unfortunately, I don't think I'll be able to get it in for the 3.0 release. I MIGHT be able to isolate the max_chars fixes / features I mentioned if I can isolate them out of my branch, but I've been having really weird problems in getting my version of godot to build correctly as of late.

I was working on a different project for the last month - something I could do without having to compile the engine from source, cause I was starting to get burnt out / frustrated. I wanna try re-tackling my engine compilation issues though, so hopefully I can resume work on this.

Missed this as well. Awesome. If I can aid in any way let me know.

Yeah, definitely. I wanna finish up the project I've been working on, and then once that's done, I'll get a repo going again with the text_edit.cpp/.h files. I'll update you again once it's up and we can work together on it. Sound good?

I'm not sure my C++ is up to a standard of being of a great deal of use but if there is work I can do in another regard to help I am happy to. I was wondering, from the work you have already done, is it possible to extract just a very simple text wrapping text edit node. Many people who want the user to be able input text that wraps don't need all of the functions that text edit provides - only for the text to wrap and scroll to adapt as the length of the text increases, or possibly not even this, the node could be placed inside of a scroll container, similar to the way Vbox's can be placed inside such. Is this possible? Or is it just as easy to implement it for the current text edit node as it is now.

@stubbsy345 Ah, sorry again for not getting back to you. The scrolling functionality that remains to be written is still necessary (can't be funneled into a ScrollContainer) because if I don't do it, the node literally starts drawing code OFF the bottom of the node into the space below it. I had to close the repository because I screwed up the commit stuff, but I've saved a copy of my progress on the .h/.cpp files and emailed them to myself, so I'll be recreating the repo some time down the line. Will post an update here once I resume work on the project, but it'll be a while. Spent most of the last month working in simpler engine modifications for the recent beta release, so now I'm getting back on my plugins.

Hope this gets fixed, because I need it.
Still doesn't work in Godot 3

When I was playing around with Godot, this is the missing feature that made me reluctantly walk away. This is one of those features that, when you need it, you really can't do without.

@blurymind @Supergeek there is already a PR for this ready to go. It's scheduled for the 3.1 release.

Hey, sorry if I'm posting this in the wrong place, I'm not sure if I should open a new issue or not.

Text wrap now works in 3.1 alpha 1, but accented characters (é, è, à, etc.) in wrapped lines randomly disappear. Expanding the window to display single lines make them reappear. I've tried various font and TextEdit settings but this odd behavior only seem to happen when text warp is enabled.

Hey, sorry if I'm posting this in the wrong place, I'm not sure if I should open a new issue or not.

Please open a new issue yes.

hey so I can someone direct me on how to get godot 3.1 alpha? i'm using a ubuntu.

also i tried implementing my own version of autowrap in version 3.06 with the following code, and it also didn't work. is that related to why it wasn't implemented possibly?

auto-wrap-godot02

Hey, sorry if I'm posting this in the wrong place, I'm not sure if I should open a new issue or not.

Text wrap now works in 3.1 alpha 1, but accented characters (é, è, à, etc.) in wrapped lines randomly disappear. Expanding the window to display single lines make them reappear. I've tried various font and TextEdit settings but this odd behavior only seem to happen when text warp is enabled.

Watch the official blog for alpha releases. Alpha 3 is out: https://godotengine.org/article/dev-snapshot-godot-3-1-alpha-3

Ran into this issue and so downloaded 3.1 alpha after reading this. Wrapping now works but when text moves to the next line I start getting hundreds of errors like this.
image

Any idea what could be causing this? My game still seems to function despite the errors, just wondering if this is actually a problem

I also got those error lines a while back. But I wasn't able to reproduce this now with a minimal project on Godot 3.1 RC 2.

Here is my test project: wrap_test.zip

This is how it looks:
wrap_test

@lauren-emily75: Could you provide a minimum project where this happens?

Hi @pwab , I've just made a simple project with a control node and text edit node as a child. I haven't attached any scripts, just selected wrap enabled in the inspector. When entering text I start getting errors when the text moves to a new line and then from there every time I type a character.

I downloaded and tried yours, entering the text myself and like you said, there are no errors so not really sure what's wrong with mine. I have tried reproducing yours myself and am still getting the same errors

@pwab turns out I was using an old alpha version. Downloaded the latest and there is no issue!

@lauren-emily75 glad to hear this! 😃

Was this page helpful?
0 / 5 - 0 ratings