godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.97k stars 20.18k forks source link

Editor is incorrectly drawing non existent space #44775

Closed iwek7 closed 3 years ago

iwek7 commented 3 years ago

Godot version: master 886571e0fc

OS/device including version: irrelevant

Issue description: When both setting for drawing tabs and spaces in editor are turned on when one writes tab in editor then both tab and space icons are showing:

image

Only entered character is tab but both tab and space icons are drawn (tab is arrow, space is dot).

The reason for this is that in text_edit both of those conditions evaluate to true

if (draw_tabs && ((glyphs[j].flags & TextServer::GRAPHEME_IS_TAB) == TextServer::GRAPHEME_IS_TAB)) {
    int yofs = (text_height - cache.tab_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
    cache.tab_icon->draw(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + yofs), current_color);
}
if (draw_spaces && ((glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE)) {
    int yofs = (text_height - cache.space_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
    int xofs = (glyphs[j].advance * glyphs[j].repeat - cache.space_icon->get_width()) / 2;
    cache.space_icon->draw(ci, Point2(char_ofs + char_margin + ofs_x + xofs, ofs_y + yofs), current_color);
}

Steps to reproduce:

  1. Start new project
  2. set draw tabs and draw spaces editor settings to true
  3. create new gd script file
  4. write tab
Calinou commented 3 years ago

Feel free to open a pull request to fix this :slightly_smiling_face:

dakennedyd commented 3 years ago

Would it be OK if I work on this?

Calinou commented 3 years ago

@dakennedyd Sure :slightly_smiling_face:

That said, bruvzg is only away for one week, so you may want to wait until he's back.

dakennedyd commented 3 years ago

I took a look at the bug and the problem seems to be in the files: text_server_fb.cpp text_server_adv.cpp Both of those files have a function 'is_whitespace()' that counts characters (among others) from 0x9 to 0xd as a space. In ascii 0x9 is the value for tab that's why when the user presses tab the editor draws the symbols for space and tab. Fixing it is easy, but I ignore the reason as to why 'is_whitespace()' counts 0x9 as a space.

it might be that other writing systems count tab as spaces or it is just a typo?

Assuming it was a typo I put a pr that makes the function not count tab as a space just in case. Feel free to reject it if my assumption is wrong.