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

Allow get_word_at_pos() function support symbols (@$# ....) #3580

Open
JBingrun opened this issue Nov 21, 2021 · 2 comments
Open

Allow get_word_at_pos() function support symbols (@$# ....) #3580

JBingrun opened this issue Nov 21, 2021 · 2 comments

Comments

@JBingrun
Copy link

Describe the project you are working on

I'm building a custom text editor to write code with custom extensions.

Describe the problem or limitation you are having in your project

I try to get the current text that the user input and check if it matches anything keyword I defined. If matched, it will trigger the auto-completion and give a list for users to choose from. I search a bit and found that there are two functions that might suit my need in Godot 4. One is get_word_at_pos() and the other is get_word_under_caret().
get_word_at_pos() works great only does not support symbol and get_word_under_caret() need a bit workaround and I found it support $ and ~ but still not for all. So I was stuck with no way to get the full string that the user input with symbols.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allow the get_word_at_pos() function to support symbols so any kind of custom code using symbols very often can use it more effectively.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Code:

_text_edit = $TextEdit
var _caret_pos: Vector2 =_text_edit.get_caret_draw_pos()
print("Current input text: " + _text_edit.get_word_at_pos(_caret_pos))

In extEdit when user input:
===Test Code===@#$

Console will print full of them:
Current input text: ===Test Code===@#$

If this enhancement will not be used often, can it be worked around with a few lines of script?

I didn't find any other way to do this at this moment.

Is there a reason why this should be core and not an add-on in the asset library?

TextEdit node is for building custom edit environments and more customizable for different situations will be more useful.

@Calinou
Copy link
Member

Calinou commented Nov 21, 2021

See godotengine/godot#46721. You should be able to override word break characters with an empty list when adding text to the TextEdit node to control the behavior of get_word_at_pos() and get_word_under_caret().

@JBingrun
Copy link
Author

Thanks for the reply, can't tell I do understand how to achieve my goal, anyway, I follow the example:

var a = TextParagraph.new()
a.custom_punctuation = "R"
a.add_string("test.test_testRtest test", get_theme_font("font"), 16)
print("A: ", TextServerManager.get_primary_interface().shaped_text_get_word_breaks(a.get_rid()))
#A: [(0, 14), (15, 19), (20, 24)]

And Godot stuck at setting custom_punctuation value and give me this error message:

Invalid set index 'custom_punctuation' (on base: 'TextParagraph') with value of type 'String'.

The type of custom_punctuation is a string, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants