Skip to content

Tabs not recognized in practice tests. #548

Description

@RafaelZasas

Description

Added a snippet of Go code which had a tab before the "fmt" import.
When doing a practice run, I was not able to trigger the tab with a tab or spaces.

(optional) What browsers are you seeing the problem on?

Chrome

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. RafaelZasas commented on Jul 26, 2023

    @RafaelZasas
    Author

    It is also not possible to use tabs when adding code snippets by hand.

  2. sudo-adduser-jordan commented on Jul 27, 2023

    @sudo-adduser-jordan
    Contributor

    I will look into this.

  3. sudo-adduser-jordan commented on Jul 27, 2023

    @sudo-adduser-jordan
    Contributor

    Can you please include the snippet? A video would be extra helpful. Thank you

  4. writeonlycode commented on Jul 29, 2023

    @writeonlycode
    Contributor

    I notice the same thing, and I have a fix for it.

    It's true that you cannot to use tabs when adding code snippets by hand. But if you copy and paste the snippet form somewhere else, the tab will be inserted. That's how I replicated the bug.

    Can I take care of this issue or there's someone else already working at it?

  5. writeonlycode commented on Jul 29, 2023

    @writeonlycode
    Contributor

    Here's a step-by-step on how to reproduce the issue:

    1. Run a local instance of the App.
    2. Click "Add Snippet"
    3. Copy the code below & paste in the snippet to be added, & add the snippet:
    #include <iostream>
    
    int main() {
    	std::cout << "Hello World!";
    	return 0;
    }

    The code above has tab characters in it, so the snippet will be added with tab characters to the database.

    1. Click "Race", select "C++" and run. You should see the new code snippet. If not, refresh until you got the correct snippet.
    2. When you reach the tab character, pressing tab does nothing and you are stuck.

    That's it. I'll create a PR with a fix later today.

  6. sudo-adduser-jordan commented on Jul 29, 2023

    @sudo-adduser-jordan
    Contributor

    Thanks for the snippet.
    The /t needs to be stripped and replaced with whitespace before insert into the database.
    I would prefer to avoid editing the race logic.

  7. writeonlycode commented on Jul 30, 2023

    @writeonlycode
    Contributor

    Yep. I was thinking about these alternatives. The way I found to deal with the issue, is to tweak a little the race logic in packages/app/src/app/race/_components/race/race-practice.tsx. But it turns out, the tweaks are really minimal: it's just about replicating some of the logic to deal with whitespaces in the beginning of a line, so it can also deal with \t at the beginning of a line.

    I suspect it's worth having the race practice to be able to deal with tabs, in case they end up in the database somehow. The idea of stripping the tabs before inserting into the database is good too. This would also give more consistency across different snippets, to avoid some coming with tabs and others with whitespaces.

    It might be worth implementing both. I'll create a PR with the fix I did, so you can take a look. Let me know if this looks good!

  8. added a commit that references this issue on Jul 30, 2023
  9. sudo-adduser-jordan commented on Jul 30, 2023

    @sudo-adduser-jordan
    Contributor

    @writeonlycode

    This will work. However, the race-multiplayer.tsx file will also have to be changed.

    The snippets inside the database will not be uniform. This can make debugging accuracy more difficult.
    A .replace("/t", " ") inside add-snippet-form.tsx will format the strings to be uniform upon insert into the database.
    This way the race logic does not need to be edited or perform an extra step on every enter(), only once on insert.

    Tab will still not work inside the /add-snippet-form input.

    This issue should be reopened or a new issue should be created.

  10. writeonlycode commented on Jul 30, 2023

    @writeonlycode
    Contributor

    Good points. I'll explore further this issue, and I'll create another PRs once I implement these other tweaks.

  11. vignesh-gupta commented on Aug 22, 2023

    @vignesh-gupta
    Contributor

    Hey @writeonlycode could you please share updates, if any?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions